Files
senior-kiosk/deploy.sh
T

113 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
# Deploy latest kiosk code.
# Always commits to Gitea and restarts kiosk-dev (dev/test machine).
# If the production kiosk is reachable, deploys there too.
# Usage: ./deploy.sh ["commit message"]
KIOSK_LOCAL="jgitta@192.168.88.44"
KIOSK_REMOTE="jgitta@100.64.0.1"
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
HOME_SRC="$REPO_DIR/home-screen-index.html"
HOME_DST="/home/jgitta/kiosk-home/index.html"
WEATHER_SRC="$REPO_DIR/weather.html"
WEATHER_DST="/home/jgitta/kiosk-home/weather.html"
NEWS_SRC="$REPO_DIR/news.html"
NEWS_DST="/home/jgitta/kiosk-home/news.html"
CONFIG_SRC="$REPO_DIR/config.json"
# Auto-increment patch version (0.2.0 → 0.2.1 → 0.2.2 ...)
VERSION_FILE="$REPO_DIR/VERSION"
if [ -f "$VERSION_FILE" ]; then
CUR=$(cat "$VERSION_FILE" | tr -d '[:space:]')
MAJOR=$(echo "$CUR" | cut -d. -f1)
MINOR=$(echo "$CUR" | cut -d. -f2)
PATCH=$(echo "$CUR" | cut -d. -f3)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
echo "$NEW_VERSION" > "$VERSION_FILE"
echo "==> Version: $CUR$NEW_VERSION"
else
NEW_VERSION="unknown"
fi
COMMIT_MSG="${1:-deploy: v$NEW_VERSION $(date +%Y-%m-%d)}"
# Gitea credentials (from credentials.md)
GITEA_TOKEN="4fe93c6c62490ef0bb4e4aeec58f47da26752ce8"
GITEA_USER="jgitta"
inject_config() {
local src="$1"
local dst="$2"
local config="$3"
if [ -f "$config" ]; then
local config_json=$(cat "$config" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | tr '\n' ' ')
sed "s|const config = {};|const config = $config_json;|" "$src" > "$dst"
echo " Injected config.json into home screen"
else
cp "$src" "$dst"
echo " WARNING: config.json missing — deploying without config injection"
fi
}
echo "==> Syncing home screen to $HOME_DST..."
if [ -f "$HOME_SRC" ]; then
mkdir -p "$(dirname "$HOME_DST")"
inject_config "$HOME_SRC" "$HOME_DST" "$CONFIG_SRC"
chown jgitta:jgitta "$HOME_DST" 2>/dev/null || true
else
echo " WARNING: $HOME_SRC missing — home screen not updated"
fi
if [ -f "$WEATHER_SRC" ]; then
cp "$WEATHER_SRC" "$WEATHER_DST"
chown jgitta:jgitta "$WEATHER_DST" 2>/dev/null || true
echo " Synced weather page"
fi
if [ -f "$NEWS_SRC" ]; then
cp "$NEWS_SRC" "$NEWS_DST"
chown jgitta:jgitta "$NEWS_DST" 2>/dev/null || true
echo " Synced news page"
fi
echo "==> Committing and pushing to Gitea..."
git -C "$REPO_DIR" add -A
git -C "$REPO_DIR" commit -m "$COMMIT_MSG" 2>/dev/null || echo " (nothing new to commit)"
git -C "$REPO_DIR" remote set-url origin "http://$GITEA_USER:$GITEA_TOKEN@192.168.88.27:3002/jgitta/senior-kiosk.git"
git -C "$REPO_DIR" push origin master || echo " (push failed — check network)"
echo "==> Restarting kiosk-dev..."
if [ -f "/usr/local/bin/kiosk-restart" ]; then
/usr/local/bin/kiosk-restart
else
ssh kiosk-dev "/usr/local/bin/kiosk-restart"
fi
echo "==> Trying production kiosk..."
KIOSK=""
if ssh -o ConnectTimeout=5 -o BatchMode=yes $KIOSK_LOCAL "echo ok" &>/dev/null; then
KIOSK="$KIOSK_LOCAL"
echo " Reaching production via local network"
elif ssh -o ConnectTimeout=8 -o BatchMode=yes $KIOSK_REMOTE "echo ok" &>/dev/null; then
KIOSK="$KIOSK_REMOTE"
echo " Reaching production via Tailscale"
else
echo " Production kiosk unreachable — skipping (will deploy when online)"
fi
if [ -n "$KIOSK" ]; then
ssh "$KIOSK" "
cd /home/jgitta/kiosk-browser
git pull
# Inject config at deploy time
config_json=\\\$(cat config.json | sed 's/\\\\\\\\/\\\\\\\\\\\\\\\\/g' | sed 's/\\\"/\\\\\\\"/g' | tr '\\\n' ' ')
sed \"s|const config = {};|const config = \\\$config_json;|\" home-screen-index.html > /home/jgitta/kiosk-home/index.html
cp weather.html /home/jgitta/kiosk-home/weather.html
cp news.html /home/jgitta/kiosk-home/news.html
/usr/local/bin/kiosk-restart
"
echo " Production updated."
fi
echo "==> Deploy complete!"