From 6f7e149c9a6ed3acab7b6ac414e07c30da9cac65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Z=C3=BCrcher?= Date: Mon, 19 Jan 2026 07:34:15 +0100 Subject: [PATCH] second try autostart --- .gitea/workflows/build.yml | 58 ++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 49cd59b..3af29a1 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -136,39 +136,55 @@ jobs: EOF # 7. Add post-install script for Autostart and Permissions - cat < $BUILD_DIR/DEBIAN/postinst + cat <<'EOF' > $BUILD_DIR/DEBIAN/postinst #!/bin/sh - # 1. Detect the real user (the one who ran sudo) - REAL_USER=\$SUDO_USER - if [ -z "\$REAL_USER" ]; then - REAL_USER=\$(logname 2>/dev/null || echo "pi") + set -e # Exit on error + + # 1. Detect the real user + # We use 'who' and 'awk' as a fallback because $SUDO_USER is sometimes empty in Gitea/CI environments + REAL_USER=${SUDO_USER:-$(who | awk '{print $1}' | head -n1)} + + # If still empty, default to 'mst' or 'pi' (adjust to your primary user) + if [ -z "$REAL_USER" ] || [ "$REAL_USER" = "root" ]; then + REAL_USER="mst" fi - USER_HOME=\$(getent passwd "\$REAL_USER" | cut -d: -f6) + USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6) - echo "Installing for user: \$REAL_USER in \$USER_HOME" + echo "Post-install: Target user is $REAL_USER" + echo "Post-install: Target home is $USER_HOME" # 2. Setup .env from template - if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then - cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env + if [ ! -f "/usr/share/slideshowapp/.env" ]; then + echo "Creating .env from template..." + cp /usr/share/slideshowapp/env.template /usr/share/slideshowapp/.env || true fi - # 3. Setup Autostart for the graphical desktop - AUTOSTART_DIR="\$USER_HOME/.config/autostart" - mkdir -p "\$AUTOSTART_DIR" - cp /usr/share/$PKG_NAME/setup/$PKG_NAME.desktop "\$AUTOSTART_DIR/" + # 3. Setup Autostart (THE FIX) + # We use -p to ensure parent directories exist and set ownership immediately + AUTOSTART_DIR="$USER_HOME/.config/autostart" - # 4. Fix Chromium Profile Permissions (Resolves the 'Profile Error') - # This ensures the standard user can write to their own config - if [ -d "\$USER_HOME/.config/chromium" ]; then - chown -R \$REAL_USER:\$REAL_USER "\$USER_HOME/.config/chromium" - rm -f "\$USER_HOME/.config/chromium/SingletonLock" + if [ -d "$USER_HOME" ]; then + echo "Creating autostart directory at $AUTOSTART_DIR" + mkdir -p "$AUTOSTART_DIR" + cp /usr/share/slideshowapp/setup/slideshowapp.desktop "$AUTOSTART_DIR/" + + # Critical: Change ownership of the folder and the file + chown -R "$REAL_USER:$REAL_USER" "$USER_HOME/.config" + chmod 644 "$AUTOSTART_DIR/slideshowapp.desktop" + else + echo "ERROR: Home directory $USER_HOME not found. Autostart not configured." fi - # 5. Set correct ownership for the autostart file - chown -R \$REAL_USER:\$REAL_USER "\$AUTOSTART_DIR/$PKG_NAME.desktop" + # 4. Fix Chromium Profile Permissions + if [ -d "$USER_HOME/.config/chromium" ]; then + echo "Cleaning up Chromium locks for $REAL_USER..." + chown -R "$REAL_USER:$REAL_USER" "$USER_HOME/.config/chromium" + rm -f "$USER_HOME/.config/chromium/SingletonLock" + rm -f "$USER_HOME/.config/chromium/SingletonCookie" + fi - echo "Installation complete. The app will start on the next Desktop login." + echo "Installation complete." EOF chmod 555 $BUILD_DIR/DEBIAN/postinst