From 9eff1e08b3e580d1e2a998af0243e27c8370c14e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 19 Mar 2013 14:29:04 -0400 Subject: Add pbs and pbs-help, to have it work like git --- .gitignore | 1 + Makefile | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- pbs-help | 39 +++++++++++++++++++++++++++++++++++++++ pbs.in | 21 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100755 pbs-help create mode 100755 pbs.in 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 diff --git a/Makefile b/Makefile index 96fe6b2..cfbe4a9 100644 --- a/Makefile +++ b/Makefile @@ -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 "$@" diff --git a/pbs.in b/pbs.in new file mode 100755 index 0000000..bf7cc27 --- /dev/null +++ b/pbs.in @@ -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 "$@" -- cgit v1.1-4-g5e80