8 Commits

Author SHA1 Message Date
Adrian Zürcher
f8dce0b817 fix chmod error
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 2m5s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m16s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m9s
Build Slideshow App / build (arm64, , linux) (push) Successful in 2m5s
2026-01-21 07:57:03 +01:00
Adrian Zürcher
0eb781a6d3 fix desktop output and add new data path
Some checks failed
Build Slideshow App / build (amd64, , linux) (push) Failing after 2m3s
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 2m4s
Build Slideshow App / build (arm, 7, , linux) (push) Failing after 1m48s
Build Slideshow App / build (arm64, , linux) (push) Failing after 1m54s
2026-01-21 07:28:39 +01:00
Adrian Zürcher
9150550609 new folder strucure and file path 2026-01-21 07:28:10 +01:00
Adrian Zürcher
84abf6b820 add new helper function 2026-01-21 07:27:50 +01:00
Adrian Zürcher
4904589086 change autostart script
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 3m29s
Build Slideshow App / build (amd64, , linux) (push) Successful in 3m46s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m0s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m59s
2026-01-20 17:17:03 +01:00
Adrian Zürcher
6f7e149c9a second try autostart
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m55s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m12s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m1s
Build Slideshow App / build (arm64, , linux) (push) Successful in 2m4s
2026-01-19 07:34:15 +01:00
Adrian Zürcher
df344b4c13 change from systemd to autostart
All checks were successful
Build Slideshow App / build (amd64, , linux) (push) Successful in 1m30s
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m19s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 1m23s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m24s
2026-01-19 07:19:51 +01:00
Adrian Zürcher
d82f213ca7 fix wrong log file name in linux, comments of enviroment vars
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 2m7s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m18s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m3s
Build Slideshow App / build (arm64, , linux) (push) Successful in 2m4s
2026-01-18 21:46:17 +01:00
8 changed files with 114 additions and 47 deletions

6
.env
View File

@@ -1,6 +1,8 @@
ENV= #empty|development|debug
#empty|development|debug
ENV=
PHOTO_DIR=images
HOST=0.0.0.0
PORT=8080
INTERVAL_DEFAULT=10
LOG_PATH= #path for logger files default .
#path for logger files default {executable name}.log
LOG_PATH=

View File

@@ -98,6 +98,7 @@ jobs:
# 2. Create Directory Structure
mkdir -p $BUILD_DIR/usr/bin
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/data
mkdir -p $BUILD_DIR/etc/systemd/system
mkdir -p $BUILD_DIR/DEBIAN
@@ -113,23 +114,23 @@ jobs:
echo "PORT=8080" > $BUILD_DIR/usr/share/$PKG_NAME/.env.template
fi
# 5. Create the systemd Service File
cat <<EOF > $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
WorkingDirectory=/usr/share/$PKG_NAME
Restart=always
User=root
[Install]
WantedBy=multi-user.target
# 5. Create a Template Autostart File (Instead of Systemd)
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/setup
cat <<'EOF' > $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop
[Desktop Entry]
Type=Application
Name=Slideshow App
Exec=sh -c ' \
i=0; \
while [ $i -lt 30 ]; do \
if [ "$(ls -A /media/$USER 2>/dev/null)" ] && ping -c 1 -W 1 8.8.8.8 >/dev/null 2>&1; then \
break; \
fi; \
i=$((i+1)); \
sleep 1; \
done; \
cd /usr/share/slideshowapp && /usr/bin/slideshowapp'
Terminal=false
EOF
# 6. Create Control File
@@ -139,28 +140,64 @@ jobs:
Section: utils
Priority: optional
Architecture: $ARCH
Maintainer: Your Name <you@example.com>
Maintainer: Adrian Zuercher <zuercher@tecamino.ch>
Description: Slideshow Application
EOF
# 7. Optional: Add post-install script to enable service automatically
echo "create service"
cat <<EOF > $BUILD_DIR/DEBIAN/postinst
# 7. Add post-install script for Autostart and Permissions
cat <<'EOF' > $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."
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
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 "Setting permissions for /usr/share/slideshowapp..."
chown -R "$REAL_USER:$REAL_USER" /usr/share/slideshowapp
chmod -R 755 /usr/share/slideshowapp
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/slideshowapp/.env" ]; then
echo "Creating .env from template..."
cp /usr/share/slideshowapp/env.template /usr/share/slideshowapp/.env || true
fi
# 3. Setup Autostart
# We use -p to ensure parent directories exist and set ownership immediately
AUTOSTART_DIR="$USER_HOME/.config/autostart"
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
# 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."
EOF
chmod 555 $BUILD_DIR/DEBIAN/postinst

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
images/
slideshowApp
schedule.json
schedule.json
*.log

2
go.mod
View File

@@ -3,7 +3,7 @@ module slideshowApp
go 1.25.4
require (
gitea.tecamino.com/paadi/tecamino-logger v1.0.0
gitea.tecamino.com/paadi/tecamino-logger v1.0.1
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/joho/godotenv v1.5.1

4
go.sum
View File

@@ -1,5 +1,5 @@
gitea.tecamino.com/paadi/tecamino-logger v1.0.0 h1:Quk0UJerOCy7xbHWYOuBXk0FQIgx4arjVDMt2ahvaO0=
gitea.tecamino.com/paadi/tecamino-logger v1.0.0/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
gitea.tecamino.com/paadi/tecamino-logger v1.0.1 h1:NCF/foyuf0wVKLkyy2y1FYvHo9pVaUuHc1GSU5bNVbc=
gitea.tecamino.com/paadi/tecamino-logger v1.0.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=

View File

@@ -4,20 +4,36 @@ import (
"encoding/json"
"net/http"
"os"
"slideshowApp/utils"
)
type Schedule map[string]interface{}
var scheduleFile = "./data/schedule.json"
type Schedule map[string]any
func SaveSchedule(w http.ResponseWriter, r *http.Request) {
var s Schedule
json.NewDecoder(r.Body).Decode(&s)
data, _ := json.Marshal(s)
os.WriteFile("schedule.json", data, 0644)
if err := json.NewDecoder(r.Body).Decode(&s); err != nil {
utils.SendJSONError(w, "Invalid input", http.StatusBadRequest)
return
}
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
utils.SendJSONError(w, "Encoding failed", http.StatusInternalServerError)
return
}
err = os.WriteFile(scheduleFile, data, 0644)
if err != nil {
utils.SendJSONError(w, "write file failed", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
func GetSchedule(w http.ResponseWriter, r *http.Request) {
data, err := os.ReadFile("schedule.json")
data, err := os.ReadFile(scheduleFile)
if err != nil {
json.NewEncoder(w).Encode(Schedule{})
return

View File

@@ -18,6 +18,8 @@ var staticFolder = "./web/static/"
func main() {
env.Load(".env")
logConfig := logging.DefaultConfig()
logConfig.Debug = env.Env.GetValue() == "debug"
@@ -26,9 +28,6 @@ func main() {
log.Fatal(err)
}
logger.Debug("main", "load enviroment variable")
env.Load(".env")
r := mux.NewRouter()
uploadFolder := env.PhotoDir.GetValue()

12
utils/http.go Normal file
View File

@@ -0,0 +1,12 @@
package utils
import (
"encoding/json"
"net/http"
)
func SendJSONError(w http.ResponseWriter, message string, code int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(map[string]string{"error": message})
}