diff options
-rwxr-xr-x | sbrun | 149 |
1 files changed, 88 insertions, 61 deletions
@@ -9,7 +9,7 @@ DEFAULT_MAKEFLAGS="-j8" # End of configurables. It's probably best not to configure TMP or # OUTPUT here (use the environment instead) anyway. Also it's probably -# convenient to add build.log to .gitignore. +# convenient to add build.log to .git/info/exclude. # If we're not running as root, re-exec as root, with args. # Anything sbrun expects to possibly inherit from the caller's environment @@ -30,7 +30,7 @@ MAKEFLAGS="${MAKEFLAGS:-$DEFAULT_MAKEFLAGS}" # Defaults, changed by -options. NETWORK="no" TRACK="yes" -STRACE="no" +STRACE="" CLEANUP="no" LOGDIR="" NSENTER="" @@ -43,59 +43,10 @@ SELF=$(basename $0) # able to mess with /mnt already has root access. NONET_PATH=/mnt/nonet.$SELF.$$ -# Why does sbrun exist? Why not use sbopkg or sbotools? sbrun is targeted -# more towards a SlackBuild developer/maintainer than an end user. My -# workflow is to edit the script in one terminal and repeatedly execute it -# in another. If you're editing a SlackBuild, you keep running it over & -# over again. So I wrote a 1-liner shell script that did this: - -# sudo sh ./$( pwd | sed 's,.*/,,' ).SlackBuild - -# I have /sbin:/usr/sbin in my user's PATH so sudo works fine, but it's a -# PITA to pass environment variables using the above script (sudo strips -# them out of the env). So I made the script take arguments, and treat -# those as env vars (place them between 'sudo' and 'sh'). - -# Then I added MAKEFLAGS support to it (-jN option). Then I found out -# some of my builds were writing outside of $TMP (due to either my -# own mistakes, or upstream bugs) and decided I needed a way to -# reliably detect that, hence the trackfs stuff. Also someone on -# the mailing list posted output from running a SlackBuild under -# bubblewrap, which prevented network access the script was trying -# to do. Which seems like a nifty feature to have, but bubblewrap -# is overkill for just running a shell script. - -# The strace and sh -x options were added because those are things I do -# 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 -c option is the only "end user" option, really. I mostly use it -# for building dependencies maintained by other people, not my own stuff. - -# Basically, sbrun started out as a lazy typist's tool, and grew into -# something more generally useful. It's lower-level than sbotools or -# sbopkg, but more convenient than just executing ./*.SlackBuild. It -# requires no initial setup or configuration (it's a self-contained -# shell script). Since it's *not* intended to replace sbotools or sbopkg, -# sbrun doesn't do any of these things: - -# - download source files -# - check source file md5sums -# - allow building multiple packages at once (queue files) -# - install/upgrade/remove packages (it *just* builds them) -# - dependency resolution -# - sync the repo, or even have any concept of a repo (it only deals -# with a single SlackBuild script, in the current directory). -# - anything to do with .info files. Nothing about sbrun is SBo-specific, -# it'll work with Pat's or AlienBOB's or anyone else's scripts (which -# is why it's called sbrun and not sborun). - # 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. -# -H long help (the existing help is long already, -h would be an extract) long_help() { # note: root's pager is used, not the user's, since we use sudo. @@ -126,10 +77,9 @@ under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details. Usage: $SELF [-jN] [-n] [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 without -j1, this is a bug in the SlackBuild - and you should ask its maintainer to add -j1 to the make command - in the script. + the environment if set, otherwise "$DEFAULT_MAKEFLAGS". If a SlackBuild fails + without -j1, this is a bug in the SlackBuild and you should ask + its maintainer to add -j1 to the make command in the script. -n Allow the SlackBuild to access the network. If a SlackBuild fails without this flag, that's a bug in the SlackBuild and @@ -144,6 +94,9 @@ Usage: $SELF [-jN] [-n] [variable=value ...] will be disabled). The strace log will be written to the current directory as "strace.out". +-S Like -s, but using strace's -ff option. Each child process executed + gets its own strace log file. They will be named "strace.out.<pid>". + -x Run the script with "sh -x", enables shell command tracing. -c Clean up (remove) source and package directories after the @@ -169,6 +122,69 @@ the log format, but 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. + +Note: the current directory needs to be writable, since the log and +(with -s/-S) strace output are written there. + +====================================================================== +The rest of this help message is a long-winded discussion that doesn't +include any more usage information. Feel free to stop reading at any +time :) +====================================================================== + +Why does sbrun exist? Why not use sbopkg or sbotools? sbrun is targeted +more towards a SlackBuild developer/maintainer than an end user. My +workflow is to edit the script in one terminal and repeatedly execute it +in another. If you're editing a SlackBuild, you keep running it over & +over again. So I wrote a 1-liner shell script that did this: + +sudo sh ./\$( pwd | sed 's,.*/,,' ).SlackBuild + +I have /sbin:/usr/sbin in my user's PATH so sudo works fine, but it's a +PITA to pass environment variables using the above script (sudo strips +them out of the env). So I made the script take arguments, and treat +those as env vars (place them between 'sudo' and 'sh'). + +Then I added MAKEFLAGS support to it (-jN option). Then I found out some +of my builds were writing outside of $TMP (due to either my own mistakes, +or upstream bugs) and decided I needed a way to reliably detect that, +hence the trackfs stuff. Also someone on the mailing list posted output +from running a SlackBuild under bubblewrap, which prevented network access +the script was trying to do. Which seems like a nifty feature to have, +but bubblewrap is overkill for just running a shell script. + +The strace and sh -x options were added because those are things I do +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 -c option is the only "end user" option, really. I mostly use it +for building dependencies maintained by other people, not my own stuff. + +Basically, sbrun started out as a lazy typist's tool, and grew into +something more generally useful. It's lower-level than sbotools or sbopkg, +but more convenient than just executing ./*.SlackBuild. It requires no +initial setup or configuration (it's a self-contained shell script), +except you have to install trackfs. + +Since it's *not* intended to replace sbotools or sbopkg, sbrun doesn't +do any of these things: + +- download source files. +- check source file md5sums. +- allow building multiple packages at once (queue files). +- install/upgrade/remove packages (it *just* builds them). +- dependency resolution. +- sync the repo, or even have any concept of a repo (it only deals + with a single SlackBuild script, in the current directory). +- anything to do with .info files. Nothing about sbrun is SBo-specific, + it'll work with Pat's or AlienBOB's or anyone else's scripts (which + is why it's called sbrun and not sborun). + +Finally, a helpful hint: If you use git to push to SBo, you can't +add anything to .gitignore since it's tracked by git. But you can +use .git/info/exclude for the same purpose. Add build.log and maybe +strace.out there. EOF } @@ -185,6 +201,7 @@ Usage: $SELF [-jN] [-n] [variable=value ...] -n Allow the SlackBuild to access the network. -t Don't use trackfs to watch for writes to system files. -s Run the script with strace, output in "strace.out". +-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. -h, --help @@ -283,7 +300,8 @@ while printf -- "$1" | grep -q ^-; do -j*) MAKEFLAGS="$1" ;; -n) NETWORK=yes ;; -t) TRACK=no ;; - -s) TRACK=no; STRACE=yes ;; + -s) TRACK=no; STRACE=-f ;; + -S) TRACK=no; STRACE=-ff ;; -x) X="-x" ;; -c) CLEANUP="yes" ;; -h|-help|--help) show_help ; exit 0 ;; @@ -294,7 +312,15 @@ while printf -- "$1" | grep -q ^-; do done # warn and die append to the log, make sure it starts out empty. -> $BUILDLOG +# This is the only place we use tee $BUILDLOG (everything else appends). +{ +echo -n "== $SELF starting up at " +date +echo -n "== directory: " +pwd +echo "== command: $0" "$@" +echo +} | tee $BUILDLOG # The easy way to remove the source and PKG dirs after the # script runs is to guarantee they'll be the only things in @@ -359,8 +385,8 @@ if [ "$TRACK" = "yes" ]; then fi -if [ "$STRACE" = "yes" ]; then - TRACKFS="strace -f -ostrace.out" +if [ "$STRACE" != "" ]; then + TRACKFS="strace $STRACE -ostrace.out" fi SCRIPT="./$( pwd | sed 's,.*/,,' ).SlackBuild" @@ -373,7 +399,7 @@ fi echo "Environment: $ENV" echo "File tracking: $TRACK" echo "Network access: $NETWORK" - if [ "$STRACE" = "yes" ]; then + if [ "$STRACE" != "" ]; then echo "strace log: strace.out" fi echo @@ -395,10 +421,11 @@ START_TIME="$( date +%s )" # tracked by trackfs. eval $NSENTER $TRACKFS sh $X $SCRIPT 2>&1 | tee -a $BUILDLOG RET=$? -echo "$SCRIPT exit status: $RET" | tee -a $BUILDLOG END_TIME="$( date +%s )" +echo "$SCRIPT exit status: $RET" | tee -a $BUILDLOG + { echo -n "Elapsed time: " print_hms $(( $END_TIME - $START_TIME )) |