From fa7efae3461bb6d13f5d6b1d03f97da1f2629121 Mon Sep 17 00:00:00 2001 From: RobbStarkAustria Date: Sun, 5 Apr 2026 08:59:19 +0200 Subject: [PATCH] fix: pi-setup.sh substitutes actual username when installing systemd units Service files had User=olafn and /home/olafn/ hardcoded. pi-setup.sh now uses ACTUAL_USER=${SUDO_USER:-$USER} and sed-substitutes at install time so units work on any Pi regardless of the OS user. --- src/pi-setup.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pi-setup.sh b/src/pi-setup.sh index cefd90f..ebdda8c 100644 --- a/src/pi-setup.sh +++ b/src/pi-setup.sh @@ -18,7 +18,11 @@ log_warn() { echo -e "${YELLOW}⚠️ $1${NC}"; } log_err() { echo -e "${RED}❌ $1${NC}"; } # Configuration -PROJECT_DIR="$HOME/infoscreen-dev" +# Resolve the actual unprivileged user even when the script is invoked via sudo. +ACTUAL_USER="${SUDO_USER:-$USER}" +ACTUAL_HOME="$(eval echo "~$ACTUAL_USER")" + +PROJECT_DIR="$ACTUAL_HOME/infoscreen-dev" REPO_URL="https://github.com/RobbStarkAustria/infoscreen-client-dev-2025.git" # Public HTTPS clone VENV_DIR="$PROJECT_DIR/venv" REQ_FILE="$PROJECT_DIR/src/requirements.txt" @@ -148,8 +152,11 @@ SYSTEMD_DIR="/etc/systemd/system" for unit in infoscreen-simclient.service infoscreen-display.service "infoscreen-notify-failure@.service"; do if [ -f "$SERVICES_SRC/$unit" ]; then - sudo cp "$SERVICES_SRC/$unit" "$SYSTEMD_DIR/$unit" - log_ok "Installed $SYSTEMD_DIR/$unit" + # Substitute the dev-machine username/home with the actual target user. + sed -e "s|olafn|$ACTUAL_USER|g" \ + -e "s|/home/$ACTUAL_USER|$ACTUAL_HOME|g" \ + "$SERVICES_SRC/$unit" | sudo tee "$SYSTEMD_DIR/$unit" > /dev/null + log_ok "Installed $SYSTEMD_DIR/$unit (user=$ACTUAL_USER)" else log_warn "Service unit not found: $SERVICES_SRC/$unit" fi