aboutsummaryrefslogtreecommitdiff
path: root/sbrun
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-09-24 06:52:13 -0400
committerB. Watson <urchlay@slackware.uk>2026-09-24 06:52:13 -0400
commit7034aa1288dd0b79e6971eca5c42278bbab92deb (patch)
tree9c756fe0deaacea1f7a7bafb60db7bd0d0721d9c /sbrun
parentc87f5b78866da17f0794d1abd78fe6810cfbbe36 (diff)
downloadsbostuff-7034aa1288dd0b79e6971eca5c42278bbab92deb.tar.gz
sbrun: improve option parsing (use getopts bash builtin).
Diffstat (limited to 'sbrun')
-rwxr-xr-xsbrun70
1 files changed, 46 insertions, 24 deletions
diff --git a/sbrun b/sbrun
index 3b5b8c7..0175834 100755
--- a/sbrun
+++ b/sbrun
@@ -78,13 +78,13 @@ sudo. If you hate sudo, just run $SELF as root.
$SELF is designed for use with SBo scripts, but will work for any
SlackBuild (it doesn't refer to the SBo .info file).
-$SELF written by B. Watson (yalhcru@gmail.com) and released
+$SELF written by B. Watson (urchlay@slackware.uk) and released
under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
-Usage: $SELF [-jN] [-n] [script] [variable=value ...]
+Usage: $SELF [-option [-option ...]] [script] [variable=value ...]
-Options may not be bundled (use -t -n, not -tn or -nt). All options
-beginning with - must occur before [script] or [variable=value].
+Options may be bundled (-tn is the same as -t -n), and mixed
+freely with non-option arguments.
-l Lint the package after it's built, with sbopkglint(1).
@@ -156,10 +156,10 @@ beginning with - must occur before [script] or [variable=value].
Leave off the -j1 to use the default number of jobs.
After the SlackBuild exits, any files written to outside of \$TMP,
-\$OUTPUT, /tmp, /var/tmp, or /root/.ccache (collectively referred to
-as "the sandbox") are logged to stdout. Any write outside the
-sandbox means a bug in the SlackBuild and should be reported to its
-maintainer.
+\$OUTPUT, /tmp, /var/tmp, /root/.ccachem, or /root/.cache
+(collectively referred to as "the sandbox") are logged to stdout. Any
+write outside the sandbox means a bug in the SlackBuild and should be
+reported to its maintainer.
The exit status of $SELF is the exit status of the SlackBuild,
unless the -l option is used. With -l, the exit status is that
@@ -247,23 +247,25 @@ show_help() {
cat <<EOF
$SELF: paranoid SlackBuild wrapper.
-$SELF written by B. Watson (yalhcru@gmail.com) and released
+$SELF written by B. Watson (urchlay@slackware.uk) and released
under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
Usage: $SELF [-option [-option ...]] [script] [variable=value ...]
--jN Run N make jobs in parallel.
--n Allow the SlackBuild to access the network.
--s Run the script with strace -f, output in "strace.out".
--x Run the script with "sh -x", enables shell command tracing.
--c Clean up (remove) source and package dirs after build completes.
--I Run an interactive shell in the source directory.
--p Run an interactive shell in the \$PKG directory.
--i Install built package with 'upkg'.
--d Download sources with 'sbodl'.
+-jN Run N make jobs in parallel.
+-n Allow the SlackBuild to access the network.
+-s Run the script with strace -f, output in "strace.out".
+-x Run the script with "sh -x", enables shell command tracing.
+-c Clean up (remove) source and package dirs after build completes.
+-I Run an interactive shell in the source directory.
+-p Run an interactive shell in the \$PKG directory.
+-i Install built package with 'upkg'.
+-d Download sources with 'sbodl'.
-h, --help
- Show short usage message (you're reading it now) and exit.
--H Show long help message and exit.
+ Show short usage message (you're reading it now) and exit.
+-H, --long-help
+ Show long help message and exit.
+--man Format the long help message as a man page, on stdout.
script
Run this script instead of the default .SlackBuild script.
variable=value ...
@@ -383,11 +385,30 @@ ensure_path /sbin
ensure_path /usr/sbin
ensure_path /usr/share/texmf/bin
+# we aren't using real --long-options, just these special cases:
+if [ "$1" = "--help" ]; then
+ show_help ; exit 0
+elif [ "$1" = "--long-help" ]; then
+ long_help ; exit 0
+elif [ "$1" = "--man" ]; then
+ die "--man not yet supported"
+fi
+
+# save original args, as we're going to permute them, below
+CMD="$0 $*"
+
# parse -options
-while printf -- "$1" | grep -q ^-; do
+OPTS="$( getopt -n $SELF -olj:nsxcIpDidqQhH -l help -- "$@" )"
+if [ "$?" != "0" ]; then
+ show_help
+ exit 1
+fi
+
+eval set -- "$OPTS"
+while true; do
case "$1" in
-l) LINTPKG="yes" ;;
- -j*) MAKEFLAGS="$1" ;;
+ -j) shift; MAKEFLAGS="$1" ;;
-n) NETWORK=yes ;;
-s) STRACE=-f ;;
-x) X="-x" ;;
@@ -404,7 +425,8 @@ while printf -- "$1" | grep -q ^-; do
-Q) run_queue -i ;;
-h|-help|--help) show_help ; exit 0 ;;
-H) long_help ; exit 0 ;;
- -*) show_help "$1"; exit 1 ;;
+ --) shift ; break ;;
+ *) show_help "$1"; exit 1 ;; # never happens?
esac
shift
done
@@ -418,7 +440,7 @@ echo -n "== $SELF starting up at "
date
echo -n "== directory: "
pwd
-echo "== command: $0" "$@"
+echo "== command: $CMD"
echo
} | tee $BUILDLOG