Deliberately skipped Upgrade/Full Reinstall/Complete Uninstall for now: all three are large (130-250 lines), genuinely destructive (wipe/ reinstall the kiosk), and Upgrade specifically is coupled to the legacy script's own self-extraction mechanism (it greps its own running source for embedded heredocs to pull out main.js/preload.js) - there's no modular equivalent to migrate it to yet, since those files don't exist as separate assets outside the monolith. Migrated Diagnostics instead: 4 of the legacy Advanced menu's 12 items (System Status, View Logs, Audio Diagnostics, Network Test), all read-only except one optional "play a test sound?" prompt - a deliberate change of pace with no destructive-action risk to design around, after Sites/WiFi/Power. - lib/menu.sh: ported get_vpn_ips alongside get_ip_address. - menus/diagnostics.sh: straight port, using $KIOSK_USER/$KIOSK_HOME throughout instead of the legacy code's mix of the variable and a hardcoded "kiosk" literal. Bug fixed, same set -e-safety class as v2.1.0's run_menu fix and v2.3.0's netplan/systemctl fixes, but a bigger batch this time: nearly every diagnostic command here was a bare unguarded statement whose *expected, common* failure - no lightdm running, no audio hardware, no network, missing log files, ping/nslookup not even installed - would have crashed the entire session instead of reporting "not found" and continuing. A diagnostics tool has to be the most crash-proof code in the project, since it exists to run when something is already broken. Fixed at every call site: systemctl status | head, tail on lightdm's log, journalctl, ping, nslookup, and three pactl-backed variable assignments. Also noted for future menus in this migration: writing `local var;` and `var=$(cmd)` as separate statements (good practice, and how several earlier real bugs were caught) removes an accidental safety net - `local x=$(cmd)` on one line masks the substitution's exit code with `local`'s own always-success status. Splitting them is correct, but each split assignment needs an explicit `|| true` (or real fallback) where failure is expected and non-fatal, rather than relying on that masking by accident. Caught three instances of exactly this while writing this file fresh, not just porting old bugs. Verified: - Full regression: re-ran every existing scratch-config/stub test suite (sites, display, timezone/pin, lockout, power schedule + RTC, wifi) - all still clean after the lib/menu.sh change. - New test for diagnostics.sh, exercised mostly for real (no destructive-mutation risk here, so minimal stubbing needed): system status, all three log views (including the "no such file" paths for lightdm log and electron log), full 8-step audio diagnostic with test sound declined, and network test - all report gracefully instead of crashing, confirmed by re-running after each fix until every bare unguarded statement was accounted for. - End-to-end: ran the real install.sh as a genuine non-root, non- "kiosk" user, navigating Diagnostics -> System status -> View Logs -> System journal -> Audio diagnostics (declined test sound) -> Network test -> exit. Confirmed every diagnostic path completes and returns to its menu cleanly (exit code 0) even with ping/nslookup missing and no audio hardware/network present in this environment.
115 lines
3.8 KiB
Bash
Executable File
115 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# install.sh - Modular management entry point for Ubuntu Based Kiosk.
|
|
#
|
|
# This is NOT yet the full system installer - that is still the big
|
|
# single-file script (ubuntu-based-kiosk.sh) documented in Readme.md, and
|
|
# first-time provisioning of a new kiosk still goes through it. That file
|
|
# still also contains its own (unmigrated, unmodified) copies of every
|
|
# menu below - both copies coexist deliberately until enough of Core
|
|
# Settings/Addons/Advanced has moved over to retire the old ones in one
|
|
# pass. This entry point is the modular replacement, one menus/*.sh file
|
|
# at a time, so a change to (say) the Sites menu can't accidentally break
|
|
# WiFi setup or the uninstaller three thousand lines away.
|
|
#
|
|
# Migrated so far: Sites & Page Timing (menus/sites.sh), Display &
|
|
# Interaction (menus/display.sh), Timezone (menus/timezone.sh), Hidden
|
|
# Site PIN (menus/hidden_pin.sh), Password Protection & Lockout
|
|
# (menus/lockout.sh), WiFi (menus/wifi.sh), Power/Display/Quiet Hours
|
|
# (menus/power_schedule.sh), Diagnostics (menus/diagnostics.sh - system
|
|
# status/logs/audio/network from the legacy Advanced menu).
|
|
#
|
|
# Usage (once the kiosk has already been installed):
|
|
# git clone <repo>
|
|
# cd ubuntu-based-kiosk
|
|
# ./install.sh
|
|
################################################################################
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# shellcheck source=lib/menu.sh
|
|
source "$SCRIPT_DIR/lib/menu.sh"
|
|
# shellcheck source=lib/config.sh
|
|
source "$SCRIPT_DIR/lib/config.sh"
|
|
# shellcheck source=menus/sites.sh
|
|
source "$SCRIPT_DIR/menus/sites.sh"
|
|
# shellcheck source=menus/display.sh
|
|
source "$SCRIPT_DIR/menus/display.sh"
|
|
# shellcheck source=menus/timezone.sh
|
|
source "$SCRIPT_DIR/menus/timezone.sh"
|
|
# shellcheck source=menus/hidden_pin.sh
|
|
source "$SCRIPT_DIR/menus/hidden_pin.sh"
|
|
# shellcheck source=menus/lockout.sh
|
|
source "$SCRIPT_DIR/menus/lockout.sh"
|
|
# shellcheck source=menus/wifi.sh
|
|
source "$SCRIPT_DIR/menus/wifi.sh"
|
|
# shellcheck source=menus/power_schedule.sh
|
|
source "$SCRIPT_DIR/menus/power_schedule.sh"
|
|
# shellcheck source=menus/diagnostics.sh
|
|
source "$SCRIPT_DIR/menus/diagnostics.sh"
|
|
|
|
################################################################################
|
|
# Preflight
|
|
################################################################################
|
|
|
|
if [[ "$(whoami)" == "kiosk" ]]; then
|
|
log_error "Cannot run as user 'kiosk'"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $EUID -eq 0 ]]; then
|
|
log_error "Run as a regular user with sudo privileges, not as root"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v jq &>/dev/null; then
|
|
log_error "jq is required but not installed. Run: sudo apt-get install -y jq"
|
|
exit 1
|
|
fi
|
|
|
|
if ! is_kiosk_installed; then
|
|
echo
|
|
log_error "No installed kiosk found at ${KIOSK_DIR}."
|
|
echo
|
|
echo "This tool manages an already-installed kiosk. To provision a new"
|
|
echo "one for the first time, use the full installer instead - see"
|
|
echo "Readme.md ('Quick Install') for the current download command."
|
|
echo
|
|
exit 1
|
|
fi
|
|
|
|
################################################################################
|
|
# Top-level menu
|
|
################################################################################
|
|
|
|
main_menu_builder() {
|
|
MENU_LABELS=(
|
|
"Sites & Page Timing"
|
|
"Display & Interaction"
|
|
"Timezone"
|
|
"Hidden Site PIN"
|
|
"Password Protection & Lockout"
|
|
"WiFi"
|
|
"Power/Display/Quiet Hours"
|
|
"Diagnostics"
|
|
)
|
|
MENU_HANDLERS=(
|
|
sites_menu
|
|
display_menu
|
|
timezone_menu
|
|
hidden_pin_menu
|
|
lockout_menu
|
|
wifi_menu
|
|
power_schedule_menu
|
|
diagnostics_menu
|
|
)
|
|
}
|
|
|
|
main_menu_status() {
|
|
echo "Managing kiosk at: ${KIOSK_DIR}"
|
|
}
|
|
|
|
run_menu "UBUNTU BASED KIOSK - MANAGEMENT" main_menu_builder main_menu_status "Exit"
|