From a9cf2bafebb76a22ada1ab5b8283202997c2b1ed Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 4 Apr 2025 23:54:08 +0200 Subject: [PATCH] Fix. --- bookworm/aptmark/server | 2 ++ bookworm/scripts/lib/expect_n_args | 21 +++++++++++++++++++++ bookworm/scripts/lib/setup_users | 18 +++++++++--------- bookworm/scripts/setup_server.sh | 10 ++++++++-- testing/home/desktop/.local/bin/borgplom | 2 +- testing/scripts/lib/expect_n_args | 22 +--------------------- 6 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 bookworm/scripts/lib/expect_n_args mode change 100644 => 120000 testing/scripts/lib/expect_n_args diff --git a/bookworm/aptmark/server b/bookworm/aptmark/server index 70e8d2b..a072e94 100644 --- a/bookworm/aptmark/server +++ b/bookworm/aptmark/server @@ -2,3 +2,5 @@ openssh-server # firewalling nftables +# for playing nicely with ssh sessions via the foot terminal +foot-terminfo diff --git a/bookworm/scripts/lib/expect_n_args b/bookworm/scripts/lib/expect_n_args new file mode 100644 index 0000000..950671a --- /dev/null +++ b/bookworm/scripts/lib/expect_n_args @@ -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 +} diff --git a/bookworm/scripts/lib/setup_users b/bookworm/scripts/lib/setup_users index cc09567..0d8f21b 100644 --- a/bookworm/scripts/lib/setup_users +++ b/bookworm/scripts/lib/setup_users @@ -1,21 +1,21 @@ . lib/copy_dirtree -. lib/constants_user +. lib/constants_user # PATH_USER_HOME, USERNAME setup_users() { - MIN_TAGS="$1" - TAGS_USER="$2" - PATH_CONF_HOME=../home - PATH_USER_BIN="${PATH_USER_HOME}/.local/bin" + _MIN_TAGS="$1" + _TAGS_USER="$2" + _PATH_CONF_HOME=../home + _PATH_USER_BIN="${PATH_USER_HOME}/.local/bin" echo "\nSetting up root user's home directory." - copy_dirtree "${PATH_CONF_HOME}" '/root' ${MIN_TAGS} root + copy_dirtree "${_PATH_CONF_HOME}" '/root' ${_MIN_TAGS} root echo "\nSetting up user ${USERNAME}." adduser --disabled-password --gecos "" "${USERNAME}" usermod -a -G sudo "${USERNAME}" - copy_dirtree "${PATH_CONF_HOME}" "${PATH_USER_HOME}" ${MIN_TAGS} ${TAGS_USER} - mkdir -p "${PATH_USER_BIN}" - cd "${PATH_USER_BIN}" + copy_dirtree "${_PATH_CONF_HOME}" "${PATH_USER_HOME}" ${_MIN_TAGS} ${_TAGS_USER} + mkdir -p "${_PATH_USER_BIN}" + cd "${_PATH_USER_BIN}" ln -s ../../.plomlib.sh lib cd - > /dev/null chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_HOME}" diff --git a/bookworm/scripts/setup_server.sh b/bookworm/scripts/setup_server.sh index 305fb36..1c79edd 100755 --- a/bookworm/scripts/setup_server.sh +++ b/bookworm/scripts/setup_server.sh @@ -6,13 +6,13 @@ cd $(dirname "$0") . lib/constants_user # USERNAME . lib/copy_dirtree . lib/determine_ip -. lib/expect_min_n_args +. lib/expect_n_args . lib/init_packages . lib/setup_users MIN_TAGS='all server' -expect_min_n_args 2 '(hostname, FQDN)' "$@" +expect_n_args 2 2 'HOSTNAME, FQDN' $@ HOSTNAME="$1" FQDN="$2" @@ -20,6 +20,7 @@ PATH_REL_ETC=etc PATH_CONF_ETC="${PATH_CONF}/${PATH_REL_ETC}" PATH_ETC="/${PATH_REL_ETC}" PATH_HOSTS="${PATH_ETC}/hosts" +PATH_BORG_HOME=/home/borg init_packages "${MIN_TAGS}" @@ -43,5 +44,10 @@ mkdir -p "${PATH_USER_SSH}" mv "/root/${PATH_REL_SSH}/authorized_keys" "${PATH_USER_SSH}/" chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_SSH}" +echo '\nSetting up minimal borg user.' +adduser --system --home "${PATH_BORG_HOME}" --shell /bin/sh borg +cp -a "${PATH_USER_SSH}" "${PATH_BORG_HOME}/" +chown -R borg:nogroup "${PATH_BORG_HOME}/${PATH_REL_SSH}" + echo '\nEnabling the firewall.' systemctl enable nftables.service diff --git a/testing/home/desktop/.local/bin/borgplom b/testing/home/desktop/.local/bin/borgplom index f20e1e5..e660377 100755 --- a/testing/home/desktop/.local/bin/borgplom +++ b/testing/home/desktop/.local/bin/borgplom @@ -14,7 +14,7 @@ USAGE_LINES='COMMAND [ARGUMENT]...' PATH_BORG_CONF_SECURITY="${PATH_BORG_CONF}/security" PATH_BORG_CONF_KEYS="${PATH_BORG_CONF}/keys" -location_from_servername() { printf 'ssh://plom@%s/./borg' "$1"; } +location_from_servername() { printf 'ssh://borg@%s/./borgrepo' "$1"; } servername_from_location() { echo "$1" | cut -d'/' -f3 | cut -d'@' -f2; } path_repo_location() { printf '%s' "${PATH_BORG_CONF_SECURITY}/${1}/location"; } diff --git a/testing/scripts/lib/expect_n_args b/testing/scripts/lib/expect_n_args deleted file mode 100644 index 950671a..0000000 --- a/testing/scripts/lib/expect_n_args +++ /dev/null @@ -1,21 +0,0 @@ -. 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 -} diff --git a/testing/scripts/lib/expect_n_args b/testing/scripts/lib/expect_n_args new file mode 120000 index 0000000..5c37e82 --- /dev/null +++ b/testing/scripts/lib/expect_n_args @@ -0,0 +1 @@ +../../../bookworm/scripts/lib/expect_n_args \ No newline at end of file -- 2.30.2