diff options
author | B. Watson <yalhcru@gmail.com> | 2017-03-18 13:50:39 -0400 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2017-03-18 13:50:39 -0400 |
commit | 834e26a3a54e394a42906216536d733f065e6aaf (patch) | |
tree | 60ab640579c0d159a0ea07c14da596f6c027f096 /sbrun | |
parent | 55b42d14b839ca6126984b224894d4e97bfb9e14 (diff) | |
download | sbostuff-834e26a3a54e394a42906216536d733f065e6aaf.tar.gz |
sbrun: add -i and -p options
Diffstat (limited to 'sbrun')
-rwxr-xr-x | sbrun | 163 |
1 files changed, 125 insertions, 38 deletions
@@ -32,6 +32,8 @@ NETWORK="no" TRACK="yes" STRACE="" CLEANUP="no" +SRCSH="no" +PKGSH="no" LOGDIR="" NSENTER="" TRACKFS="" @@ -46,7 +48,7 @@ NONET_PATH=/mnt/nonet.$SELF.$$ # Possible future options: # -f Run script with fakeroot. (still need root/sudo for unshare/nsenter, # and trackfs won't track failed writes, maybe this isn't that useful?) -# -i Install package after it's built. Could count as scope creep. +# -I Install package after it's built. Could count as scope creep. long_help() { # note: root's pager is used, not the user's, since we use sudo. @@ -74,7 +76,10 @@ to work. $SELF written by B. Watson (yalhcru@gmail.com) and released under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details. -Usage: $SELF [-jN] [-n] [variable=value ...] +Usage: $SELF [-jN] [-n] [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]. -jN Run N make jobs in parallel. Default is to use MAKEFLAGS from the environment if set, otherwise "$DEFAULT_MAKEFLAGS". If a SlackBuild fails @@ -99,6 +104,17 @@ Usage: $SELF [-jN] [-n] [variable=value ...] -x Run the script with "sh -x", enables shell command tracing. +-i Run an interactive shell in the source directory, after the script + completes *successfully* (nothing happens if it fails). Useful for + development, e.g. place 'exit 0' in the script wherever you need to + examine the state of the source directory. May not work as expected + if the SlackBuild creates multiple directories under \$TMP, or if + multiple SlackBuilds are being run simultaneously. + +-p Run an interactive shell in the \$PKG directory, after the script + completes (successfully or otherwise, provided the directory + exists). Useful for development. + -c Clean up (remove) source and package directories after the build completes. This option overrides \$TMP from the environment. @@ -107,13 +123,19 @@ Usage: $SELF [-jN] [-n] [variable=value ...] -H Show long help message (you're reading it now) and exit. -All arguments not beginning with - are passed as part of the SlackBuild -script's environment. Options beginning with - must occur before -environment variables. Example: +[script] + Run this script instead of the .SlackBuild script. Useful for + development, I hope. Useful also for Slack-derived distros that + use something other than .SlackBuild for their script names. - $SELF -j1 SDL2=no DOCS=yes +[variable=value ...] + All arguments containing an = (and not beginning with -) are passed as + part of the SlackBuild script's environment. Options beginning with - + must occur before environment variables. Example: -Leave off the -j1 to use the default number of jobs. + $SELF -j1 SDL2=no DOCS=yes + + 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 @@ -158,6 +180,12 @@ fairly often with buggy SlackBuilds. The elapsed time display is a nice convenience (I complain that "This thing takes 2 hours to build!" when really it's closer to 1 hour). +The -i option exists because I used to be in the habit of placing 'exec +bash -login' part of the way through a script as a way to get a shell in +the source dir... but this stopped being possible once I added build.log +to sbrun. So now I can stick 'exit 0' part way through the script and use +'sbrun -i' to get the same thing. -p was added for similar reasons. + The -c option is the only "end user" option, really. I mostly use it for building dependencies maintained by other people, not my own stuff. @@ -189,13 +217,17 @@ EOF } show_help() { + # don't use warn here, log isn't open yet. + if [ -n "$1" ]; then + echo "$SELF: unknown option '$1'" 2>&1 + fi cat <<EOF $SELF: paranoid SlackBuild wrapper. $SELF written by B. Watson (yalhcru@gmail.com) and released under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details. -Usage: $SELF [-jN] [-n] [variable=value ...] +Usage: $SELF [-option [-option ...]] [script] [variable=value ...] -jN Run N make jobs in parallel. -n Allow the SlackBuild to access the network. @@ -204,10 +236,14 @@ Usage: $SELF [-jN] [-n] [variable=value ...] -S Run the script with strace -ff, outputs in "strace.out.<pid>". -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. -h, --help Show short usage message (you're reading it now) and exit. -H Show long help message and exit. -variable=value +script + Run this script instead of the default .SlackBuild script. +variable=value ... Passed to script as environment variables. EOF } @@ -297,16 +333,18 @@ ensure_path /usr/share/texmf/bin # parse -options while printf -- "$1" | grep -q ^-; do case "$1" in - -j*) MAKEFLAGS="$1" ;; - -n) NETWORK=yes ;; - -t) TRACK=no ;; - -s) TRACK=no; STRACE=-f ;; - -S) TRACK=no; STRACE=-ff ;; - -x) X="-x" ;; - -c) CLEANUP="yes" ;; - -h|-help|--help) show_help ; exit 0 ;; - -H) long_help ; exit 0 ;; - -*) show_help ; exit 1 ;; + -j*) MAKEFLAGS="$1" ;; + -n) NETWORK=yes ;; + -t) TRACK=no ;; + -s) TRACK=no; STRACE=-f ;; + -S) TRACK=no; STRACE=-ff ;; + -x) X="-x" ;; + -c) CLEANUP="yes" ;; + -i) SRCSH="yes" ;; + -p) PKGSH="yes" ;; + -h|-help|--help) show_help ; exit 0 ;; + -H) long_help ; exit 0 ;; + -*) show_help "$1"; exit 1 ;; esac shift done @@ -322,6 +360,32 @@ echo "== command: $0" "$@" echo } | tee $BUILDLOG +# rest of arg parsing can use warn or die. +if echo "$1" | grep -qv '='; then + SCRIPT="$1" + shift + #[ ! -e "$SCRIPT" ] && warn "$SCRIPT not found, I hope you know what you're doing!" +fi + +# $ENV is only for showing to the user +ENV="MAKEFLAGS=$MAKEFLAGS" +export MAKEFLAGS TMP OUTPUT + +# Add rest of args to environment. The echo|cut and eval stuff allows +# spaces to occur in the values. There is probably a better modern-bash +# way to do this, but (to me anyway) it'll be less readable. +for arg; do + if echo "$arg" | grep -qv '='; then + die "invalid/unknown argument '$1', try -h for help or -H for long help." + else + ENV="$ENV $arg" + #eval export "$arg" # works but doesn't allow spaces + var="$( echo "$arg" | cut -d= -f1 )" + val="$( echo "$arg" | cut -d= -f2 )" + eval "export $var='$val'" + fi +done + # The easy way to remove the source and PKG dirs after the # script runs is to guarantee they'll be the only things in # $TMP. Normally, we don't create the $TMP dir, so we can @@ -335,21 +399,6 @@ if [ "$CLEANUP" = "yes" ]; then fi fi -# $ENV is only for showing to the user -ENV="MAKEFLAGS=$MAKEFLAGS" -export MAKEFLAGS TMP OUTPUT - -# Add rest of args to environment. The echo|cut and eval stuff allows -# spaces to occur in the values. There is probably a better modern-bash -# way to do this, but (to me anyway) it'll be less readable. -for arg; do - ENV="$ENV $arg" - #eval export "$arg" # works but doesn't allow spaces - var="$( echo "$arg" | cut -d= -f1 )" - val="$( echo "$arg" | cut -d= -f2 )" - eval "export $var='$val'" -done - # I wasn't gonna trap signals, but I can't break myself of the habit # of hitting ^C. # TODO: we should be trapping more signals here... @@ -389,7 +438,15 @@ if [ "$STRACE" != "" ]; then TRACKFS="strace $STRACE -ostrace.out" fi -SCRIPT="./$( pwd | sed 's,.*/,,' ).SlackBuild" +# Used to do this, but it doesn't allow for cases where the directory +# has been renamed (foo.SlackBuild in a dir called foo.testing or foo.old). +#SCRIPT="./$( pwd | sed 's,.*/,,' ).SlackBuild" + +# This is better, but during development, a user might have copies of the +# script named foo.old.SlackBuild and foo.new.SlackBuild, so not perfect. +# To allow for this, we now take an optional script name on the command line. +SCRIPT="${SCRIPT:-$( /bin/ls ./*.SlackBuild | head -1 )}" + if [ ! -e "$SCRIPT" ]; then die "$SCRIPT not found, bailing" fi @@ -418,9 +475,11 @@ fi START_TIME="$( date +%s )" # Actually run the script. Note that the 'tee' command isn't being -# tracked by trackfs. -eval $NSENTER $TRACKFS sh $X $SCRIPT 2>&1 | tee -a $BUILDLOG -RET=$? +# tracked by trackfs. The rigmarole with $? and RET might not be the +# best way to get the exit status, TODO: see if I can do this cleaner. +# Also, using { } instead of ( ) utterly fails. +( eval $NSENTER $TRACKFS sh $X $SCRIPT 2>&1; echo "$?" > $LOGDIR/ret ) | tee -a $BUILDLOG +RET="$( cat $LOGDIR/ret )" END_TIME="$( date +%s )" @@ -443,6 +502,34 @@ if [ "$TRACK" = "yes" ]; then cleanup_log fi +# spawn shell(s) if requested. -i and -p are not mutually exclusive. + +# TODO: maybe do this cleaner, using trackfs? +if [ "$SRCSH" = "yes" ]; then + if [ "$RET" != "0" ]; then + warn "Script failed (status $RET), ignoring -i option" + else + SRCDIR="$( /bin/ls -td $TMP/*/ | grep -v /package- | head -1 )" + ( cd $SRCDIR && bash -login ) + fi +fi + +# PRGNAM is problematic. We don't want to use $( basename $( pwd ) ) +# because the directory might have been renamed (foo => foo.testing or +# foo.old). Reading the .info file is no good (this might not be an SBo +# build). For now, extract it from the script name, but eventually this +# won't work because I want to support passing a script name someday +# instead of hard-coding .SlackBuild. +if [ "$PKGSH" = "yes" ]; then + PRGNAM="$( echo $SCRIPT | sed 's,^\./\(.*\)\.SlackBuild$,\1,' )" + PKG=$TMP/package-$PRGNAM + if [ -d "$PKG" ]; then + ( cd $PKG && bash -login ) + else + warn "$PKG not found, ignoring -p option" + fi +fi + cleanup_build # Our return status is that of the SlackBuild. |