diff options
author | Karel Kočí <cynerd@email.cz> | 2018-08-29 19:49:30 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2018-08-29 19:49:30 +0200 |
commit | ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52 (patch) | |
tree | 2763cf89c01f1c221812b9d7b3c4a1361fc36644 /scripts | |
parent | d96e29faa6ffa38c9576640cad1ca0f0ef645110 (diff) | |
download | laminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.tar.gz laminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.tar.bz2 laminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.zip |
turris4x: replace laminar locks with flock
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/utils | 58 |
1 files changed, 12 insertions, 46 deletions
diff --git a/scripts/utils b/scripts/utils index 2d549e6..86edaa9 100644 --- a/scripts/utils +++ b/scripts/utils @@ -1,19 +1,5 @@ # vim: ft=sh -# Returns current job's id -jobid() { - basename "$0" | sed 's/\.run$//' -} - -# Return current template's id -# If this is not template then this returns job's id -templateid() { - basename "$(readlink -f "$0")" | sed 's/\.run$//' -} - -TWORKSPACE="$HOME/workspace/$(templateid)" -[ "$(jobid)" != "$(templateid)" ] || TWORKSPACE="$HOME/Workspace/notemplate" - ## Simple echo wrappers ######################################################### echo_stage() { echo -e "\033[1;34m========== $@ ==========\033[0m ($(date))" >&2 @@ -29,24 +15,22 @@ echo_fail() { return 1 } -## Cleanup handler ############################################################## -_LAMINAR_LOCKS="" -_handle_exit() { - # Release all locks - for LOCK in $_LAMINAR_LOCKS; do - laminarc release "$(jobid)-$LOCK" - done +## Job and template IDs ######################################################### +# Returns current job's id +jobid() { + basename "$0" | sed 's/\.run$//' } -trap _handle_exit EXIT -# Verify that we are running in process that was configured with trap (not in -# subprocess) -_check_trap() { - [ -n "$(trap -p EXIT)" ] || \ - echo_fail "Unable to use this function as trap handling is not available in subprocess" +# Return current template's id +# If this is not template then this returns job's id +templateid() { + basename "$(readlink -f "$0")" | sed 's/\.run$//' } -################################################################################# +TWORKSPACE="$HOME/workspace/$(templateid)" +[ "$(jobid)" != "$(templateid)" ] || TWORKSPACE="$HOME/workspace/notemplate" + +## GIT ########################################################################## # Fetch bare git repository # First argument has to be a source URL # Second argument is path to directory to which will be repository cloned to. @@ -102,21 +86,3 @@ git_clone() { git checkout FETCH_HEAD ) } - -# Lock special lock for this job -# Extension appended to lock name has to be provided as first argument -laminar_self_lock() { - _check_trap - _LAMINAR_LOCKS="$_LAMINAR_LOCKS $1" - laminarc lock "$(jobid)-$1" - echo_debug "Locking $1" -} - -# Unlock special lock for this job -# Extension appended to lock name has to be provided as first argument -laminar_self_release() { - _check_trap - laminarc release "$(jobid)-$1" - _LAMINAR_LOCKS="$(echo "$_LAMINAR_LOCKS" | sed "s/ $1//")" - echo_debug "Releasing $1" -} |