#!/bin/bash # Kiosk Pi Bootstrap Script # Usage: curl -sL kiosk.contractcandles.com | bash -s -- "https://your-kiosk-url" # # Sets up a Raspberry Pi as a fullscreen kiosk display: # - Installs Chromium if missing # - Downloads and installs the kiosk management script # - Configures 4K output, CEC, and overscan # - Downloads and sets the CCD wallpaper # - Configures autostart on boot # - Launches the kiosk immediately set -euo pipefail KIOSK_URL="${1:-}" KIOSK_SERVER="https://kiosk.contractcandles.com" # --- Colours --- RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' info() { echo -e "${BLUE}[INFO]${NC} $*"; } ok() { echo -e "${GREEN}[OK]${NC} $*"; } warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } err() { echo -e "${RED}[ERROR]${NC} $*"; } # --- Validate arguments --- if [[ -z "$KIOSK_URL" ]]; then err "No kiosk URL provided." echo "" echo "Usage:" echo " curl -sL kiosk.contractcandles.com | bash -s -- \"https://ops-tv.thfholdings.com/tv/chichester/1,2,3,4\"" exit 1 fi echo "" echo "==========================================" echo " CCD Kiosk Pi Setup" echo "==========================================" echo "" info "Kiosk URL: $KIOSK_URL" echo "" # --- Install Chromium if not present --- if command -v chromium-browser &>/dev/null || command -v chromium &>/dev/null; then ok "Chromium already installed" else info "Installing Chromium..." sudo apt-get update -qq sudo apt-get install -y -qq chromium-browser ok "Chromium installed" fi # --- Ensure xdotool is available (used for screen blanking prevention) --- if command -v xdotool &>/dev/null; then ok "xdotool already installed" else info "Installing xdotool..." sudo apt-get install -y -qq xdotool ok "xdotool installed" fi # --- Configure /boot/firmware/config.txt for 4K, CEC, and overscan --- BOOT_CONFIG="/boot/firmware/config.txt" if [[ ! -f "$BOOT_CONFIG" ]]; then BOOT_CONFIG="/boot/config.txt" fi if [[ -f "$BOOT_CONFIG" ]]; then info "Configuring display output (4K, CEC, overscan)..." changed=false # Enable 4K @ 60Hz on HDMI0 if ! grep -q "^hdmi_enable_4kp60=1" "$BOOT_CONFIG" 2>/dev/null; then echo "hdmi_enable_4kp60=1" | sudo tee -a "$BOOT_CONFIG" >/dev/null changed=true fi # Disable overscan (removes black borders, fills TV natively) if ! grep -q "^disable_overscan=1" "$BOOT_CONFIG" 2>/dev/null; then echo "disable_overscan=1" | sudo tee -a "$BOOT_CONFIG" >/dev/null changed=true fi # Prevent TV from controlling Pi power state via CEC unexpectedly if ! grep -q "^hdmi_ignore_cec_init=1" "$BOOT_CONFIG" 2>/dev/null; then echo "hdmi_ignore_cec_init=1" | sudo tee -a "$BOOT_CONFIG" >/dev/null changed=true fi # Increase GPU memory for 4K rendering if ! grep -q "^gpu_mem=" "$BOOT_CONFIG" 2>/dev/null; then echo "gpu_mem=256" | sudo tee -a "$BOOT_CONFIG" >/dev/null changed=true fi if $changed; then ok "Boot config updated (changes apply after reboot)" else ok "Boot config already configured" fi else warn "Boot config not found — skipping display configuration" fi # --- Download kiosk script --- info "Downloading kiosk script..." curl -sL "${KIOSK_SERVER}/start_kiosk.sh" -o "$HOME/start_kiosk.sh" chmod +x "$HOME/start_kiosk.sh" ok "Kiosk script installed at $HOME/start_kiosk.sh" # --- Download and set wallpaper --- info "Downloading CCD wallpaper (4K)..." mkdir -p "$HOME/.wallpaper" curl -sL "${KIOSK_SERVER}/wallpaper/CCD-3840x2160.png" -o "$HOME/.wallpaper/CCD-3840x2160.png" ok "Wallpaper downloaded" # Set wallpaper via pcmanfm (works on Raspberry Pi OS desktop) WALLPAPER_PATH="$HOME/.wallpaper/CCD-3840x2160.png" # Try pcmanfm (LXDE — most common on RPi OS) if command -v pcmanfm &>/dev/null; then # Update the desktop config directly (pcmanfm --set-wallpaper needs a running instance) DESKTOP_CONF="$HOME/.config/pcmanfm/LXDE-pi/desktop-items-0.conf" if [[ -f "$DESKTOP_CONF" ]]; then # Update existing wallpaper line sed -i "s|^wallpaper=.*|wallpaper=${WALLPAPER_PATH}|" "$DESKTOP_CONF" # Ensure stretch mode for 4K fill if grep -q "^wallpaper_mode=" "$DESKTOP_CONF"; then sed -i "s|^wallpaper_mode=.*|wallpaper_mode=stretch|" "$DESKTOP_CONF" else echo "wallpaper_mode=stretch" >> "$DESKTOP_CONF" fi ok "Wallpaper configured (pcmanfm)" else # Config doesn't exist yet — create it mkdir -p "$(dirname "$DESKTOP_CONF")" cat > "$DESKTOP_CONF" << WPEOF [*] wallpaper_mode=stretch wallpaper_common=1 wallpaper=${WALLPAPER_PATH} desktop_bg=#000000 desktop_fg=#ffffff desktop_shadow=#000000 show_documents=0 show_trash=0 show_mounts=0 WPEOF ok "Wallpaper configured (pcmanfm — created new config)" fi # Refresh desktop if pcmanfm is running pcmanfm --reconfigure 2>/dev/null || true fi # Also set for labwc/wayfire (swaybg) if present if command -v swaybg &>/dev/null; then # Kill existing swaybg and start with new wallpaper pkill swaybg 2>/dev/null || true swaybg -i "$WALLPAPER_PATH" -m fill & ok "Wallpaper set (swaybg/Wayland)" fi # --- Set kiosk URL environment variable --- info "Setting KIOSK_URL environment..." # Write to .kiosk_env so start_kiosk.sh can source it cat > "$HOME/.kiosk_env" << EOF export KIOSK_URL="${KIOSK_URL}" EOF ok "KIOSK_URL saved to $HOME/.kiosk_env" # Also add to .bashrc if not already there if ! grep -q "source.*\.kiosk_env" "$HOME/.bashrc" 2>/dev/null; then echo '[ -f "$HOME/.kiosk_env" ] && source "$HOME/.kiosk_env"' >> "$HOME/.bashrc" fi # Export for current session export KIOSK_URL # --- Configure LXDE autostart --- AUTOSTART_DIR="$HOME/.config/lxsession/LXDE-pi" AUTOSTART_FILE="${AUTOSTART_DIR}/autostart" info "Configuring autostart..." mkdir -p "$AUTOSTART_DIR" # Build autostart file — keep existing panel/desktop entries, add kiosk cat > "$AUTOSTART_FILE" << EOF @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi @bash -c "source \$HOME/.kiosk_env && \$HOME/start_kiosk.sh" EOF ok "Autostart configured at $AUTOSTART_FILE" # --- Clear Chromium session state and singleton locks --- info "Clearing Chromium state..." rm -rf "$HOME/.config/chromium/Default/Session*" \ "$HOME/.config/chromium/Default/Current*" \ "$HOME/.config/chromium/SingletonLock" \ "$HOME/.config/chromium/SingletonCookie" \ "$HOME/.config/chromium/SingletonSocket" 2>/dev/null || true ok "Chromium state cleared" # --- Clear GNOME keyring (prevents unlock popup) --- info "Clearing GNOME keyring..." rm -f "$HOME/.local/share/keyrings/"* 2>/dev/null || true ok "Keyring cleared" # --- Kill existing kiosk/chromium processes --- info "Stopping any existing kiosk processes..." pkill -f start_kiosk.sh 2>/dev/null || true pkill -f chromium 2>/dev/null || true sleep 1 pkill -9 -f chromium 2>/dev/null || true ok "Existing processes stopped" # --- Launch kiosk --- info "Launching kiosk..." nohup bash -c "source $HOME/.kiosk_env && $HOME/start_kiosk.sh" >/dev/null 2>&1 & sleep 2 # --- Status summary --- echo "" echo "==========================================" echo " Setup Complete" echo "==========================================" echo "" ok "Kiosk URL: $KIOSK_URL" ok "Kiosk script: $HOME/start_kiosk.sh" ok "Wallpaper: $WALLPAPER_PATH" ok "Autostart: $AUTOSTART_FILE" ok "Log file: $HOME/kiosk.log" echo "" if pgrep -f chromium >/dev/null 2>&1; then ok "Chromium is running" else warn "Chromium may still be starting — check $HOME/kiosk.log" fi echo "" info "Display settings (4K/CEC/overscan) will take effect after reboot." info "The kiosk will autostart on every boot." echo ""