summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2018-08-28 11:03:12 +0200
committerKarel Kočí <karel.koci@nic.cz>2018-08-28 11:03:12 +0200
commite0d47569fa05a84feb6401b52c91d61e814003dd (patch)
tree3c0401aa019b4e71f2b9d43c86f537c50e1f9e56
parent4fb1e1ccb7825c4ae42d98c882978281868974d2 (diff)
downloadlaminar-cnf-e0d47569fa05a84feb6401b52c91d61e814003dd.tar.gz
laminar-cnf-e0d47569fa05a84feb6401b52c91d61e814003dd.tar.bz2
laminar-cnf-e0d47569fa05a84feb6401b52c91d61e814003dd.zip
Implement some lock cleaning
I hope that this will work.
-rw-r--r--scripts/utils36
-rwxr-xr-xtemplates/turris4x.run4
2 files changed, 31 insertions, 9 deletions
diff --git a/scripts/utils b/scripts/utils
index c096f29..0034d9b 100644
--- a/scripts/utils
+++ b/scripts/utils
@@ -1,15 +1,35 @@
# vim: ft=sh
-# Simple echo wrapper for stage marking
+## Simple echo wrappers #########################################################
echo_stage() {
- echo -e "\033[1;34m========== $@ ==========\033[0m"
+ echo -e "\033[1;34m========== $@ ==========\033[0m" >&2
}
-
-# Simple echo wrapper for stage marking
echo_info() {
- echo -e "\033[1;32m---------- $@ ----------\033[0m"
+ 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() {
+ # Free all locks
+ for LOCK in $_LAMINAR_LOCKS; do
+ laminarc unlock "$(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.
@@ -36,13 +56,15 @@ git_fetch() {
# Lock special lock for this job
# Extension appended to lock name has to be provided as first argument
laminar_self_lock() {
- # TODO trap release
+ _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_unlock() {
- # TODO remove trap release
+ _check_trap
laminarc unlock "$(basename "$0")-$1"
+ _LAMINAR_LOCKS="$(echo "$_LAMINAR_LOCKS" | sed "s/ $1//")"
}
diff --git a/templates/turris4x.run b/templates/turris4x.run
index bbc8551..dc461b6 100755
--- a/templates/turris4x.run
+++ b/templates/turris4x.run
@@ -9,6 +9,7 @@ echo_stage "Get packages"
git_fetch "https://git.cynerd.cz/openwrt-personal-pkgs" pkgs
curl "https://repo.turris.cz/$BOARD-$BRANCH/git-hash" > git-hash
+laminar_self_lock sdk
if [ -f "$WORKSPACE/openwrt-git-hash" ] && cmp -s git-hash "$WORKSPACE/openwrt-git-hash"; then
echo_info "Using previous version of SDK"
cp -a "$WORKSPACE/sdk" openwrt
@@ -36,13 +37,12 @@ else
echo_stage "Store SDK in workspace"
cd ..
- laminar_self_lock sdk
rm -rf "$WORKSPACE/sdk"
cp -a openwrt "$WORKSPACE/sdk"
- laminar_self_unlock sdk
cd openwrt
fi
+laminar_self_unlock sdk
echo_stage "Add our repository as feed"
echo "src-git personal file://$WORKSPACE/pkgs" >> feeds.conf