home · contact · privacy
reorganize dependencies. master
authorChristian Heller <c.heller@plomlompom.de>
Tue, 25 Mar 2025 16:40:31 +0000 (17:40 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 25 Mar 2025 16:40:31 +0000 (17:40 +0100)
testing/scripts/_config_scripts_lib.sh [deleted file]
testing/scripts/_setup_secrets_user.sh
testing/scripts/lib/abort [new file with mode: 0644]
testing/scripts/lib/abort_if_exists [new file with mode: 0644]
testing/scripts/lib/abort_if_not_user [new file with mode: 0644]
testing/scripts/lib/abort_if_offline [new file with mode: 0644]
testing/scripts/lib/constants [new file with mode: 0644]
testing/scripts/lib/expect_min_n_args [new file with mode: 0644]
testing/scripts/setup_desktop.sh
testing/scripts/setup_secrets.sh

diff --git a/testing/scripts/_config_scripts_lib.sh b/testing/scripts/_config_scripts_lib.sh
deleted file mode 100644 (file)
index 62f9fcc..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# NB: this all assumes we're run from script's parent directory
-PARENT_DIR=$(dirname $(pwd))
-DEBIAN_RELEASE=$(basename ${PARENT_DIR})
-PATH_REPO=$(dirname ${PARENT_DIR})
-PATH_CONF="${PATH_REPO}/${DEBIAN_RELEASE}"
-PATH_CONF_HOME="${PATH_CONF}/home"
-
-USERNAME=plom
-PATH_USER_HOME="/home/${USERNAME}"
-
-expect_min_n_args() {
-    MIN_ARGS="$1"
-    EXPLAINER="$2"
-    shift 2
-    if [ "$#" -lt "${MIN_ARGS}" ]; then
-        echo "Need at least ${MIN_ARGS} arguments … ${EXPLAINER}"
-        false
-    fi
-}
-
-_abort() {
-    echo "Aborting: $1"
-    exit 1
-}
-
-abort_if_exists() {
-    if [ -e "$1" ]; then
-        _abort "$1 already exists."
-    fi
-}
-
-abort_if_not_user() {
-    if [ "$(whoami)" != "$1" ]; then
-        _abort "Must be run as ${1}."
-    fi
-}
-
-abort_if_offline() {
-    if ! ping -c1 -W2 1.1.1.1 > /dev/null 2>&1; then
-        _abort 'Must be run online.'
-    fi
-}
index 60196c313ad68c9daf789d9b59408dafc0ffabb2..30e08aadd5278b31babbe67f8a4834944d75e547 100644 (file)
@@ -2,12 +2,11 @@
 set -e
 cd $(dirname "$0")
 
 set -e
 cd $(dirname "$0")
 
-. ./_config_scripts_lib.sh
-# for:
-# abort_if_exists
-# abort_if_not_user
-# abort_if_offline
-# - USERNAME
+. lib/constants  # USERNAME
+. lib/abort
+. lib/abort_if_exists
+. lib/abort_if_not_user
+. lib/abort_if_offline
 
 PATH_REPOS="${HOME}/repos"
 PATH_BORGKEYS="${HOME}/.config/borg/keys"
 
 PATH_REPOS="${HOME}/repos"
 PATH_BORGKEYS="${HOME}/.config/borg/keys"
@@ -83,7 +82,6 @@ while true; do
     if [ "${RESULT}" = "0" ]; then
         break
     elif [ "${RESULT}" != "2" ]; then
     if [ "${RESULT}" = "0" ]; then
         break
     elif [ "${RESULT}" != "2" ]; then
-        echo "Aborting due to unexpected ${NAME_BORGAPP} error."
-       exit 1
+        abort "Aborting due to unexpected ${NAME_BORGAPP} error."
     fi
 done
     fi
 done
diff --git a/testing/scripts/lib/abort b/testing/scripts/lib/abort
new file mode 100644 (file)
index 0000000..b0a1704
--- /dev/null
@@ -0,0 +1,4 @@
+abort() {
+    echo "$1"
+    exit 1
+}
diff --git a/testing/scripts/lib/abort_if_exists b/testing/scripts/lib/abort_if_exists
new file mode 100644 (file)
index 0000000..a459a38
--- /dev/null
@@ -0,0 +1,6 @@
+abort_if_exists() {
+    if [ -e "$1" ]; then
+        abort "$1 already exists."
+    fi
+}
+
diff --git a/testing/scripts/lib/abort_if_not_user b/testing/scripts/lib/abort_if_not_user
new file mode 100644 (file)
index 0000000..a7b3da3
--- /dev/null
@@ -0,0 +1,7 @@
+. lib/abort
+
+abort_if_not_user() {
+    if [ "$(whoami)" != "$1" ]; then
+        abort "Must be run as ${1}."
+    fi
+}
diff --git a/testing/scripts/lib/abort_if_offline b/testing/scripts/lib/abort_if_offline
new file mode 100644 (file)
index 0000000..b81c784
--- /dev/null
@@ -0,0 +1,7 @@
+. lib/abort
+
+abort_if_offline() {
+    if ! ping -c1 -W2 1.1.1.1 > /dev/null 2>&1; then
+        abort 'Must be run online.'
+    fi
+}
diff --git a/testing/scripts/lib/constants b/testing/scripts/lib/constants
new file mode 100644 (file)
index 0000000..90747aa
--- /dev/null
@@ -0,0 +1,2 @@
+USERNAME=plom
+PATH_USER_HOME="/home/${USERNAME}"
diff --git a/testing/scripts/lib/expect_min_n_args b/testing/scripts/lib/expect_min_n_args
new file mode 100644 (file)
index 0000000..8f9c74d
--- /dev/null
@@ -0,0 +1,9 @@
+expect_min_n_args() {
+    MIN_ARGS="$1"
+    EXPLAINER="$2"
+    shift 2
+    if [ "$#" -lt "${MIN_ARGS}" ]; then
+        echo "Need at least ${MIN_ARGS} arguments … ${EXPLAINER}"
+        false
+    fi
+}
index 0473b46be2025cac0e0e5e20a50a5243eb73e0cf..53327efd22ee9d63b0786f8fe4ef28841a1f46ca 100755 (executable)
@@ -2,15 +2,16 @@
 set -e
 cd $(dirname "$0")
 
 set -e
 cd $(dirname "$0")
 
-. ./_config_scripts_lib.sh
-# for:
-# - abort_if_offline
-# - expect_min_n_args
-# - PATH_CONF
-# - PATH_CONF_HOME
-# - PATH_REPO
-# - PATH_USER_HOME
-# - USERNAME
+. lib/constants  # PATH_USER_HOME, USERNAME
+. lib/expect_min_n_args
+. lib/abort
+. lib/abort_if_offline
+
+PARENT_DIR=$(dirname $(pwd))
+DEBIAN_RELEASE=$(basename ${PARENT_DIR})
+PATH_REPO=$(dirname ${PARENT_DIR})
+PATH_CONF="${PATH_REPO}/${DEBIAN_RELEASE}"
+PATH_CONF_HOME="${PATH_CONF}/home"
 
 PATH_REL_ETC=etc
 PATH_CONF_ETC="${PATH_CONF}/${PATH_REL_ETC}"
 
 PATH_REL_ETC=etc
 PATH_CONF_ETC="${PATH_CONF}/${PATH_REL_ETC}"
@@ -64,8 +65,7 @@ abort_if_illegal_system_name() {
            return 0
         fi
     done
            return 0
         fi
     done
-    echo "Need legal system name."
-    exit 1
+    abort 'Need legal system name.'
 }
 
 upgrade_from_older_release() {
 }
 
 upgrade_from_older_release() {
index 10c6ad4af15c33c999889494857685ac3639ef7c..4eb26459a83a3f6ff6598acf599305d8c04b0062 100755 (executable)
@@ -2,14 +2,12 @@
 set -e
 cd $(dirname "$0")
 
 set -e
 cd $(dirname "$0")
 
-. ./_config_scripts_lib.sh
-# for:
-# - abort_if_exists
-# - abort_if_not_user
-# - abort_if_offline
-# - expect_min_n_args
-# - PATH_USER_HOME
-# - USERNAME
+. lib/constants  # PATH_USER_HOME, USERNAME
+. lib/expect_min_n_args
+. lib/abort
+. lib/abort_if_exists
+. lib/abort_if_not_user
+. lib/abort_if_offline
 
 . "${PATH_USER_HOME}/.plomlib.sh/get_passphrase"
 . "${PATH_USER_HOME}/.plomlib.sh/path_tmp_timestamped"
 
 . "${PATH_USER_HOME}/.plomlib.sh/get_passphrase"
 . "${PATH_USER_HOME}/.plomlib.sh/path_tmp_timestamped"
@@ -17,9 +15,6 @@ cd $(dirname "$0")
 PATH_REL_SECRETS=to_usb
 export PATH_SECRETS="${PATH_USER_HOME}/${PATH_REL_SECRETS}"
 
 PATH_REL_SECRETS=to_usb
 export PATH_SECRETS="${PATH_USER_HOME}/${PATH_REL_SECRETS}"
 
-abort_if_not_user root
-abort_if_offline
-
 # Mount secrets device and copy over its content.
 abort_if_exists "${PATH_SECRETS}"
 expect_min_n_args 1 "(device name, e.g. 'sda')" "$@"
 # Mount secrets device and copy over its content.
 abort_if_exists "${PATH_SECRETS}"
 expect_min_n_args 1 "(device name, e.g. 'sda')" "$@"
@@ -42,10 +37,9 @@ while true; do
     if [ "${RESULT}" = "0" ]; then
         break
     elif [ "${RESULT}" != "100" ]; then
     if [ "${RESULT}" = "0" ]; then
         break
     elif [ "${RESULT}" != "100" ]; then
-        echo "Aborting due to pmount error:"
-       cat "${PATH_PMOUNT_ERR}"
+       PMOUNT_ERR="$(cat ${PATH_PMOUNT_ERR})"
        rm "${PATH_PMOUNT_ERR}"
        rm "${PATH_PMOUNT_ERR}"
-       exit 1
+        abort "Aborting due to pmount error: ${PMOUNT_ERR}"
     fi
 done
 cp -a "${PATH_SOURCE}" "${PATH_SECRETS}"
     fi
 done
 cp -a "${PATH_SOURCE}" "${PATH_SECRETS}"