diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e075319..49cd59b 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -113,23 +113,15 @@ jobs: echo "PORT=8080" > $BUILD_DIR/usr/share/$PKG_NAME/.env.template fi - # 5. Create the systemd Service File - cat < $BUILD_DIR/etc/systemd/system/$PKG_NAME.service - [Unit] - Description=Slideshow Application Service - After=graphical.target - - [Service] - Type=simple - Environment=DISPLAY=:0 - Environment=XAUTHORITY=/home/youruser/.Xauthority - ExecStart=/usr/bin/$PKG_NAME + # 5. Create a Template Autostart File (Instead of Systemd) + mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/setup + cat < $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop + [Desktop Entry] + Type=Application + Name=Slideshow App + Exec=/usr/bin/$PKG_NAME WorkingDirectory=/usr/share/$PKG_NAME - Restart=always - User=root - - [Install] - WantedBy=multi-user.target + Terminal=false EOF # 6. Create Control File @@ -139,28 +131,44 @@ jobs: Section: utils Priority: optional Architecture: $ARCH - Maintainer: Your Name + Maintainer: Adrian Zuercher Description: Slideshow Application EOF - # 7. Optional: Add post-install script to enable service automatically - echo "create service" + # 7. Add post-install script for Autostart and Permissions cat < $BUILD_DIR/DEBIAN/postinst #!/bin/sh - # Check if .env exists in the target share folder - if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then - echo "Creating new .env from template..." - cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env - else - echo ".env already exists, skipping template copy to preserve settings." + # 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") fi - echo "reload" - systemctl daemon-reload - echo "enable service" - systemctl enable $PKG_NAME.service - echo "start service" - systemctl start $PKG_NAME.service + USER_HOME=\$(getent passwd "\$REAL_USER" | cut -d: -f6) + + echo "Installing for user: \$REAL_USER in \$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 + 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/" + + # 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" + fi + + # 5. Set correct ownership for the autostart file + chown -R \$REAL_USER:\$REAL_USER "\$AUTOSTART_DIR/$PKG_NAME.desktop" + + echo "Installation complete. The app will start on the next Desktop login." EOF chmod 555 $BUILD_DIR/DEBIAN/postinst