# vim: ft=sh ## Simple echo wrappers ######################################################### echo_stage() { echo -e "\033[1;34m========== $@ ==========\033[0m" >&2 } echo_info() { echo -e "\033[1;32m---------- $@ ----------\033[0m" >&2 } echo_fail() { echo -e "\033[1;31m---------- $@ ----------\033[0m" >&2 return 1 } ## Cleanup handler ############################################################## _LAMINAR_LOCKS="" _handle_exit() { # Release all locks for LOCK in $_LAMINAR_LOCKS; do laminarc release "$(basename "$0")-$LOCK" done } 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" } ################################################################################# # Fetch bare git repository to WORKSPACE # First argument has to be a source URL # Second argument is name of directory to which will be repository cloned to. git_fetch_bare() { if [ -d "$WORKSPACE/$2" ]; then git --git-dir="$WORKSPACE/$2" --bare remote update --prune else git clone --mirror "$1" "$WORKSPACE/$2" fi } # Calls git_fetch_bare and then creates detached work tree in run directory # First agument has to be a source URL # Second argument is name of directory to which will be directory cloned in. # Second argument is optional and should be branch name (master is used if not # provided). git_fetch() { git_fetch_bare "$1" "$2" local BRANCH="$3" [ -n "$BRANCH" ] || BRANCH=master git --git-dir="$WORKSPACE/$2" --bare worktree add --detach $2 $BRANCH } # 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 "$(basename "$0")-$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 "$(basename "$0")-$1" _LAMINAR_LOCKS="$(echo "$_LAMINAR_LOCKS" | sed "s/ $1//")" }