Files
KeruOS/installer/install.sh
T
2026-09-01 11:45:46 +02:00

148 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env sh
# 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"
OUT="${MAKE_CONF_OUT:-/tmp/keru/make.conf}"
mkdir -p /tmp/keru
# show a menu of options, remember the pick in $CHOICE
pick() {
prompt="$1"; shift
default="$1"; shift
CHOICE="$default"
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
}
require_network() {
ok=0
for host in 1.1.1.1 github.com; 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 && 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" ]
}
configure_network() {
if command -v nmtui >/dev/null 2>&1; then
nmtui >/dev/null 2>&1
else
warn "nmtui not available — bring up the network yourself, then continue"
fi
}
banner "Keru OS — network required"
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."
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
done
msg "network: connected"
banner "Keru OS — craft your system"
pick "Init system" runit runit s6 openrc systemd busybox-init sysvinit dinit shepherd
INIT="$CHOICE"
pick "C library" glibc glibc musl uclibc-ng
LIBC="$CHOICE"
pick "Filesystem" ext4 ext4 ext2 ext3 btrfs xfs zfs f2fs jfs reiserfs
TARGET_FS="$CHOICE"
pick "Kernel" linux linux linux-lts linux-hardened linux-cachyos linux-zen
KERNEL="$CHOICE"
pick "Privilege elevation (sudo alternative)" doas doas sudo opendoas su
SUDO="$CHOICE"
pick "Network tools" nmtui nmtui networkmanager connman systemd-networkd
NET="$CHOICE"
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.
INIT=$INIT
LIBC=$LIBC
TARGET_FS=$TARGET_FS
KERNEL=$KERNEL
SUDO=$SUDO
NET=$NET
LICENSE_ACCEPT=(*)
EOF
msg "profile complete:"
cat "$OUT"
read -r -p "Build now? [y/N] " go
case "$go" in
y|Y|yes)
"$(dirname "$0")/../scripts/build-root.sh" "$OUT"
;;
*)
msg "saved profile to $OUT (run scripts/build-root.sh to build)"
;;
esac