home · contact · privacy
Fixes.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 4 Apr 2025 17:28:32 +0000 (19:28 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 4 Apr 2025 17:28:32 +0000 (19:28 +0200)
bookworm/scripts/init_server_access.sh [deleted file]
bookworm/scripts/lib/abort_if_command_unknown [new file with mode: 0644]
bookworm/scripts/lib/constants_installer
bookworm/scripts/lib/expect_n_args [new file with mode: 0644]
bookworm/scripts/lib/get_mountable_device_path
bookworm/scripts/make_writable_installer.sh
bookworm/scripts/update_preseed.sh
testing/home/desktop/.local/bin/borgplom
testing/scripts/init_server_access.sh [new file with mode: 0755]
testing/scripts/lib/expect_n_args [new symlink]

diff --git a/bookworm/scripts/init_server_access.sh b/bookworm/scripts/init_server_access.sh
deleted file mode 100755 (executable)
index 385b3b3..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-set -e
-cd $(dirname "$0")
-. lib/constants_ssh  # PATH_USER_SSH
-. lib/expect_min_n_args
-
-PATH_KNOWN_HOSTS="${PATH_USER_SSH}/known_hosts"
-
-expect_min_n_args 1 '(server)' "$@"
-SERVER="$1"
-
-echo '\nKnow host.\n'
-set +e
-ssh-keygen -f "${PATH_KNOWN_HOSTS}" -R "${SERVER}"
-set -e
-ssh-keyscan "${SERVER}" >> "${PATH_KNOWN_HOSTS}"
-
-echo '\nAsking for new root password.\n'
-stty -echo
-ssh "root@${SERVER}" 'printf "\n\n" && passwd'
-stty echo
-
-echo '\nSetting up config repo.'
-ssh "root@${SERVER}" 'apt update && apt install -y git && git clone https://plomlompom.com/repos/clone/config'
diff --git a/bookworm/scripts/lib/abort_if_command_unknown b/bookworm/scripts/lib/abort_if_command_unknown
new file mode 100644 (file)
index 0000000..81a3365
--- /dev/null
@@ -0,0 +1,7 @@
+. lib/abort
+
+abort_if_command_unknown() {
+    if ! which "$1" > /dev/null; then
+        abort "Expected command unavailable: ${1}."
+    fi
+}
index b710116ca2d2feacc9d8d1c3a12269c9443ac696..92e60df9b95a8af5be5e1248133bcd98522ff940 100644 (file)
@@ -1,3 +1,2 @@
 FILENAME_PRESEED_CFG=preseed.cfg
 PATH_PRESEED_CFG="../${FILENAME_PRESEED_CFG}"
-PATH_MNT_STICK=/mnt/stick
diff --git a/bookworm/scripts/lib/expect_n_args b/bookworm/scripts/lib/expect_n_args
new file mode 100644 (file)
index 0000000..950671a
--- /dev/null
@@ -0,0 +1,21 @@
+. lib/abort
+
+expect_n_args() {
+    _N_MIN_ARGS="$1"
+    _N_MAX_ARGS="$2"
+    _USAGE="$3"
+    shift 3
+    _ABORT_MSG=
+    if [ "$#" -lt "${_N_MIN_ARGS}" ]; then
+        _ABORT_MSG="missing arguments (got $# instead of ${_N_MAX_ARGS})."
+    elif [ "$#" -gt "${_N_MAX_ARGS}" ]; then
+        shift "${_N_MAX_ARGS}"
+        _ABORT_MSG="unexpected arguments beyond expected number (${_N_MAX_ARGS}): $@"
+    fi
+    if [ ! -z "${_ABORT_MSG}" ]; then 
+        if [ ! -z "${_USAGE}" ]; then 
+            _ABORT_MSG="${_ABORT_MSG}\nExpected arguments: ${_USAGE}"
+        fi 
+        abort "Aborting due to ${_ABORT_MSG}"
+    fi
+}
index 7090a46a51783d05ba0df0d3c9b19f9be36ad44f..b0a1cd5e7eaa0993ee4d877fca69070690402994 100644 (file)
@@ -1,11 +1,11 @@
 . lib/abort
 
 get_mountable_device_path() {
-    PATH_DEV="/dev/$1"
-    if [ ! -b "${PATH_DEV}" ]; then
-        abort "No block device at ${PATH_DEV}."
-    elif [ $(mount | grep -E "^${PATH_DEV}" | wc -l) -gt 0 ]; then
-        abort "${PATH_DEV} already mounted."
+    _PATH_DEV="/dev/$1"
+    if [ ! -b "${_PATH_DEV}" ]; then
+        abort "No block device at ${_PATH_DEV}."
+    elif [ $(mount | grep -E "^${_PATH_DEV}" | wc -l) -gt 0 ]; then
+        abort "${_PATH_DEV} already mounted."
     fi
-    printf "${PATH_DEV}"
+    printf "${_PATH_DEV}"
 }
index d8283445033552e3271bca4cecdf289ed157567a..1cf871df4cff03ef6d17dd47d32d367cf67a8e63 100755 (executable)
@@ -3,28 +3,24 @@
 set -e
 cd $(dirname "$0")
 . lib/abort
+. lib/abort_if_command_unknown
 . lib/abort_if_not_user
 . lib/abort_if_offline
 . lib/constants_installer
-. lib/expect_min_n_args
+. lib/expect_n_args
 . lib/get_mountable_device_path
 
 INSTALLER_VERSION=12.10.0
 PATH_MNT_ISO=/mnt/iso
 
+expect_n_args 1 1 'DEVICE (e.g. "sdb")' $@
 abort_if_not_user root
-abort_if_offline root
-abort_if_command_unknown() {
-    if ! which "$1" > /dev/null; then
-        abort "expected command unavailable: ${1}."
-    fi
-}
-abort_if_command_unknown wget 
-abort_if_command_unknown rsync
-abort_if_command_unknown parted 
+abort_if_offline
 abort_if_command_unknown mkfs.vfat 
+abort_if_command_unknown parted 
+abort_if_command_unknown rsync
+abort_if_command_unknown wget 
 
-expect_min_n_args 1 '(device name, e.g. "sdb")' $@
 PATH_STICK="$(get_mountable_device_path $1)"
 
 FILENAME_ISO="debian-${INSTALLER_VERSION}-amd64-netinst.iso"
index b0572bc2b9cb5c622eeb53aa42743cf39fda69d4..ffd093865383ce8810388b4dd8c23779d4ea4116 100755 (executable)
@@ -1,17 +1,19 @@
 #!/bin/sh
 set -e
 cd $(dirname "$0")
-. lib/abort_if_not_user
+. lib/abort_if_command_unknown
 . lib/constants_installer
-. lib/expect_min_n_args
+. lib/expect_n_args
 . lib/get_mountable_device_path
 
-abort_if_not_user root
-expect_min_n_args 1 '(e.g. "sdb1")' $@
-PATH_STICK="$(get_mountable_device_path $1)"
+expect_n_args 1 1 'DEVICE (e.g. "sdb")' $@
+abort_if_command_unknown pmount
 
-echo "Mounting ${PATH_STICK} …"
-mount "${PATH_STICK}" "${PATH_MNT_STICK}"
-trap "echo 'Unmounting'; umount ${PATH_MNT_STICK}" EXIT INT TERM
+DEVICE_NAME="$1"
+PATH_DEVICE="$(get_mountable_device_path ${DEVICE_NAME})"
+PATH_MOUNTED="/media/$1"
+echo "Mounting ${PATH_DEVICE} …"
+pmount "${DEVICE_NAME}"
+trap "echo 'Unmounting '${PATH_DEVICE}; pumount ${DEVICE_NAME}" EXIT INT TERM
 echo "Copying ${PATH_PRESEED_CFG} …"
-cp "${PATH_PRESEED_CFG}" "${PATH_MNT_STICK}/"
+cp "${PATH_PRESEED_CFG}" "${PATH_MOUNTED}/"
index 1f1eccd237107cb89d0b8c1717de92edf2052976..58969e06cc22459a0d374964923b3fcf6e0ad569 100755 (executable)
@@ -3,6 +3,7 @@ set -e
 cd $(dirname "$0")
 . lib/abort
 . lib/constants_borg  # PATH_BORG_CONF
+. lib/expect_n_args
 . lib/get_passphrase
 . lib/path_tmp_timestamped
 . lib/print_usage
@@ -22,19 +23,7 @@ error_exit() { abort "Aborting due to $1"; }
 error_exit_with_usage() { error_exit "${1}\n\n$(print_usage)"; }
 
 # commands
-USAGE_INDICES='backup_keys claim help keys orgpull info'
-
-_check_args_n() {
-    _N_MIN_ARGS="$1"
-    _N_MAX_ARGS="$2"
-    shift 2
-    if [ "$#" -lt "${_N_MIN_ARGS}" ]; then
-        error_exit_with_usage "missing arguments ($# instead of ${_N_MAX_ARGS})."
-    elif [ "$#" -gt "${_N_MAX_ARGS}" ]; then
-        shift "${_N_MAX_ARGS}"
-        error_exit_with_usage "unexpected arguments beyond expected number: $@"
-    fi
-}
+USAGE_INDICES='backup_keys claim help info keys orgpull'
 
 _run_borg_with_passphrase() {
     while true; do
@@ -61,7 +50,7 @@ _id_from_file() { head -1 "$1" | cut -d' ' -f2; }
 USAGE_ARGS_backup_keys='PATH'
 USAGE_DESC_backup_keys="copy known keys to PATH/, with their repos' server names as filenames"
 CMDFNC_backup_keys() {
-    _check_args_n 1 1 "$@"
+    expect_n_args 1 1 "${USAGE_ARGS_backup_keys}" "$@"
     _PATH_TARGET_DIR=$(realpath "$1")
     if [ -e "${_PATH_TARGET_DIR}" ] && [ ! -d "${_PATH_TARGET_DIR}" ]; then
         error_exit "non-directory at ${_PATH_TARGET_DIR}"
@@ -86,7 +75,7 @@ CMDFNC_backup_keys() {
 USAGE_ARGS_claim='PATH'
 USAGE_DESC_claim="register file of PATH as key to repo at \"$(location_from_servername SERVER_NAME)\", with SERVER_NAME the filename portion of PATH"
 CMDFNC_claim() {
-    _check_args_n 1 1 "$@"
+    expect_n_args 1 1 "${USAGE_ARGS_claim}" "$@"
     _PATH_SOURCE="$1"
     _ensure_no_overwrite_at() {
         if [ -f "$1" ]; then
@@ -116,14 +105,14 @@ CMDFNC_claim() {
 
 USAGE_DESC_help='print this help and exit'
 CMDFNC_help() {
-    _check_args_n 0 0 "$@"
+    expect_n_args 0 0 '' "$@"
     print_usage
 }
 
 USAGE_ARGS_info='SERVER_NAME [ARCHIVE]'
 USAGE_DESC_info="run 'borg info' against repo at \"$(location_from_servername SERVER_NAME)\", optionally only against ARCHIVE; if latter not provided, list most recent archives of repo"
 CMDFNC_info() {
-    _check_args_n 1 2 "$@"
+    expect_n_args 1 2 "${USAGE_ARGS_info}" $@
     _TARGET_REPO="$(location_from_servername ${1})"
     if [ ! -z "$2" ]; then
         borg info "${_TARGET_REPO}::$2"
@@ -136,35 +125,7 @@ CMDFNC_info() {
 
 USAGE_DESC_keys='list known repos in ID, key filename, and alleged location'
 CMDFNC_keys() {
-    _check_args_n 0 0 "$@"
-    _exit_ok() {
-       echo "(none, since directory ${1})"
-       exit 0
-    }
-
-    echo "Known keys, as per ${PATH_BORG_CONF_KEYS}:"
-    if [ ! -d "${PATH_BORG_CONF_KEYS}" ]; then
-       _exit_ok "non-existant"
-    fi
-    _KEYFILES="$(ls -1 ${PATH_BORG_CONF_KEYS})"
-    if [ -z "${_KEYFILES}" ]; then
-       _exit_ok "empty"
-    fi
-    echo "${_KEYFILES}" | while read _FILENAME; do
-        _KEY_ID=$(_id_from_file "${PATH_BORG_CONF_KEYS}/${_FILENAME}")
-       _PATH_LOC="$(path_repo_location ${_KEY_ID})"
-        printf "${_KEY_ID} ${_FILENAME} "
-        if [ -f "${_PATH_LOC}" ]; then
-            printf '%s\n' "$(cat ${_PATH_LOC})"
-        else
-            printf '?\n'
-        fi
-    done
-}
-
-USAGE_DESC_orgpull='pull most recent org directory available in repos'
-CMDFNC_orgpull() {
-    _check_args_n 0 0 "$@"
+    expect_n_args 0 0 '' "$@"
     _NAME_ARCHIVE=orgdir
 
     # determine server and repo
diff --git a/testing/scripts/init_server_access.sh b/testing/scripts/init_server_access.sh
new file mode 100755 (executable)
index 0000000..385b3b3
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+set -e
+cd $(dirname "$0")
+. lib/constants_ssh  # PATH_USER_SSH
+. lib/expect_min_n_args
+
+PATH_KNOWN_HOSTS="${PATH_USER_SSH}/known_hosts"
+
+expect_min_n_args 1 '(server)' "$@"
+SERVER="$1"
+
+echo '\nKnow host.\n'
+set +e
+ssh-keygen -f "${PATH_KNOWN_HOSTS}" -R "${SERVER}"
+set -e
+ssh-keyscan "${SERVER}" >> "${PATH_KNOWN_HOSTS}"
+
+echo '\nAsking for new root password.\n'
+stty -echo
+ssh "root@${SERVER}" 'printf "\n\n" && passwd'
+stty echo
+
+echo '\nSetting up config repo.'
+ssh "root@${SERVER}" 'apt update && apt install -y git && git clone https://plomlompom.com/repos/clone/config'
diff --git a/testing/scripts/lib/expect_n_args b/testing/scripts/lib/expect_n_args
new file mode 120000 (symlink)
index 0000000..5c37e82
--- /dev/null
@@ -0,0 +1 @@
+../../../bookworm/scripts/lib/expect_n_args
\ No newline at end of file