Cleanup ZEDLETs

This commit factors out several common ZEDLET code blocks into
zed-functions.sh.  This shortens the length of the scripts, thereby
(hopefully) making them easier to understand and maintain.

In addition, this commit revamps the coding style used by the
scripts to be more consistent and (again, hopefully) maintainable.
It now mostly follows the Google Shell Style Guide.  I've tried to
assimilate the following resources:

  Google Shell Style Guide
  https://google-styleguide.googlecode.com/svn/trunk/shell.xml

  Dash as /bin/sh
  https://wiki.ubuntu.com/DashAsBinSh

  Filenames and Pathnames in Shell: How to do it Correctly
  http://www.dwheeler.com/essays/filenames-in-shell.html

  Common shell script mistakes
  http://www.pixelbeat.org/programming/shell_script_mistakes.html

Finally, this commit updates the exit codes used by the ZEDLETs to be
more consistent with one another.

All scripts run cleanly through ShellCheck <http://www.shellcheck.net/>.
All scripts have been tested on bash and dash.

Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
This commit is contained in:
Chris Dunlap
2015-02-17 17:23:54 -08:00
committed by Brian Behlendorf
parent 0336f3d001
commit aded9a6814
11 changed files with 624 additions and 331 deletions
+13 -6
View File
@@ -2,16 +2,23 @@
#
# Log all environment variables to ZED_DEBUG_LOG.
#
test -f "${ZED_ZEDLET_DIR}/zed.rc" && . "${ZED_ZEDLET_DIR}/zed.rc"
# This can be a useful aid when developing/debugging ZEDLETs since it shows the
# environment variables defined for each zevent.
[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
. "${ZED_ZEDLET_DIR}/zed-functions.sh"
: "${ZED_DEBUG_LOG:="${TMPDIR:="/tmp"}/zed.debug.log"}"
lockfile="$(basename -- "${ZED_DEBUG_LOG}").lock"
# Override the default umask to restrict access to a newly-created logfile.
umask 077
# Append stdout to the logfile after obtaining an advisory lock.
exec >> "${ZED_DEBUG_LOG:=/tmp/zed.debug.log}"
flock -x 1
zed_lock "${lockfile}"
exec >> "${ZED_DEBUG_LOG}"
printenv | sort
echo
exec >&-
zed_unlock "${lockfile}"
exit 0