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.
This commit is contained in:
RobbStarkAustria
2026-04-05 08:59:19 +02:00
parent 0cd0d95612
commit fa7efae346

View File

@@ -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