diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 55 | ||||
-rwxr-xr-x | pbs-help | 39 | ||||
-rwxr-xr-x | pbs.in | 21 |
4 files changed, 106 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..974b555 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/pbs
\ No newline at end of file @@ -1,20 +1,55 @@ PREFIX=/usr/local -BINPROGS=$(shell find * -type f -executable) +# in a bind, thes can all be set to the same directory +pbs-bindir = $(PREFIX)/lib/pbs-core +git-bindir = $(PREFIX)/lib/git-core +bindir = $(PREFIX)/bin +libreconfdir = /etc/libretools.d -all: $(BINPROGS) pbs-convert.conf +pbs-progs := $(shell printf '%s\n' pbs-* | fgrep -v .) +git-progs := $(shell printf '%s\n' git-* | fgrep -v .) +bin-progs = pbs +libreconf := $(wildcard pbs-*.conf) -install: $(addprefix $(DESTDIR)$(PREFIX)/bin/,$(BINPROGS)) $(DESTDIR)/etc/libretools.d/pbs.conf +install-targets := \ + $(addprefix $(DESTDIR)$(pbs-bindir)/,$(pbs-progs)) \ + $(addprefix $(DESTDIR)$(git-bindir)/,$(git-progs)) \ + $(addprefix $(DESTDIR)$(bindir)/,$(bin-progs)) \ + $(addprefix $(DESTDIR)$(libreconfdir)/,$(libreconf)) -uninstall: - for f in $(BINPROGS); do rm -f $(DESTDIR)$(PREFIX)/bin/$$f; done - rm -f $(DESTDIR)/etc/libretools.d/pbs-convert.conf +# phony rules -$(DESTDIR)$(PREFIX)/bin/%: % | $(DESTDIR)$(PREFIX)/bin - install -m755 '$*' '${@D}' +all: PHONY $(pbs-progs) $(git-progs) $(bin-progs) $(libreconf) -$(DESTDIR)/etc/libretools.d/pbs-convert.conf: pbs-convert.conf | $(DESTDIR)/etc/libretools.d +clean: PHONY + rm -f pbs + +install: PHONY $(install-targets) + +uninstall: PHONY + for f in $(install-targets); do rm -f -- $(f); done + +# actual file rules + +pbs: pbs.in + sed 's|@pbs-bindir@|$(pbs-bindir)|g' < $< > $@ + chmod 755 $@ + +$(DESTDIR)$(pbs-bindir)/%: % | $(DESTDIR)$(pbs-bindir) + cp '$*' '${@D}' + +$(DESTDIR)$(git-bindir)/%: % | $(DESTDIR)$(git-bindir) + cp '$*' '${@D}' + +$(DESTDIR)$(bindir)/%: % | $(DESTDIR)$(bindir) + cp '$*' '${@D}' + +$(DESTDIR)$(libreconfdir)/%: % | $(DESTDIR)$(libreconfdir) install -m644 '$*' '${@D}' -$(DESTDIR)$(PREFIX)/bin $(DESTDIR)/etc/libretools.d: +$(addprefix $(DESTDIR),$(pbs-bindir) $(git-bindir) $(bindir) $(libreconfdir)): install -d '$@' + +# tricks + +.PHONY: PHONY diff --git a/pbs-help b/pbs-help new file mode 100755 index 0000000..60d4270 --- /dev/null +++ b/pbs-help @@ -0,0 +1,39 @@ +#!/bin/bash -euE + +. libremessages + +stem=pbs + +list_commands() { + find ${PATH//:/ } -type f -executable -name "$stem-*" \ + -printf '%f\n' 2>/dev/null | sed "s/^${stem}-//;/--/d" +} + +master_usage() { + echo "Usage: ${pbs_short:-${stem}} COMMAND [OPTIONS]" + echo + echo "Commands:" + list_commands | sed 's/^/ /' +} + +help_usage() { + echo "Usage: ${pbs_short:-${stem}} help [OPTIONS] COMMAND" + echo "Shows the manual page for a command" + echo '' + echo 'Options:' + echo ' -h Show this message' +} + +main() { + if [[ $# < 1 ]]; then + master_usage + else + if in_array '-h' "$@"; then + help_usage + else + man "$stem-$1" + fi + fi +} + +main "$@" @@ -0,0 +1,21 @@ +#!/bin/bash + +if [[ -z PBS_PATH ]]; then + export PBS_PATH=@pbs-bindir@ +fi + +if [[ -z "$pbs_cmd" ]]; then + export pbs_cmd=$0 + export pbs_short=${pbs_cmd##*/} + export PATH="$PBS_PATH:$PATH" +fi + +main() { + if [[ $# < 1 ]]; then + pbs-help + return 1 + fi + pbs-"$@" +} + +main "$@" |