simplify installer, drop eval, fix network check

This commit is contained in:
Astral
2026-09-01 10:57:46 +02:00
parent 535ccc1ffc
commit cb1da62339
3 changed files with 106 additions and 78 deletions
+69 -73
View File
@@ -1,88 +1,66 @@
#!/usr/bin/env sh
# keru-install — the Keru OS TUI installer
#
# Walks you through crafting your exact system, then writes make.conf and
# kicks off the build. Everything is swappable here, at install time, and
# locked in when you boot.
#
# Designed to run from the Keru live ISO. Backed by dialog/whiptail if
# present; falls back to plain prompted input. All shell, no magic.
# keru-install — Keru OS installer. Runs from the live ISO, walks you
# through your choices, writes make.conf, then builds your system.
set -eu
. "$(dirname "$0")/../scripts/common.sh"
# ---- defaults (mirror profile/make.conf) --------------------------------
OUT="${MAKE_CONF_OUT:-/tmp/keru/make.conf}"
DROP="/tmp/keru"
mkdir -p "$DROP"
mkdir -p /tmp/keru
# ---- menu helpers -------------------------------------------------------
pick() { # prompt, array-of-labels, defaults -> writes choice to $CHOICE
local prompt="$1"; shift
local default="$1"; shift
# show a menu of options, remember the pick in $CHOICE
pick() {
prompt="$1"; shift
default="$1"; shift
CHOICE="$default"
if command -v dialog >/dev/null 2>&1; then
local args=()
local i=0
for opt in "$@"; do
args+=("$i" "$opt")
i=$((i+1))
done
local sel
sel=$(dialog --stdout --no-cancel --menu "$prompt" 15 60 8 \
--default-item "$default" "${args[@]}") || true
CHOICE=$(eval "printf '%s' \"\${$((sel+1)):-\$default}\"" 2>/dev/null || printf '%s' "$default")
else
printf '%s\n' "== $prompt =="
local n=1
for opt in "$@"; do
printf ' %s) %s\n' "$n" "$opt"
n=$((n+1))
done
printf 'Select [%s]: ' "$default"
read -r sel
[ -n "$sel" ] && CHOICE=$(eval "printf '%s' \"\${$sel}\"") || CHOICE="$default"
fi
printf '%s\n' "== $prompt =="
n=0
for opt in "$@"; do
n=$((n+1))
printf ' %s) %s\n' "$n" "$opt"
done
printf 'Select [%s]: ' "$default"
read -r sel
case "$sel" in
''|*[!0-9]*) CHOICE="$default" ;;
*)
if [ "$sel" -ge 1 ] && [ "$sel" -le "$n" ]; then
i=0
for opt in "$@"; do
i=$((i+1))
[ "$i" -eq "$sel" ] && { CHOICE="$opt"; break; }
done
else
CHOICE="$default"
fi
;;
esac
}
# ---- network check -------------------------------------------------------
# The ISO carries only the installer. Everything else (kernels, init systems,
# libcs, filesystems, tools) is fetched and built at install time, so a working
# network connection is a hard prerequisite.
require_network() {
local ok=0
# try a few reachability probes
for host in mirror.keru.org github.com 1.1.1.1; do
if command -v ping >/dev/null 2>&1 && ping -c1 -W2 "$host" >/dev/null 2>&1; then ok=1; break; fi
# fallback: plain connect test via /dev/tcp
case "$host" in
*.*.*.*) : ;; # ip already covered by ping
esac
ok=0
for host in 1.1.1.1 github.com mirror.keru.org; do
if command -v ping >/dev/null 2>&1 && ping -c1 -W2 "$host" >/dev/null 2>&1; then
ok=1; break
fi
done
if [ "$ok" = "0" ]; then
if command -v nc >/dev/null 2>&1; then
nc -z -w5 mirror.keru.org 443 >/dev/null 2>&1 && ok=1
if command -v nc >/dev/null 2>&1 && nc -z -w5 github.com 443 >/dev/null 2>&1; then
ok=1
elif [ -e /dev/tcp ] && (exec 3<>/dev/tcp/github.com/443) >/dev/null 2>&1; then
ok=1
fi
fi
[ "$ok" = "1" ]
}
# ---- network configuration ------------------------------------------------
configure_network() {
msg "network configuration"
if command -v nmtui >/dev/null 2>&1; then
nmtui 2>/dev/null && return 0
nmtui >/dev/null 2>&1
else
warn "nmtui not available — bring up the network yourself, then continue"
fi
if command -v dialog >/dev/null 2>&1 && command -v wifi-menu >/dev/null 2>&1; then
dialog --stdout --menu "Network" 12 40 3 \
1 "Wireless (wifi-menu)" 2 "Ethernet (skip)" 3 "Manual (ip)" 2>/dev/null
fi
read -r -p "Bring up Ethernet (DHCP) now? [Y/n] " eth
case "$eth" in
n|N|no) : ;;
*) command -v dhcpcd >/dev/null 2>&1 && (dhcpcd >/dev/null 2>&1 &) || true ;;
esac
}
banner "Keru OS — network required"
@@ -90,20 +68,16 @@ info "the ISO only carries the installer."
info "the system you choose (init, libc, fs, kernel, tools) is fetched and"
info "built from the network during installation. a connection is required."
if require_network; then
msg "network: connected"
else
warn "network: not detected"
read -r -p "Configure the network now? [Y/n] " cfg
while ! require_network; do
warn "network: not connected"
read -r -p "Connect to the network now (runs nmtui)? [Y/n] " cfg
case "$cfg" in
n|N|no) die "a network connection is required to install Keru" ;;
*) configure_network ;;
esac
require_network || die "still no network connection — cannot install"
msg "network: connected"
fi
done
msg "network: connected"
# ---- swappable selections ------------------------------------------------
banner "Keru OS — craft your system"
pick "Init system" runit runit s6 openrc systemd busybox-init sysvinit dinit shepherd
@@ -124,7 +98,29 @@ SUDO="$CHOICE"
pick "Network tools" nmtui nmtui networkmanager connman systemd-networkd
NET="$CHOICE"
# ---- assemble make.conf ------------------------------------------------
warn_unstable() {
unstable=0
case "$LIBC:$INIT" in
uclibc-ng:*|musl:systemd)
warn "$LIBC + $INIT: not yet proven to build and boot together"
unstable=1 ;;
esac
case "$LIBC:$KERNEL" in
musl:linux-zen|uclibc-ng:*)
warn "$LIBC + $KERNEL: not yet proven to build and boot together"
unstable=1 ;;
esac
case "$TARGET_FS" in
zfs) warn "zfs + $LIBC: needs kernel module + ZFS userspace, not yet proven"
unstable=1 ;;
reiserfs) warn "reiserfs is unmaintained and has no stable future"
unstable=1 ;;
esac
[ "$unstable" = "1" ] && warn "this combination is unstable. Keru won't stop you — build at your own risk."
}
warn_unstable
msg "writing $OUT"
cat > "$OUT" <<EOF
# Generated by keru-install — hand-tune then rebuild if you like.