From 5334accd1ccc0d52b7b8502e118f65de410a311b Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:04:39 +0200 Subject: [PATCH] Support non-apt OS, fix sysvinit autologin Refine LXC container bootstrap and sysvinit autologin handling. - Fix case branch formatting and change Debian-family check to an elif to avoid logic fall-through. - Add a non-apt branch for Fedora/Rocky/Alma/CentOS/openEuler/openSUSE/Arch/Gentoo that sets the container timezone from the host and ensures curl is installed via the appropriate package manager. - Improve sysvinit (/etc/inittab) auto-login changes: use more robust sed patterns, append a console autologin entry via heredoc, signal init to reload inittab before killing getty processes, and target getty processes more precisely to ensure proper respawn with new settings. --- misc/build.func | 32 ++++++++++++++++++++++++++++++-- misc/install.func | 38 ++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/misc/build.func b/misc/build.func index 157e5382..6d7bc9ff 100644 --- a/misc/build.func +++ b/misc/build.func @@ -3608,7 +3608,7 @@ install_script() { base_settings "$VERBOSE" echo_default break - ;; + ;; *) echo -e "${CROSS}${RD}Invalid option: $CHOICE${CL}" exit 1 @@ -4598,7 +4598,7 @@ EOF exit 1 fi } - else + elif [[ "$var_os" =~ ^(debian|ubuntu|devuan)$ ]]; then sleep 3 LANG=${LANG:-en_US.UTF-8} @@ -4764,6 +4764,34 @@ EOF exit 1 fi } + else + # Non-apt, non-apk systems: Fedora/Rocky/Alma/CentOS/openEuler/openSUSE/Arch/Gentoo + sleep 3 + + # Set timezone (host's timezone, falling back to UTC) + if [[ -z "${tz:-}" ]]; then + tz=$(timedatectl show --property=Timezone --value 2>/dev/null || echo "UTC") + fi + [[ "${tz:-}" == Etc/* ]] && tz="UTC" + if pct exec "$CTID" -- test -e "/usr/share/zoneinfo/$tz"; then + pct exec "$CTID" -- bash -c "ln -sf \"/usr/share/zoneinfo/$tz\" /etc/localtime && echo \"$tz\" >/etc/timezone || true" + fi + + # Ensure curl is present for install.func bootstrap (most templates have it, but be safe) + case "$var_os" in + fedora | rocky | rockylinux | alma | almalinux | centos | openeuler) + pct exec "$CTID" -- bash -c "command -v curl >/dev/null 2>&1 || (command -v dnf >/dev/null 2>&1 && dnf install -y curl >/dev/null 2>&1) || (command -v yum >/dev/null 2>&1 && yum install -y curl >/dev/null 2>&1)" || true + ;; + opensuse) + pct exec "$CTID" -- bash -c "command -v curl >/dev/null 2>&1 || zypper -n install curl >/dev/null 2>&1" || true + ;; + archlinux | arch) + pct exec "$CTID" -- bash -c "command -v curl >/dev/null 2>&1 || pacman -Sy --noconfirm curl >/dev/null 2>&1" || true + ;; + gentoo) + pct exec "$CTID" -- bash -c "command -v curl >/dev/null 2>&1 || emerge --quiet net-misc/curl >/dev/null 2>&1" || true + ;; + esac fi msg_ok "Customized LXC Container" diff --git a/misc/install.func b/misc/install.func index 37f9f57f..4468ee67 100644 --- a/misc/install.func +++ b/misc/install.func @@ -1211,36 +1211,30 @@ EOF ;; sysvinit) - # Devuan/older systems - modify inittab for auto-login - # Devuan 5 (daedalus) uses SysVinit with various inittab formats - # LXC can use /dev/console OR /dev/tty1 depending on how pct console connects + # Devuan/older SysVinit systems: modify inittab for auto-login on tty1 + console if [[ -f /etc/inittab ]]; then - # Backup original inittab cp /etc/inittab /etc/inittab.bak 2>/dev/null || true - # Enable autologin on tty1 (for direct access) - handle various formats - # Devuan uses format: 1:2345:respawn:/sbin/getty 38400 tty1 - sed -i 's|^\(1:[0-9]*:respawn:\).*getty.*tty1.*|1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 38400 linux|' /etc/inittab + # Replace the tty1 getty line with an autologin version. + # Devuan 5 ships: 1:2345:respawn:/sbin/agetty --noclear tty1 38400 linux + sed -i 's|^\(1:[0-9]*:respawn:\).*[ag]etty.*tty1.*|1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 38400 linux|' /etc/inittab - # CRITICAL: Add/replace console entry for LXC - this is what pct console uses! - # Remove any existing console entries first (commented or not) - sed -i '/^[^#]*:.*:respawn:.*getty.*console/d' /etc/inittab + # Add/replace console entry (pct console maps to /dev/console in some configs) + sed -i '/^[^#]*:.*:respawn:.*[ag]etty.*console/d' /etc/inittab sed -i '/^# LXC console autologin/d' /etc/inittab + cat >>/etc/inittab <<'EOF' - # Add new console entry for LXC at the end - echo "" >>/etc/inittab - echo "# LXC console autologin (added by community-scripts)" >>/etc/inittab - echo "co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux" >>/etc/inittab +# LXC console autologin (added by community-scripts) +co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux +EOF - # Force a reload of inittab and respawn ALL getty processes - # Kill ALL getty processes to force respawn with new autologin settings - pkill -9 -f '[ag]etty' &>/dev/null || true - - # Small delay to let init notice the dead processes - sleep 1 - - # Reload inittab - try multiple methods + # IMPORTANT: signal init to load the new inittab into memory FIRST, + # then kill the running getty — init will respawn it using the new config. + # (Killing first causes init to respawn with the OLD in-memory config.) telinit q &>/dev/null || init q &>/dev/null || kill -HUP 1 &>/dev/null || true + sleep 1 + pkill -f '[ag]etty.*tty1' &>/dev/null || true + pkill -f '[ag]etty.*console' &>/dev/null || true fi touch /root/.hushlogin ;;