Files
ubuntu-based-kiosk/menus/advanced_virtual_consoles.sh
T
Claude a3313aa9b8 Migrate 4 more Advanced items (Electron, Factory Reset, Virtual Consoles, Emergency Hotspot); bump to v2.11.0
New in install.sh's Advanced menu, alongside Diagnostics:
- menus/advanced_electron.sh: "Electron Maintenance" - the legacy
  "Manual Electron Update" and "Fix Blank Screen" combined into one
  submenu, sharing the binary-repair logic (electron_install_binary).
- menus/advanced_factory_reset.sh: "Factory Reset" - wipes config.json
  back to defaults only; addons are untouched.
- menus/advanced_virtual_consoles.sh: "Virtual Consoles" - toggles
  Ctrl+Alt+F1-F8 terminal login access.
- menus/advanced_emergency_hotspot.sh: "Emergency Hotspot" - auto-starts
  a WiFi hotspot if no internet is detected 60 seconds after boot. Its
  own runtime script and systemd unit now go through $BIN_DIR/
  $SYSTEMD_DIR like every other addon's own files, instead of the
  legacy's hardcoded /usr/local/bin and /etc/systemd/system.

That covers 8 of the legacy Advanced menu's 12 entries. Not migrated
this round: Export/Import Settings (pending a decision on rebuilding it
around actual paths vs. a hardcoded step list, or whether the future
web UI replaces the need for it) and Fix Squeezelite Audio (small
enough it may fold into the LMS addon instead of staying standalone).

Full command-level stubbed test suite per file, including set -e safety
checks (declined/failed paths never crash the session) and content
verification for every written file. Full 18-suite regression + real
end-to-end menu navigation via install.sh all pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VfsFSoRqfbRG7XAg5RoE7e
2026-08-19 02:52:43 +00:00

128 lines
4.0 KiB
Bash

#!/bin/bash
################################################################################
# menus/advanced_virtual_consoles.sh - "Virtual Consoles" (Advanced): toggle
# Ctrl+Alt+F1-F8 terminal login access for troubleshooting.
#
# Real system state: masks/unmasks the getty@ttyN systemd units and writes
# a fixed-path X11 server-flags file. Neither is relocatable (X11 only
# reads /etc/X11/xorg.conf.d/, and getty units are always system units),
# so tests use full command-level `sudo` stubbing, same approach as CUPS.
#
# Depends on: lib/menu.sh, lib/config.sh being sourced first.
################################################################################
vconsoles_are_disabled() {
local getty_masked=false
local vt_switch_disabled=false
if systemctl is-masked --quiet getty@tty1.service 2>/dev/null; then
getty_masked=true
fi
if [[ -f /etc/X11/xorg.conf.d/10-serverflags.conf ]] && \
grep -q 'Option.*"DontVTSwitch".*"true"' /etc/X11/xorg.conf.d/10-serverflags.conf 2>/dev/null; then
vt_switch_disabled=true
fi
[[ "$getty_masked" == "true" || "$vt_switch_disabled" == "true" ]]
}
advanced_virtual_consoles_status() {
if vconsoles_are_disabled; then
echo "Virtual consoles: Disabled"
else
echo "Virtual consoles: Enabled"
fi
}
advanced_virtual_consoles_menu_builder() {
if vconsoles_are_disabled; then
MENU_LABELS=("Enable virtual consoles (Ctrl+Alt+F1-F8 for manual login)")
MENU_HANDLERS=(action_enable_virtual_consoles)
else
MENU_LABELS=("Disable virtual consoles (more secure, kiosk only)")
MENU_HANDLERS=(action_disable_virtual_consoles)
fi
}
advanced_virtual_consoles_menu() {
run_menu "VIRTUAL CONSOLES" advanced_virtual_consoles_menu_builder advanced_virtual_consoles_status
}
################################################################################
# Actions
################################################################################
action_enable_virtual_consoles() {
echo
echo "Enabling virtual consoles..."
for i in {1..8}; do
sudo systemctl unmask "getty@tty${i}.service" 2>/dev/null || true
done
sudo systemctl daemon-reload 2>/dev/null || true
sudo mkdir -p /etc/X11/xorg.conf.d
sudo tee /etc/X11/xorg.conf.d/10-serverflags.conf > /dev/null <<'EOF'
Section "ServerFlags"
# Disable Ctrl+Alt+Backspace (X server kill)
Option "DontZap" "true"
# ALLOW VT switching (Ctrl+Alt+F1-F12)
Option "DontVTSwitch" "false"
# Don't allow clients to disconnect on exit
Option "AllowClosedownGrabs" "false"
EndSection
EOF
log_success "Virtual consoles enabled"
echo " Access with Ctrl+Alt+F1 through Ctrl+Alt+F8"
echo " (Ctrl+Alt+F7 typically returns to the kiosk)"
echo
if ask_yes_no "Restart kiosk display now to apply?" "n"; then
sudo systemctl restart lightdm
else
log_warning "Remember to restart: sudo systemctl restart lightdm"
fi
pause
}
action_disable_virtual_consoles() {
echo
ask_yes_no "Disable all virtual consoles?" "n" || { echo "Cancelled"; pause; return; }
echo "Disabling virtual consoles..."
for i in {1..8}; do
sudo systemctl mask "getty@tty${i}.service" 2>/dev/null || true
done
sudo systemctl daemon-reload 2>/dev/null || true
sudo mkdir -p /etc/X11/xorg.conf.d
sudo tee /etc/X11/xorg.conf.d/10-serverflags.conf > /dev/null <<'EOF'
Section "ServerFlags"
# Disable Ctrl+Alt+Backspace (X server kill)
Option "DontZap" "true"
# DISABLE VT switching (Ctrl+Alt+F1-F12)
Option "DontVTSwitch" "true"
# Don't allow clients to disconnect on exit
Option "AllowClosedownGrabs" "false"
EndSection
EOF
log_success "Virtual consoles disabled"
echo " You can re-enable them from this menu at any time."
echo
if ask_yes_no "Restart kiosk display now to apply?" "n"; then
sudo systemctl restart lightdm
else
log_warning "Remember to restart: sudo systemctl restart lightdm"
fi
pause
}