#!/bin/bash # # Setup Archipelago kiosk mode on the server # Runs Chromium in kiosk mode so keyboard/touchpad control the web UI # Only starts when logging in at the physical console (tty1) # # Run on server: sudo ./setup-kiosk.sh # set -e KIOSK_USER="${1:-archipelago}" ARCHIPELAGO_URL="${ARCHIPELAGO_URL:-http://localhost}" echo "Setting up kiosk for user: $KIOSK_USER" echo "URL: $ARCHIPELAGO_URL" echo "" # Create .xinitrc for kiosk HOMEDIR=$(getent passwd "$KIOSK_USER" | cut -d: -f6) XINITRC="$HOMEDIR/.xinitrc" cat > "$XINITRC" << 'XINITRC_EOF' #!/bin/bash # Archipelago kiosk — Chromium fullscreen with auto-restart on crash # Disable screen blanking xset s off xset -dpms xset s noblank # Hide cursor after inactivity unclutter -idle 3 -root & # Run Chromium in a restart loop (recovers from crashes within ~3s) while true; do chromium --kiosk \ --app=http://localhost/kiosk \ --noerrdialogs \ --disable-infobars \ --disable-translate \ --no-first-run \ --check-for-update-interval=31536000 \ --disable-features=TranslateUI \ --disable-session-crashed-bubble \ --disable-save-password-bubble \ --disable-suggestions-service \ --disable-component-update sleep 3 done XINITRC_EOF # Replace localhost with actual URL if different if [ "$ARCHIPELAGO_URL" != "http://localhost" ]; then sed -i "s|http://localhost|$ARCHIPELAGO_URL|g" "$XINITRC" fi chown "$KIOSK_USER:$KIOSK_USER" "$XINITRC" chmod +x "$XINITRC" # Add startx to .bash_profile only when on console (tty1) BASHPROFILE="$HOMEDIR/.bash_profile" if [ ! -f "$BASHPROFILE" ]; then touch "$BASHPROFILE" chown "$KIOSK_USER:$KIOSK_USER" "$BASHPROFILE" fi # Remove any existing kiosk block if grep -q "ARCHIPELAGO_KIOSK" "$BASHPROFILE" 2>/dev/null; then sed -i '/# ARCHIPELAGO_KIOSK/,/^# END ARCHIPELAGO_KIOSK/d' "$BASHPROFILE" fi # Add kiosk startup (only runs on physical console tty1) cat >> "$BASHPROFILE" << 'BASHPROFILE_EOF' # ARCHIPELAGO_KIOSK - Start X/kiosk when logging in at physical console if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then startx 2>/dev/null # If X fails, show IP on text console as fallback if [ $? -ne 0 ]; then IP=$(hostname -I | awk '{print $1}') echo "" echo " ============================================= " echo " Archipelago Server (kiosk display failed) " echo " IP: $IP " echo " Web UI: http://$IP " echo " ============================================= " echo "" fi fi # END ARCHIPELAGO_KIOSK BASHPROFILE_EOF chown "$KIOSK_USER:$KIOSK_USER" "$BASHPROFILE" # Install kiosk X11 launcher script (used by systemd service) KIOSK_X11="/usr/local/bin/archipelago-kiosk-x11" cat > "$KIOSK_X11" << 'X11_EOF' #!/bin/bash # Archipelago kiosk X11 session — launched by systemd or startx # Disable screen blanking xset s off xset -dpms xset s noblank # Hide cursor after inactivity unclutter -idle 3 -root & # Run Chromium in a restart loop (recovers from crashes within ~3s) while true; do chromium --kiosk \ --app=http://localhost/kiosk \ --noerrdialogs \ --disable-infobars \ --disable-translate \ --no-first-run \ --check-for-update-interval=31536000 \ --disable-features=TranslateUI \ --disable-session-crashed-bubble \ --disable-save-password-bubble \ --disable-suggestions-service \ --disable-component-update sleep 3 done X11_EOF # Replace localhost with actual URL if different if [ "$ARCHIPELAGO_URL" != "http://localhost" ]; then sed -i "s|http://localhost|$ARCHIPELAGO_URL|g" "$KIOSK_X11" fi chmod +x "$KIOSK_X11" # Install kiosk watchdog script install -m 755 "$(dirname "$0")/kiosk-watchdog.sh" /usr/local/bin/archipelago-kiosk-watchdog 2>/dev/null || true # Install systemd services SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" if [ -f "$SCRIPT_DIR/image-recipe/configs/archipelago-kiosk.service" ]; then cp "$SCRIPT_DIR/image-recipe/configs/archipelago-kiosk.service" /etc/systemd/system/ cp "$SCRIPT_DIR/image-recipe/configs/archipelago-kiosk-watchdog.service" /etc/systemd/system/ systemctl daemon-reload systemctl enable archipelago-kiosk-watchdog echo " Systemd services installed (enable archipelago-kiosk.service to auto-start)" fi echo "Kiosk installed!" echo "" echo " When you log in at the physical console (monitor + keyboard):" echo " - X will start automatically" echo " - Chromium opens in kiosk mode with crash auto-restart" echo " - If X fails, IP address is displayed on text console" echo " - Your keyboard/touchpad will control the Archipelago UI" echo "" echo " To use: Connect a display, plug in keyboard, reboot (or log in at tty1)" echo ""