From 357abc20973db723dcf25ea0ef1ee05199fac3ae Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 5 Aug 2026 11:57:16 +1000 Subject: [PATCH] fix(install.sh): three argument/linger handling defects --force was advertised in --help, accepted, and inert (FORCE_BUILD was set and never read -- go build already rebuilds unconditionally). Removed the flag and its help line rather than fake an up-to-date check that go build's own cache already makes unnecessary. Unknown flags fell through the case statement with no default branch and silently kept every default, so a typo like --no-systmd installed the systemd service the user asked to skip. Unknown options now print a diagnostic naming the bad flag and exit 1, per the (a) option agreed 2026-07-30: this is a hand-run interactive installer where typos dominate and silent wrong behaviour is the worst outcome. Linger detection grepped for "Linger=no" and treated any other output -- including a failed or empty `loginctl show-user` from a missing logind session, a container, or unset $USER aborting under `set -u` -- as "already enabled" without observing anything. Detection now requires a positive "Linger=yes" and falls through to enable-linger (idempotent) in every other case, and uses $(id -un) instead of $USER. Refs archie-core-bfw, archie-core-c6o, archie-core-utt Verified manually: bash -n syntax check; a real invocation of an unknown flag (exits 1, no side effects, before any build/network step); the linger branch logic exercised in isolation against stubbed loginctl output for Linger=yes, Linger=no, empty output, and a failing command. No shell test harness (bats or similar) exists in this repo yet, so this is direct verification rather than a committed test. --- install.sh | 60 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index 061690f04..3da0c0aad 100755 --- a/install.sh +++ b/install.sh @@ -39,11 +39,26 @@ ENV_FILE="${ARCHIE_CONFIG_DIR}/env" INSTALL_SYSTEMD=true ENABLE_LINGER=true AUTO_START=true -FORCE_BUILD=false INTERACTIVE=true [ ! -t 0 ] && INTERACTIVE=false +usage() { + echo "Usage: ./install.sh [options]" + echo "" + echo "Options:" + echo " --no-systemd Skip systemd user unit installation" + echo " --no-linger Skip loginctl enable-linger execution" + echo " --no-start Install service but do not auto-start archied" + echo " --non-interactive Run without interactive setup prompts" + echo " --help, -h Show this help message" + echo "" + echo "XDG Target Directories:" + echo " Config: ${ARCHIE_CONFIG_DIR}" + echo " Data: ${ARCHIE_DATA_DIR}" + echo " Bin: ${ARCHIE_BIN_DIR}" +} + for arg in "$@"; do case "$arg" in --no-systemd) @@ -63,27 +78,16 @@ for arg in "$@"; do INTERACTIVE=false shift ;; - --force) - FORCE_BUILD=true - shift - ;; --help|-h) - echo "Usage: ./install.sh [options]" - echo "" - echo "Options:" - echo " --no-systemd Skip systemd user unit installation" - echo " --no-linger Skip loginctl enable-linger execution" - echo " --no-start Install service but do not auto-start archied" - echo " --non-interactive Run without interactive setup prompts" - echo " --force Force rebuild binaries even if up to date" - echo " --help, -h Show this help message" - echo "" - echo "XDG Target Directories:" - echo " Config: ${ARCHIE_CONFIG_DIR}" - echo " Data: ${ARCHIE_DATA_DIR}" - echo " Bin: ${ARCHIE_BIN_DIR}" + usage exit 0 ;; + *) + echo "Error: unknown option '${arg}'" >&2 + echo "" >&2 + usage >&2 + exit 1 + ;; esac done @@ -444,13 +448,21 @@ EOF SERVICE_INSTALLED=true echo " Installed ${SERVICE_FILE}" - # Enable linger so systemd --user runs continuously without an active login session + # Enable linger so systemd --user runs continuously without an active login + # session. $(id -un) is used rather than $USER, which is unset in some + # container and cron contexts and would abort under `set -u`. Only a + # positive "Linger=yes" counts as already enabled -- a failed or empty + # `loginctl show-user` (no logind session, a container) falls through to + # enable-linger rather than being reported as already OK, since nothing + # was actually observed. enable-linger is idempotent, so a redundant call + # here is harmless. if [ "${ENABLE_LINGER}" = true ] && command -v loginctl &>/dev/null; then - if loginctl show-user "${USER}" 2>/dev/null | grep -q "Linger=no"; then - echo "==> Enabling systemd user linger (loginctl enable-linger ${USER})..." - loginctl enable-linger "${USER}" || echo " Notice: Could not enable linger automatically. Run 'loginctl enable-linger ${USER}' manually if needed." - else + LINGER_USER="$(id -un)" + if loginctl show-user "${LINGER_USER}" 2>/dev/null | grep -q "Linger=yes"; then echo " [OK] User linger is already enabled." + else + echo "==> Enabling systemd user linger (loginctl enable-linger ${LINGER_USER})..." + loginctl enable-linger "${LINGER_USER}" || echo " Notice: Could not enable linger automatically. Run 'loginctl enable-linger ${LINGER_USER}' manually if needed." fi fi