#!/usr/bin/env bash # hamclock.me Raspberry Pi setup # Makes this Pi open hamclock.me full-screen every time it starts. # Safe to run again (it just rewrites its own files). Nothing is deleted. # Undo: rm -f ~/.config/autostart/hamclock-me.desktop ~/.local/bin/hamclock-me # and remove the "hamclock-me" line from ~/.config/labwc/autostart or ~/.config/wayfire.ini set -e if [ "$(id -u)" = "0" ]; then echo "Run this as your normal Pi user (not with sudo)."; exit 1 fi # Settings from the setup page. Only letters, numbers, / = & and _ - are kept. PARAMS="$(printf '%s' "${1:-}" | tr -cd 'A-Za-z0-9/=&_-')" URL="https://hamclock.me/" [ -n "$PARAMS" ] && URL="https://hamclock.me/?${PARAMS}" # Find a browser BROWSER="" for b in chromium-browser chromium; do if command -v "$b" >/dev/null 2>&1; then BROWSER="$b"; break; fi done if [ -z "$BROWSER" ]; then echo "Chromium isn't installed. Installing it (you may be asked for your password)..." sudo apt-get update && sudo apt-get install -y chromium-browser || sudo apt-get install -y chromium for b in chromium-browser chromium; do if command -v "$b" >/dev/null 2>&1; then BROWSER="$b"; break; fi done fi [ -z "$BROWSER" ] && { echo "Couldn't install Chromium. Install it, then run this again."; exit 1; } # Launcher script mkdir -p "$HOME/.local/bin" cat > "$HOME/.local/bin/hamclock-me" </dev/null || true exec $BROWSER --kiosk --noerrdialogs --disable-infobars --disable-session-crashed-bubble \\ --check-for-update-interval=31536000 --password-store=basic "$URL" EOF chmod +x "$HOME/.local/bin/hamclock-me" # Autostart for every Raspberry Pi OS desktop (old LXDE, Wayfire, labwc) mkdir -p "$HOME/.config/autostart" cat > "$HOME/.config/autostart/hamclock-me.desktop" </dev/null 2>&1; then mkdir -p "$HOME/.config/labwc" touch "$HOME/.config/labwc/autostart" grep -q 'hamclock-me' "$HOME/.config/labwc/autostart" || echo "$HOME/.local/bin/hamclock-me &" >> "$HOME/.config/labwc/autostart" fi if [ -f "$HOME/.config/wayfire.ini" ]; then if ! grep -q 'hamclock-me' "$HOME/.config/wayfire.ini"; then if grep -q '^\[autostart\]' "$HOME/.config/wayfire.ini"; then sed -i "/^\[autostart\]/a hamclock = $HOME/.local/bin/hamclock-me" "$HOME/.config/wayfire.ini" else printf '\n[autostart]\nhamclock = %s\n' "$HOME/.local/bin/hamclock-me" >> "$HOME/.config/wayfire.ini" fi fi fi # Stop the screen going blank (Raspberry Pi OS only; skipped if raspi-config isn't there) if command -v raspi-config >/dev/null 2>&1; then sudo raspi-config nonint do_blanking 1 2>/dev/null || true fi echo echo "Done. This Pi will open:" echo " $URL" echo "full-screen at startup. Restart now with: sudo reboot" echo "Press Alt+F4 to close the clock. 73!"