diff --git a/posimai-dev/setup-kiosk.sh b/posimai-dev/setup-kiosk.sh new file mode 100644 index 00000000..a1d8f2ec --- /dev/null +++ b/posimai-dev/setup-kiosk.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# posimai-station kiosk setup +# Usage: bash setup-kiosk.sh +# What this does: +# 1. Installs posimai-dev as a systemd service (auto-start on boot) +# 2. Installs openbox (lightweight window manager, replaces GNOME) +# 3. Sets up auto-login and Chromium kiosk pointing to station.html +# 4. Removes GNOME (saves ~1.5GB disk + frees RAM) +# +# SAFE TO RUN: shows a summary and asks for confirmation before each step. + +set -e + +STATION_URL="http://localhost:3000/station" +SERVICE_SRC="$(dirname "$0")/posimai-dev.service" +WHOAMI=$(whoami) + +echo "" +echo "=== posimai-station kiosk setup ===" +echo "Current user : $WHOAMI" +echo "Station URL : $STATION_URL" +echo "" + +# ── Step 1: Detect username and home ────────────────────────── +# The service file was written with User=ubuntu-pc, update if different +if [ "$WHOAMI" != "ubuntu-pc" ]; then + echo "[INFO] Updating service file user from 'ubuntu-pc' to '$WHOAMI'" + sed -i "s/User=ubuntu-pc/User=$WHOAMI/g" "$SERVICE_SRC" + sed -i "s|/home/ubuntu-pc/|/home/$WHOAMI/|g" "$SERVICE_SRC" +fi + +# ── Step 2: Install posimai-dev as systemd service ──────────── +echo "--- Step 1: systemd service for posimai-dev ---" +read -p "Install / update posimai-dev.service? [Y/n] " ans +if [[ "$ans" != "n" && "$ans" != "N" ]]; then + sudo cp "$SERVICE_SRC" /etc/systemd/system/posimai-dev.service + sudo systemctl daemon-reload + sudo systemctl enable posimai-dev + sudo systemctl restart posimai-dev + sleep 2 + if curl -sf http://localhost:3000/api/health > /dev/null; then + echo " [OK] posimai-dev is running" + else + echo " [WARN] posimai-dev did not respond. Check: sudo journalctl -u posimai-dev -n 20" + fi +fi + +# ── Step 3: Install Openbox + Chromium ──────────────────────── +echo "" +echo "--- Step 2: Install openbox + chromium ---" +read -p "Install openbox and chromium-browser? [Y/n] " ans +if [[ "$ans" != "n" && "$ans" != "N" ]]; then + sudo apt-get update -qq + sudo apt-get install -y openbox chromium-browser xdotool unclutter + echo " [OK] installed" +fi + +# ── Step 4: Kiosk autostart ─────────────────────────────────── +echo "" +echo "--- Step 3: Configure kiosk autostart ---" +AUTOSTART_DIR="$HOME/.config/openbox" +mkdir -p "$AUTOSTART_DIR" +cat > "$AUTOSTART_DIR/autostart" << EOF +# posimai-station kiosk +# Wait for posimai-dev to be ready +sleep 3 + +# Hide cursor after 1 second of inactivity +unclutter -idle 1 -root & + +# Launch Chromium in kiosk mode +chromium-browser \ + --kiosk \ + --no-first-run \ + --disable-infobars \ + --disable-session-crashed-bubble \ + --disable-translate \ + --noerrdialogs \ + --app=$STATION_URL & +EOF +echo " [OK] openbox autostart written to $AUTOSTART_DIR/autostart" + +# ── Step 5: LightDM autologin ───────────────────────────────── +echo "" +echo "--- Step 4: Configure auto-login (LightDM) ---" +read -p "Set up autologin for user '$WHOAMI' with openbox session? [Y/n] " ans +if [[ "$ans" != "n" && "$ans" != "N" ]]; then + LIGHTDM_CONF="/etc/lightdm/lightdm.conf.d/50-kiosk.conf" + sudo mkdir -p /etc/lightdm/lightdm.conf.d + sudo tee "$LIGHTDM_CONF" > /dev/null << EOF +[Seat:*] +autologin-user=$WHOAMI +autologin-user-timeout=0 +user-session=openbox +EOF + echo " [OK] LightDM autologin configured" +fi + +# ── Step 6: Remove GNOME (optional, last step) ──────────────── +echo "" +echo "--- Step 5: Remove GNOME Desktop ---" +echo " This frees ~1.5GB disk and ~600MB RAM on boot." +echo " The display will show station.html only (no desktop UI)." +echo " WARNING: This is hard to undo without reinstalling Ubuntu." +read -p "Remove GNOME now? [y/N] " ans +if [[ "$ans" == "y" || "$ans" == "Y" ]]; then + sudo apt-get remove --purge -y ubuntu-desktop gnome-shell gnome-session \ + gnome-panel gnome-control-center nautilus + sudo apt-get autoremove -y + echo " [OK] GNOME removed" +else + echo " [SKIP] GNOME not removed. Run this script again when ready." +fi + +echo "" +echo "=== Setup complete ===" +echo "Reboot to activate kiosk mode: sudo reboot" +echo "" +echo "Useful commands:" +echo " sudo systemctl status posimai-dev # check server" +echo " sudo journalctl -u posimai-dev -f # server logs" +echo " sudo systemctl restart posimai-dev # restart server"