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.
This commit is contained in:
CanbiZ (MickLesk)
2026-04-27 14:04:39 +02:00
parent 582eb5c718
commit 5334accd1c
2 changed files with 46 additions and 24 deletions

View File

@@ -3608,7 +3608,7 @@ install_script() {
base_settings "$VERBOSE" base_settings "$VERBOSE"
echo_default echo_default
break break
;; ;;
*) *)
echo -e "${CROSS}${RD}Invalid option: $CHOICE${CL}" echo -e "${CROSS}${RD}Invalid option: $CHOICE${CL}"
exit 1 exit 1
@@ -4598,7 +4598,7 @@ EOF
exit 1 exit 1
fi fi
} }
else elif [[ "$var_os" =~ ^(debian|ubuntu|devuan)$ ]]; then
sleep 3 sleep 3
LANG=${LANG:-en_US.UTF-8} LANG=${LANG:-en_US.UTF-8}
@@ -4764,6 +4764,34 @@ EOF
exit 1 exit 1
fi 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 fi
msg_ok "Customized LXC Container" msg_ok "Customized LXC Container"

View File

@@ -1211,36 +1211,30 @@ EOF
;; ;;
sysvinit) sysvinit)
# Devuan/older systems - modify inittab for auto-login # Devuan/older SysVinit systems: modify inittab for auto-login on tty1 + console
# Devuan 5 (daedalus) uses SysVinit with various inittab formats
# LXC can use /dev/console OR /dev/tty1 depending on how pct console connects
if [[ -f /etc/inittab ]]; then if [[ -f /etc/inittab ]]; then
# Backup original inittab
cp /etc/inittab /etc/inittab.bak 2>/dev/null || true cp /etc/inittab /etc/inittab.bak 2>/dev/null || true
# Enable autologin on tty1 (for direct access) - handle various formats # Replace the tty1 getty line with an autologin version.
# Devuan uses format: 1:2345:respawn:/sbin/getty 38400 tty1 # Devuan 5 ships: 1:2345:respawn:/sbin/agetty --noclear tty1 38400 linux
sed -i 's|^\(1:[0-9]*:respawn:\).*getty.*tty1.*|1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 38400 linux|' /etc/inittab 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! # Add/replace console entry (pct console maps to /dev/console in some configs)
# Remove any existing console entries first (commented or not) sed -i '/^[^#]*:.*:respawn:.*[ag]etty.*console/d' /etc/inittab
sed -i '/^[^#]*:.*:respawn:.*getty.*console/d' /etc/inittab
sed -i '/^# LXC console autologin/d' /etc/inittab sed -i '/^# LXC console autologin/d' /etc/inittab
cat >>/etc/inittab <<'EOF'
# Add new console entry for LXC at the end # LXC console autologin (added by community-scripts)
echo "" >>/etc/inittab co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux
echo "# LXC console autologin (added by community-scripts)" >>/etc/inittab EOF
echo "co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux" >>/etc/inittab
# Force a reload of inittab and respawn ALL getty processes # IMPORTANT: signal init to load the new inittab into memory FIRST,
# Kill ALL getty processes to force respawn with new autologin settings # then kill the running getty — init will respawn it using the new config.
pkill -9 -f '[ag]etty' &>/dev/null || true # (Killing first causes init to respawn with the OLD in-memory config.)
# Small delay to let init notice the dead processes
sleep 1
# Reload inittab - try multiple methods
telinit q &>/dev/null || init q &>/dev/null || kill -HUP 1 &>/dev/null || true 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 fi
touch /root/.hushlogin touch /root/.hushlogin
;; ;;