From ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 29 Aug 2018 19:49:30 +0200 Subject: turris4x: replace laminar locks with flock --- scripts/utils | 58 ++++++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'scripts') 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" -} -- cgit v1.2.3