Compare commits
5 Commits
v0.0.16
...
0eb781a6d3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eb781a6d3 | ||
|
|
9150550609 | ||
|
|
84abf6b820 | ||
|
|
4904589086 | ||
|
|
6f7e149c9a |
@@ -98,9 +98,12 @@ jobs:
|
|||||||
# 2. Create Directory Structure
|
# 2. Create Directory Structure
|
||||||
mkdir -p $BUILD_DIR/usr/bin
|
mkdir -p $BUILD_DIR/usr/bin
|
||||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
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/etc/systemd/system
|
||||||
mkdir -p $BUILD_DIR/DEBIAN
|
mkdir -p $BUILD_DIR/DEBIAN
|
||||||
|
|
||||||
|
chown -R "$REAL_USER:$REAL_USER" /usr/share/slideshowapp/data
|
||||||
|
|
||||||
# 3. Copy Files
|
# 3. Copy Files
|
||||||
cp ${APP_NAME} $BUILD_DIR/usr/bin/$PKG_NAME
|
cp ${APP_NAME} $BUILD_DIR/usr/bin/$PKG_NAME
|
||||||
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
||||||
@@ -115,12 +118,20 @@ jobs:
|
|||||||
|
|
||||||
# 5. Create a Template Autostart File (Instead of Systemd)
|
# 5. Create a Template Autostart File (Instead of Systemd)
|
||||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/setup
|
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/setup
|
||||||
cat <<EOF > $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop
|
cat <<'EOF' > $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Type=Application
|
Type=Application
|
||||||
Name=Slideshow App
|
Name=Slideshow App
|
||||||
Exec=/usr/bin/$PKG_NAME
|
Exec=sh -c ' \
|
||||||
WorkingDirectory=/usr/share/$PKG_NAME
|
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
|
Terminal=false
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -136,39 +147,55 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 7. Add post-install script for Autostart and Permissions
|
# 7. Add post-install script for Autostart and Permissions
|
||||||
cat <<EOF > $BUILD_DIR/DEBIAN/postinst
|
cat <<'EOF' > $BUILD_DIR/DEBIAN/postinst
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# 1. Detect the real user (the one who ran sudo)
|
set -e # Exit on error
|
||||||
REAL_USER=\$SUDO_USER
|
|
||||||
if [ -z "\$REAL_USER" ]; then
|
# 1. Detect the real user
|
||||||
REAL_USER=\$(logname 2>/dev/null || echo "pi")
|
# 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
|
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
|
# 2. Setup .env from template
|
||||||
if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then
|
if [ ! -f "/usr/share/slideshowapp/.env" ]; then
|
||||||
cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env
|
echo "Creating .env from template..."
|
||||||
|
cp /usr/share/slideshowapp/env.template /usr/share/slideshowapp/.env || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Setup Autostart for the graphical desktop
|
# 3. Setup Autostart (THE FIX)
|
||||||
AUTOSTART_DIR="\$USER_HOME/.config/autostart"
|
# We use -p to ensure parent directories exist and set ownership immediately
|
||||||
mkdir -p "\$AUTOSTART_DIR"
|
AUTOSTART_DIR="$USER_HOME/.config/autostart"
|
||||||
cp /usr/share/$PKG_NAME/setup/$PKG_NAME.desktop "\$AUTOSTART_DIR/"
|
|
||||||
|
|
||||||
# 4. Fix Chromium Profile Permissions (Resolves the 'Profile Error')
|
if [ -d "$USER_HOME" ]; then
|
||||||
# This ensures the standard user can write to their own config
|
echo "Creating autostart directory at $AUTOSTART_DIR"
|
||||||
if [ -d "\$USER_HOME/.config/chromium" ]; then
|
mkdir -p "$AUTOSTART_DIR"
|
||||||
chown -R \$REAL_USER:\$REAL_USER "\$USER_HOME/.config/chromium"
|
cp /usr/share/slideshowapp/setup/slideshowapp.desktop "$AUTOSTART_DIR/"
|
||||||
rm -f "\$USER_HOME/.config/chromium/SingletonLock"
|
|
||||||
|
# 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
|
fi
|
||||||
|
|
||||||
# 5. Set correct ownership for the autostart file
|
# 4. Fix Chromium Profile Permissions
|
||||||
chown -R \$REAL_USER:\$REAL_USER "\$AUTOSTART_DIR/$PKG_NAME.desktop"
|
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
|
EOF
|
||||||
chmod 555 $BUILD_DIR/DEBIAN/postinst
|
chmod 555 $BUILD_DIR/DEBIAN/postinst
|
||||||
|
|
||||||
|
|||||||
@@ -4,20 +4,36 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"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) {
|
func SaveSchedule(w http.ResponseWriter, r *http.Request) {
|
||||||
var s Schedule
|
var s Schedule
|
||||||
json.NewDecoder(r.Body).Decode(&s)
|
if err := json.NewDecoder(r.Body).Decode(&s); err != nil {
|
||||||
data, _ := json.Marshal(s)
|
utils.SendJSONError(w, "Invalid input", http.StatusBadRequest)
|
||||||
os.WriteFile("schedule.json", data, 0644)
|
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)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSchedule(w http.ResponseWriter, r *http.Request) {
|
func GetSchedule(w http.ResponseWriter, r *http.Request) {
|
||||||
data, err := os.ReadFile("schedule.json")
|
data, err := os.ReadFile(scheduleFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
json.NewEncoder(w).Encode(Schedule{})
|
json.NewEncoder(w).Encode(Schedule{})
|
||||||
return
|
return
|
||||||
|
|||||||
12
utils/http.go
Normal file
12
utils/http.go
Normal 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})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user