summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/common23
-rw-r--r--scripts/utils18
-rwxr-xr-xtemplates/turris3x.run2
-rwxr-xr-xtemplates/turris4x.run2
4 files changed, 27 insertions, 18 deletions
diff --git a/scripts/common b/scripts/common
new file mode 100644
index 0000000..7514ea9
--- /dev/null
+++ b/scripts/common
@@ -0,0 +1,23 @@
+# vim: ft=sh
+# Laminar guard
+if [ -z "$WORKSPACE" ]; then
+ echo "This script can be run only from laminar build environment!" >&2
+ exit 1
+fi
+
+# Subprocess inclusion guard
+[ -z "$LAMINAR_COMMON" ]
+export LAMINAR_COMMON=y
+
+# Job and template id
+export JOBID="$(basename "$0" | sed 's/\.run$//')"
+export TEMPLATEID="$(basename "$(readlink -f "$0")" | sed 's/\.run$//')"
+
+# Template workspace
+export TWORKSPACE="$HOME/workspace/$TEMPLATEID"
+if [ "$JOBID" = "$TEMPLATEID" ]; then
+ TWORKSPACE="$HOME/workspace/notemplate"
+fi
+
+# Include utils
+. utils
diff --git a/scripts/utils b/scripts/utils
index a955699..8781882 100644
--- a/scripts/utils
+++ b/scripts/utils
@@ -1,6 +1,7 @@
# vim: ft=sh
+[ -n "$LAMINAR_COMMON" ] # variables definition guard
-if [ "$V" -ge 2 ]; then
+if [ "$V" -ge 3 ]; then
set -x
fi
@@ -19,21 +20,6 @@ echo_fail() {
return 1
}
-## Job and template IDs #########################################################
-# 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"
-
## GIT ##########################################################################
# Fetch bare git repository
# First argument has to be a source URL
diff --git a/templates/turris3x.run b/templates/turris3x.run
index 98dfa15..1327e24 100755
--- a/templates/turris3x.run
+++ b/templates/turris3x.run
@@ -1,7 +1,7 @@
#!/bin/sh
# vim: ft=sh
set -e
-. utils
+. common
echo_stage "Get packages"
git_clone "git@cynerd.cz:openwrt-personal-pkgs" pkgs turris3x
diff --git a/templates/turris4x.run b/templates/turris4x.run
index 4c2623e..a5405b5 100755
--- a/templates/turris4x.run
+++ b/templates/turris4x.run
@@ -1,7 +1,7 @@
#!/bin/sh
# vim: ft=sh
set -e
-. utils
+. common
if [ "$V" -ge 1 ]; then
MAKE="make -j1 IS_TTY=1 BUILD_LOG=1 V=99"