Initial commit

This commit is contained in:
Chris 2025-05-14 07:18:49 +01:00
commit 9f20e5d26f
8 changed files with 152 additions and 0 deletions

0
README.md Normal file
View File

33
deploy.sh Normal file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -e
echo "🚀 Starting kiosk deployment..."
REPO_DIR="/home/pi/kiosk"
SYSTEMD_DIR="/etc/systemd/system"
# Make sure we are in the repo directory
cd "$REPO_DIR" || { echo "❌ Repo directory not found at $REPO_DIR"; exit 1; }
# Make scripts executable
chmod +x start-kiosk.sh
chmod +x update-kiosk.sh
# Copy and install kiosk service
sudo cp kiosk.service "$SYSTEMD_DIR/"
sudo systemctl enable --now kiosk.service
# Copy and install update service and timer
sudo cp update-kiosk.service "$SYSTEMD_DIR/"
sudo cp update-kiosk.timer "$SYSTEMD_DIR/"
sudo systemctl daemon-reexec
sudo systemctl enable --now update-kiosk.timer
echo "✅ Kiosk service and update timer are set up and running!"
# Optional: show status
sudo systemctl status kiosk.service --no-pager
sudo systemctl status update-kiosk.timer --no-pager
echo "🎉 Deployment complete!"

12
kiosk.service Normal file
View File

@ -0,0 +1,12 @@
[Unit]
Description=Kiosk Mode Slideshow
After=graphical.target network.target
[Service]
ExecStart=/home/pi/kiosk/start-kiosk.sh
User=pi
Group=pi
Restart=on-failure
[Install]
WantedBy=graphical.target

56
site/index.html Normal file
View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Media Slideshow</title>
<style>
body { margin: 0; background: black; }
img, video { width: 100vw; height: 100vh; object-fit: contain; }
</style>
</head>
<body>
<img id="slideshow" style="display:none;" alt="Loading...">
<video id="videoPlayer" autoplay loop muted style="display:none;"></video>
<script>
const img = document.getElementById('slideshow');
const video = document.getElementById('videoPlayer');
const apiUrl = 'http://localhost:8111/wp-json/cwadvert/v1/get-ad'; // << update this
const interval = 30000;
async function updateMedia() {
try {
const response = await fetch(apiUrl);
const data = await response.json();
const url = data.image;
if (!url){
console.error("media url is blank");
return;
}
console.trace("Setting media url");
if (url.endsWith('.mp4') || url.endsWith('.webm')) {
img.style.display = 'none';
video.style.display = 'block';
if (video.src !== url) {
video.src = url;
video.load();
video.play();
}
} else {
video.style.display = 'none';
img.style.display = 'block';
img.src = url;
}
} catch (e) {
console.error('Error fetching media:', e);
}
}
updateMedia();
setInterval(updateMedia, interval);
</script>
</body>
</html>

7
start-kiosk.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
# Wait a bit for network + desktop environment to load
sleep 10
# Launch Chromium in kiosk mode
/usr/bin/chromium-browser --kiosk "file:///home/pi/kiosk/site/index.html"

10
update-kiosk.service Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Update kiosk repo and restart if changed
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/home/pi/kiosk/update-kiosk.sh
User=pi
Group=pi

24
update-kiosk.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -e
cd /home/pi/kiosk || exit 1
# Fetch latest updates and tags
git fetch --tags origin
git fetch origin
# Get latest tag, if any
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "")
if [ -n "$LATEST_TAG" ]; then
echo "Checking out latest tag: $LATEST_TAG"
git checkout "$LATEST_TAG"
else
echo "No tags found — using main branch"
git checkout main
git pull origin main
fi
# Restart the kiosk service to apply updates
sudo systemctl restart kiosk.service

10
update-kiosk.timer Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=Run kiosk updater every 10 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=10min
Unit=update-kiosk.service
[Install]
WantedBy=timers.target