mirror of
https://gitlab.com/hacklab01/pivilion.git
synced 2026-08-06 16:08:22 +00:00
Move MOTD into TTY login banner
This commit is contained in:
parent
ed0b168ab6
commit
bbbf80c25f
11 changed files with 137 additions and 29 deletions
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source /usr/local/lib/pivilion/common.sh
|
||||
pivilion_load_config
|
||||
pivilion_print_motd "Welcome to Pivilion!"
|
||||
|
|
@ -161,6 +161,7 @@ pivilion_service_state() {
|
|||
|
||||
pivilion_print_motd() {
|
||||
local heading=${1:-Welcome to Pivilion!}
|
||||
local show_addresses=${2:-yes}
|
||||
local uptime_text memory_free memory_total load_one load_five load_fifteen processes torname desired active backend health addresses
|
||||
|
||||
uptime_text=$(uptime -p 2>/dev/null || printf 'unknown')
|
||||
|
|
@ -191,6 +192,19 @@ pivilion_print_motd() {
|
|||
@@, @ ,@@ Onion Address......: $torname
|
||||
@@@@@#@@@@@@@#@@@@@ Desired / active....: $desired / $active
|
||||
Backend / health...: $backend / $health
|
||||
IP addresses.......: $addresses
|
||||
EOF
|
||||
if [ "$show_addresses" = yes ]; then
|
||||
printf ' IP addresses.......: %s\n' "$addresses"
|
||||
fi
|
||||
}
|
||||
|
||||
pivilion_print_issue() {
|
||||
local iface
|
||||
iface=$(pivilion_wifi_interface)
|
||||
if [ -n "$iface" ]; then
|
||||
printf 'My IP address is \\4{%s}\n' "$iface"
|
||||
else
|
||||
printf 'My IP address is unknown\n'
|
||||
fi
|
||||
pivilion_print_motd "Welcome to Pivilion!" no
|
||||
}
|
||||
|
|
|
|||
16
usr/local/lib/pivilion/issue-banner.sh
Executable file
16
usr/local/lib/pivilion/issue-banner.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
source /usr/local/lib/pivilion/common.sh
|
||||
pivilion_require_root
|
||||
pivilion_load_config
|
||||
|
||||
ISSUE_FILE=/etc/issue.d/90-pivilion.issue
|
||||
ISSUE_DIR=$(dirname "$ISSUE_FILE")
|
||||
install -d -m 0755 "$ISSUE_DIR"
|
||||
tmp=$(mktemp "$ISSUE_DIR/.90-pivilion.XXXXXX")
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
pivilion_print_issue > "$tmp"
|
||||
chmod 0644 "$tmp"
|
||||
mv -f "$tmp" "$ISSUE_FILE"
|
||||
trap - EXIT
|
||||
|
|
@ -24,10 +24,18 @@ CAPTIVE_LIVE=$PIVILION_WEBROOT/gen/.htaccess
|
|||
BACKEND=legacy
|
||||
pivilion_uses_networkmanager && BACKEND=networkmanager
|
||||
|
||||
refresh_login_banner() {
|
||||
if [ -x /usr/local/lib/pivilion/issue-banner.sh ]; then
|
||||
/usr/local/lib/pivilion/issue-banner.sh || logger -t pivilion-mode "Could not refresh TTY login banner"
|
||||
fi
|
||||
command -v agetty >/dev/null 2>&1 && agetty --reload >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
activation_error() {
|
||||
local rc=$? line=${BASH_LINENO[0]:-unknown}
|
||||
trap - ERR
|
||||
pivilion_write_state none "$BACKEND" failed "Activation failed at line $line (exit $rc)" || true
|
||||
refresh_login_banner || true
|
||||
logger -t pivilion-mode "Failed to activate $MODE mode at line $line (exit $rc)" 2>/dev/null || true
|
||||
exit "$rc"
|
||||
}
|
||||
|
|
@ -168,16 +176,19 @@ start_hotspot() {
|
|||
pivilion_write_state none "$BACKEND" activating none
|
||||
validate_ap_support || {
|
||||
pivilion_write_state none "$BACKEND" failed "$IFACE does not advertise Wi-Fi AP support"
|
||||
refresh_login_banner
|
||||
echo "$IFACE does not advertise Wi-Fi AP support." >&2
|
||||
exit "$PIVILION_E_HARDWARE"
|
||||
}
|
||||
cleanup_hotspot
|
||||
if ! check_hostapd_conflict; then
|
||||
pivilion_write_state none "$BACKEND" failed "System hostapd conflict"
|
||||
refresh_login_banner
|
||||
exit "$PIVILION_E_CONFLICT"
|
||||
fi
|
||||
if ! check_dns_conflict; then
|
||||
pivilion_write_state none "$BACKEND" failed "Port 53 conflict"
|
||||
refresh_login_banner
|
||||
exit "$PIVILION_E_CONFLICT"
|
||||
fi
|
||||
install_captive_redirect
|
||||
|
|
@ -203,6 +214,7 @@ start_hotspot() {
|
|||
pivilion_write_state hotspot "$BACKEND" degraded "Post-start captive portal diagnostics failed"
|
||||
logger -t pivilion-mode "Hotspot active but degraded; run pivilion diagnose" || true
|
||||
fi
|
||||
refresh_login_banner
|
||||
echo "Pivilion hotspot '$PIVILION_HOTSPOT_SSID' is active on $IFACE."
|
||||
}
|
||||
|
||||
|
|
@ -227,6 +239,7 @@ start_onion() {
|
|||
pivilion_write_state onion "$BACKEND" degraded "${failure:-Onion diagnostics failed}"
|
||||
logger -t pivilion-mode "Onion mode active but degraded: ${failure:-diagnostics failed}" || true
|
||||
fi
|
||||
refresh_login_banner
|
||||
echo "Pivilion onion mode activation completed."
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue