From: Christian Heller Date: Tue, 25 Mar 2025 16:40:31 +0000 (+0100) Subject: reorganize dependencies. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/do_tasks?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=config reorganize dependencies. --- diff --git a/testing/scripts/_config_scripts_lib.sh b/testing/scripts/_config_scripts_lib.sh deleted file mode 100644 index 62f9fcc..0000000 --- a/testing/scripts/_config_scripts_lib.sh +++ /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 -} diff --git a/testing/scripts/_setup_secrets_user.sh b/testing/scripts/_setup_secrets_user.sh index 60196c3..30e08aa 100644 --- a/testing/scripts/_setup_secrets_user.sh +++ b/testing/scripts/_setup_secrets_user.sh @@ -2,12 +2,11 @@ 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" @@ -83,7 +82,6 @@ while true; do 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 diff --git a/testing/scripts/lib/abort b/testing/scripts/lib/abort new file mode 100644 index 0000000..b0a1704 --- /dev/null +++ b/testing/scripts/lib/abort @@ -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 index 0000000..a459a38 --- /dev/null +++ b/testing/scripts/lib/abort_if_exists @@ -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 index 0000000..a7b3da3 --- /dev/null +++ b/testing/scripts/lib/abort_if_not_user @@ -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 index 0000000..b81c784 --- /dev/null +++ b/testing/scripts/lib/abort_if_offline @@ -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 index 0000000..90747aa --- /dev/null +++ b/testing/scripts/lib/constants @@ -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 index 0000000..8f9c74d --- /dev/null +++ b/testing/scripts/lib/expect_min_n_args @@ -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 +} diff --git a/testing/scripts/setup_desktop.sh b/testing/scripts/setup_desktop.sh index 0473b46..53327ef 100755 --- a/testing/scripts/setup_desktop.sh +++ b/testing/scripts/setup_desktop.sh @@ -2,15 +2,16 @@ 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}" @@ -64,8 +65,7 @@ abort_if_illegal_system_name() { return 0 fi done - echo "Need legal system name." - exit 1 + abort 'Need legal system name.' } upgrade_from_older_release() { diff --git a/testing/scripts/setup_secrets.sh b/testing/scripts/setup_secrets.sh index 10c6ad4..4eb2645 100755 --- a/testing/scripts/setup_secrets.sh +++ b/testing/scripts/setup_secrets.sh @@ -2,14 +2,12 @@ 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" @@ -17,9 +15,6 @@ cd $(dirname "$0") 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')" "$@" @@ -42,10 +37,9 @@ while true; do 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}" - exit 1 + abort "Aborting due to pmount error: ${PMOUNT_ERR}" fi done cp -a "${PATH_SOURCE}" "${PATH_SECRETS}"