summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-08-29 19:49:30 +0200
committerKarel Kočí <cynerd@email.cz>2018-08-29 19:49:30 +0200
commitab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52 (patch)
tree2763cf89c01f1c221812b9d7b3c4a1361fc36644
parentd96e29faa6ffa38c9576640cad1ca0f0ef645110 (diff)
downloadlaminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.tar.gz
laminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.tar.bz2
laminar-cnf-ab62d2c6a3b30410d5c1bda92e6bd43cebf8ba52.zip
turris4x: replace laminar locks with flock
-rw-r--r--scripts/utils58
-rwxr-xr-xtemplates/turris4x.run26
2 files changed, 26 insertions, 58 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"
-}
diff --git a/templates/turris4x.run b/templates/turris4x.run
index 9321d90..97aa745 100755
--- a/templates/turris4x.run
+++ b/templates/turris4x.run
@@ -5,16 +5,7 @@ set -e
MAKE="make -j4 IS_TTY=1 BUILD_LOG=1"
-laminar_self_lock sdk
-curl "https://repo.turris.cz/$BOARD-$BRANCH/git-hash" > git-hash
-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/openwrt-sdk" openwrt
- cd openwrt
-
-else
- echo_info "Building new version of SDK"
-
+build_sdk() {
echo_stage "Get turris-build"
HASH="$(awk '/ \* turris-build\: /{print $3}' git-hash)"
git_fetch_t "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build "$HASH"
@@ -36,10 +27,21 @@ else
rm -rf "$WORKSPACE/openwrt-sdk"
cp -a openwrt "$WORKSPACE/openwrt-sdk"
cp git-hash "$WORKSPACE/openwrt-git-hash"
- cd openwrt
+}
+
+copy_sdk() {
+ cp -a "$WORKSPACE/openwrt-sdk" openwrt
+}
+curl "https://repo.turris.cz/$BOARD-$BRANCH/git-hash" > git-hash
+if [ -f "$WORKSPACE/openwrt-git-hash" ] && cmp -s git-hash "$WORKSPACE/openwrt-git-hash"; then
+ echo_info "Using previous version of SDK"
+ flock --shared "$WORKSPACE/openwrt-sdk.lock" -c copy_sdk
+else
+ echo_info "Building new version of SDK"
+ flock --exclusive "$WORKSPACE/openwrt-sdk.lock" -c build_sdk
fi
-laminar_self_release sdk
+cd openwrt
echo_stage "Add our repository as feed"
echo "src-git personal git@cynerd.cz:openwrt-personal-pkgs" >> feeds.conf