Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored. Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
102 lines
3.2 KiB
Bash
102 lines
3.2 KiB
Bash
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
#
|
|
# Networking for the live environment and for the installed system.
|
|
#
|
|
# In the live environment we drive NetworkManager (present in the Gentoo
|
|
# LiveGUI reference) because it works for both wired and wireless. The installed
|
|
# system also uses NetworkManager, which matches the desktop profile.
|
|
|
|
WIFI_PASSPHRASE=""
|
|
|
|
network_interfaces() {
|
|
local iface
|
|
for iface in /sys/class/net/*; do
|
|
iface="${iface##*/}"
|
|
[[ "$iface" == "lo" ]] && continue
|
|
printf '%s\n' "$iface"
|
|
done
|
|
}
|
|
|
|
network_is_wireless() {
|
|
local iface="$1"
|
|
[[ -d "/sys/class/net/$iface/wireless" ]] || \
|
|
[[ -d "/sys/class/net/$iface/phy80211" ]]
|
|
}
|
|
|
|
network_interface_state() {
|
|
cat "/sys/class/net/$1/operstate" 2>/dev/null || printf 'unknown'
|
|
}
|
|
|
|
network_online() {
|
|
command -v ip >/dev/null 2>&1 || return 1
|
|
ip route show default 2>/dev/null | grep -q 'default' && return 0
|
|
if command -v ping >/dev/null 2>&1; then
|
|
ping -c1 -W2 1.1.1.1 >/dev/null 2>&1 && return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
network_status_text() {
|
|
local iface
|
|
printf 'Connectivity: %s\n\n' "$(network_online && echo online || echo offline)"
|
|
for iface in $(network_interfaces); do
|
|
local kind state
|
|
kind="$(network_is_wireless "$iface" && echo wireless || echo wired)"
|
|
state="$(network_interface_state "$iface")"
|
|
printf ' %-12s %-8s %s\n' "$iface" "$kind" "$state"
|
|
done
|
|
}
|
|
|
|
# network_live_start - best effort start of the live network manager
|
|
network_live_start() {
|
|
if command -v rc-service >/dev/null 2>&1; then
|
|
run_cmd "start NetworkManager (OpenRC)" rc-service NetworkManager start 2>/dev/null || true
|
|
fi
|
|
if command -v nmcli >/dev/null 2>&1; then
|
|
run_cmd "ensure NetworkManager running" nmcli general status >/dev/null 2>&1 || true
|
|
fi
|
|
if command -v rfkill >/dev/null 2>&1; then
|
|
run_cmd "unblock wifi" rfkill unblock wifi 2>/dev/null || true
|
|
fi
|
|
}
|
|
|
|
# network_connect_wifi SSID PASSPHRASE - live environment helper
|
|
network_connect_wifi() {
|
|
local ssid="$1" pass="$2"
|
|
command -v nmcli >/dev/null 2>&1 || { log_error "nmcli not available"; return 1; }
|
|
secret_register "$pass"
|
|
if [[ -n "$pass" ]]; then
|
|
run_cmd "connect to wifi '$ssid'" nmcli device wifi connect "$ssid" password "$pass"
|
|
else
|
|
run_cmd "connect to wifi '$ssid'" nmcli device wifi connect "$ssid"
|
|
fi
|
|
}
|
|
|
|
# network_wifi_scan - print "SSID SIGNAL SECURITY" lines
|
|
network_wifi_scan() {
|
|
command -v nmcli >/dev/null 2>&1 || return 1
|
|
nmcli -t -f SSID,SIGNAL,SECURITY device wifi list 2>/dev/null | \
|
|
awk -F: 'NF && $1!=""{printf "%-32s %3s%% %s\n", $1, $2, $3}'
|
|
}
|
|
|
|
# network_configure_target ROOT
|
|
# Write the target hostname and enable the networking services. Service
|
|
# enablement itself happens inside the chroot during install.
|
|
network_configure_target() {
|
|
local root="$1" hostname
|
|
hostname="$(config_get HOSTNAME)"
|
|
mkdir -p "$root/etc"
|
|
printf '%s\n' "$hostname" >"$root/etc/hostname"
|
|
{
|
|
printf '127.0.0.1\tlocalhost\n'
|
|
printf '::1\t\tlocalhost\n'
|
|
printf '127.0.1.1\t%s\n' "$hostname"
|
|
} >"$root/etc/hosts"
|
|
log_info "configured hostname '$hostname' in target"
|
|
}
|
|
|
|
# network_target_service_names - services to enable in the installed system
|
|
network_target_services() {
|
|
printf '%s\n' NetworkManager systemd-resolved
|
|
}
|