fix: lib/runscripts/util.run: runscript template: all(): moved example commands to target(), where they would more likely be located
bugfix: lib/runscripts/util.run: $is_runscript: unexport so don't pass it to invoked scripts
bugfix: lib/runscripts/util.run: run_args_cmd(): don't prepend main to args if no args, because for a non-runscript, all args will be passed to main(), leading `main` to be doubled
bugfix: lib/runscripts/util.run: a non-runscript should have all args passed to main(). this fixes a bug in backups/*_snapshot where "main" would need to be prepended to any args for the script to run correctly.
bugfix: lib/runscripts/util.run: $wrap_fn: invoked script must always run as runscript so that wrapped command is run
lib/runscripts/util.run: added $is_runscript, for use by $wrap_fn
bugfix: lib/runscripts/util.run: $wrap_fn: $top_script doesn't need to be world-executable for most uses of sudo (only if sudoing to non-root)
lib/runscripts/util.run: sudo(): avoid slow $wrap_fn when using `command` (ie. always executable)
bugfix: lib/runscripts/util.run: $subdirs: adjusted log_level now that echo_vars is one log_level lower
lib/runscripts/util.run: $wrap_fn: log at higher log_level because it's startup code
lib/sh/util.sh, runscripts/util.run: set_paths(): run with higher log_level to hide all the paths that are set at the beginning of the script
lib/runscripts/util.run: added sudo() override that uses $wrap_fn to support shell functions
fix: lib/runscripts/util.run: $wrap_fn: make it usable even if $top_script isn't world-executable
fix: lib/runscripts/util.run: to_top_file(): handle $_remake properly, without requiring deferred_check_target_exists to set to_file()'s flags
*{.sh,run}: runscript targets: use begin_target instead of echo_func so the target name is properly echoed. note that this requires using with_rm so that $rm is properly progagated to applicable invoked targets. (previously, $rm was progagated to all invoked targets. note that with_rm only works inside a runscript target that starts with begin_target.)
lib/sh/make.sh: self_make(): renamed to with_rm() for clarity, since this is used only to progagate $rm, and does not also invoke a command with the same name as the current function, as the name might suggest
lib/runscripts/util.run: support conventional main() method as well as `all` target
lib/runscripts/util.run: on_exit(): documented that users can also override gateway()/fallback() to perform other commands (or no commands) after the script is read
fix: lib/runscripts/util.run: run_args_cmd(): need to indent the output of the target that it's running
lib/sh/util.sh: clog*: renamed to log* for clarity (possible now that log* is no longer used for function-local log_level setting)
lib/runscripts/util.run: runscript template: added sample make target, using new make target template
bugfix: lib/runscripts/util.run: $auto_ignore: need to unexport it so don't pass this to invoked scripts except through fwd()
bugfix: lib/runscripts/util.run: auto_fwd's fallback() must be set after auto_ignore's fallback() to overwrite it (auto_ignore should only apply if an error would otherwise have been generated by the fallback)
lib/runscripts/util.run: fwd(): support subdirs that don't contain a runscript, so that the default value of @subdirs will work in most cases
lib/runscripts/util.run: fwd(): set default @subdirs (`{.,}*/`)
lib/runscripts/util.run: fwd(): enable $auto_ignore so that each subdir doesn't have to have a definition for the forwarded target
lib/runscripts/util.run: added $auto_ignore switch, which causes fallback() not to generate an error that a non-existant target doesn't exist
lib/runscripts/util.run: added fwd_self alias
lib/runscripts/util.run: added $auto_fwd switch
bugfix: lib/runscripts/util.run: gateway(): need to use is_callable() rather than func_exists() to check whether the target exists, because external commands (eg. echo) are supported as targets, too
lib/runscripts/util.run: support custom handlers for all targets (gateway()) as well as targets w/o function (fallback())
moved everything into /trunk/ to create the standard svn layout, for use with tools that require this (eg. git-svn). IMPORTANT: do NOT do an `svn up`. instead, re-use your working copy's existing files with `svn switch` (http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.switch.html).
bugfix: lib/runscripts/util.run: `trap on_exit EXIT`: only set this if the script is not a dot script, because if it is a dot script, on_exit() will not be invoked until the calling shell exits, which may be much later than when the script is run. previously, this was handled by canceling the EXIT trap if on_exit() is run manually, but this would not work correctly if a load-time error prevented on_exit() from running and canceling the trap.
bugfix: lib/runscripts/util.run: if is_dot_script, fix $ when no args causes this to incorrectly contain the script name. use is_dot_script rather than the presence of $ args to decide whether to use @BASH_ARGV, because @BASH_ARGV is actually wrong when run as a .-script (it contains the script name).
when no args causes this to incorrectly contain the script name. use is_dot_script rather than the presence of $
lib/runscripts/util.run: run script template: changed sample command name to all() because each runscript requires this in order to be run without args
lib/runscripts/util.run: support scripts that are run as shell-includes (with leading "."), by allowing the calling script to manually invoke on_exit() without it then being invoked twice (the end of a shell-include does not trigger the EXIT trap)
lib/runscripts/util.run: support scripts that are run as shell-includes (with leading "."), by also accepting $@ args that are passed along in the util.run include, in addition to @BASH_ARGV
bugfix: lib/runscripts/util.run: to_top_file(): need to pass "$@" to to_file
lib/runscripts/util.run: to_top_file: added function for this (in addition to alias), so that this can be run from sudo in a wrap_fn command
lib/runscripts/util.run: added $wrap_fn to run any function via sudo, etc.
lib/runscripts/util.run: usage: documented that this usage also applies to all files that include this file
lib/runscripts/util.run: usage: clarified that the cmd to run is a function
lib/runscripts/util.run: added to_top_file alias for use with $top_file
lib/runscripts/util.run: added , function, which treats each of the command-line args as commands the way make does (instead of as args to the same command, the way runscripts do)
lib/sh/util.sh: moved runscript-related commands to lib/runscripts/util.run because these only apply to runscripts
*{.sh,run}: use simpler .rel() instead of `. "$(dirname "${BASH_SOURCE0}")"/...` for relative includes
bugfix: lib/runscripts/util.run: need to include sh/make.sh for all runscripts that use make-style commands
lib/sh/util.sh: run_args_cmd(): moved test of $? to lib/runscripts/util.run on_exit() since it needs to be performed for all run_args_cmd() functions, not just the default implementation. (this test ensures that no commands are executed if the EXIT trap was encountered due to a parsing/loading error).
lib/runscripts/util.run: added setting of $top_file, $top_filename to set_paths()
lib/runscripts/util.run: set $top_file, $top_filename in a function (set_paths__util_run())
lib/runscripts/util.run: $top_file: also match dir-level runscripts by removing /run suffix
*{.sh,run}: echo all global vars (except those defined before echo_vars is available)
*{.sh,run}: removed extra space between function name and (), which is apparently not needed even though `help function` includes it. this greatly improves readability, including when function names are pasted into commit messages!
moved lib/*.sh to sh/ subdir so it's easier to find the .sh files among all the other lib/ files
lib/util.sh: run all commands verbosely by default, not just runscripts. this ensures verbose output for invoked commands like inputs/GBIF/MySQL_export.
lib/util.sh: moved $top_file* to runscripts/util.run because they only apply to runscripts
lib/runscripts/util.run: tell users to override run_args_cmd rather than this function to perform other commands, so that on_exit () can contain other exit-related processing that should not be overriden by the user
lib/util.sh: echo_vars (): output vars with log_level 3 so they can be excluded separately from function calls to reduce clutter in the logging output. increase the default util.run verbosity so that vars are still printed by default.
*{.sh,run}: changed echo_func to an alias that includes the "$", so that callers don't need to specify the "$" manually. although the original echo_func function is still there, callers need to switch over to the alias at the same time as it's defined because otherwise the "$@" would be doubled, since echo_func refers to the alias instead.
", so that callers don't need to specify the "$
moved lib/*.run into runscripts/ subdir so runscripts are grouped together and easier to find rather than being scattered throughout lib/
lib/util.run: doc comment: changed "run scripts" to "runscripts"
lib/util.run: factored general utils (non-runscript-specific) out into new util.sh
lib/util.run: renamed $verbose to $verbosity because it's an integer level, not a boolean. continue to support specifying the verbosity in $verbose.
lib/util.run: support $verbose="", which is treated as 0
lib/util.run: only automatically echo env vars when they are set if verbosity is >= 2
lib/util.run: added $verbose var to control logging. this is normally set to 0, but defaults to 2 for a runscript.
lib/util.run: moved `shopt -s expand_aliases` inside the include guard so callers can override the setting without it being reset if util.run is included again
bugfix: lib/util.run: added include guard to prevent issues in "diamond includes", where a runscript includes two runscripts and each includes util.run, causing the second include of util.run to reset any methods overridden in the first included runscript. this prevents util.run from being included twice in the first place.
lib/util.run: added include_guard_var (), self_not_included () for use by path-based include guards
lib/util.run: echo_stdin (): print a separator before and after the echoed output to help distinguish it from other verbose output
lib/util.run: echo_export (): run the export builtin using `builtin` to avoid recursively calling any export alias or function defined by the user (e.g. `alias export=echo_export`. this causes util.run to be idempotent, such that it can be included multiple times without causing problems due to the redefinition of functions, vars, etc.
lib/util.run: added set_var ()
bugfix: lib/util.run: run_args_cmd (): `set --`: need to use eval so that the output of reverse is interpreted as escaped args rather than split using $IFS
bugfix: lib/util.run: run_args_cmd (): BASH_ARGV is stored in reverse order, so it needs to be reversed to be usable as $@
lib/util.run: added reverse ()
lib/util.run: added zip/unzip_newer aliases
lib/util.run: added zip/unzip echo_run aliases
bugfix: lib/util.run: inline_make (): put echo_func at the top of the function
lib/util.run: inline_make (): pass Makefile commands using /dev/fd/3 (i.e. 3<<'EOF' ...) instead of stdin, to allow stdin to be used by commands that prompt the user
lib/util.run: inline_make (): use <() to pass Makefile commands as a named descriptor rather than using stdin, to allow stdin to be used by commands that prompt the user
bugfix: lib/util.run: echo_vars (): remove any value to set (=*) from the vars, since this is often used with export
bugfix: lib/util.run: echo_export (): set the vars before echoing them
lib/util.run: run_args_cmd (): use new canon_rel_path() to resolve .. in the script path, so it's easier to see where the script is actually located
lib/util.run: echo_func (): use new canon_rel_path() to resolve .. in the script path, so it's easier to see where the script is actually located
lib/util.run: added canon_rel_path ()
lib/util.run: inline_make (): provide $self as make var
lib/util.run: inline_make (): provide self_dir to make as env var instead of as make var, to avoid specifying every make var both as a local var and as a make var in the make command
lib/util.run: export alias: added comment explaining what it does
lib/util.run: aliased export to echo_export so all env vars are automatically echoed when they are set
lib/util.run: added echo_vars (), echo_export ()
lib/util.run: inline_make (): added local $self and use it to create $self_dir
lib/util.run: inline_make (): set $self_dir as a local var before passing it to make, to avoid clutter in the command that invokes make
lib/util.run: run_cmd (): renamed to run_args_cmd to clarify that this runs only the command line args command, not any command. added doc comment to clarify this.
lib/util.run: EXIT trap: use on_exit() function which calls run_cmd instead of having run_cmd be the handler, so that users can override this function to perform other commands (or no commands) after the script is read
lib/util.run: echo_func (): use the caller's FUNCNAME via the $FUNCNAME[] array instead of requiring them to pass it in the function args as `echo_func "$FUNCNAME" "$@"`
lib/util.run: echo_func: Fixed bug where need to use BASH_LINENO0 for the line #s to match up with the files. For some reason the required array indexes for BASH_SOURCE (1) and BASH_LINENO (0) differ by one.
lib/util.run: echo_func: Include the line # of the function to make it easier to find where the code being run is
lib/util.run: run_cmd: If bash exited with an error, don't run the "$@" command. This test is necessary because `trap run_cmd EXIT` will run run_cmd as the result of any exit from the shell, including an error.
*run: Use -e option to bash on the #! line instead of separate `set -o errexit` line so that there is no issue with the `set -o errexit` line getting separated from the #! line (errexit is required for the scripts to work properly)
lib/util.run: run_cmd: When no command specified, default to running the `all` command, just like make