+++ /dev/null
-#!/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'
--- /dev/null
+. lib/abort
+
+abort_if_command_unknown() {
+ if ! which "$1" > /dev/null; then
+ abort "Expected command unavailable: ${1}."
+ fi
+}
FILENAME_PRESEED_CFG=preseed.cfg
PATH_PRESEED_CFG="../${FILENAME_PRESEED_CFG}"
-PATH_MNT_STICK=/mnt/stick
--- /dev/null
+. 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
+}
. 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}"
}
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"
#!/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}/"
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
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
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}"
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
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"
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
--- /dev/null
+#!/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'
--- /dev/null
+../../../bookworm/scripts/lib/expect_n_args
\ No newline at end of file