Files
aero3/packages/chroot-systemd.sh
2026-06-19 10:02:12 -04:00

141 lines
5.4 KiB
Bash
Executable File

#!/bin/bash
# packages/chroot-systemd.sh — systemd, D-Bus, shadow, GRUB + system config.
# Runs INSIDE the chroot.
set -Eeuo pipefail
export LC_ALL=POSIX MAKEFLAGS="${MAKEFLAGS:--j4}"
SRC=/sources; STAMPS=/root/.base-stamps; mkdir -p "$STAMPS"
say(){ printf '\n\e[1;36m== %s ==\e[0m\n' "$*"; }
once(){ local n="$1"; shift; [[ -f "$STAMPS/$n" ]] && { echo "skip $n"; return; }; "$@"; touch "$STAMPS/$n"; }
find_tb(){ local m; shopt -s nocaseglob nullglob; local a=("$SRC/$1"-[0-9]*.tar.*) b=("$SRC/$1"*.tar.*) c=()
[[ "$1" == systemd ]] && c=("$SRC"/v[0-9]*.tar.*)
shopt -u nocaseglob nullglob
m="${a[0]:-${b[0]:-${c[0]:-}}}"
[[ -n "$m" ]] || { echo "MISSING SOURCE: $1" >&2; return 1; }; echo "$m"; }
unp(){ cd /tmp; rm -rf bld-"$1"; mkdir bld-"$1"; tar -xf "$(find_tb "$1")" -C bld-"$1" --strip-components=1; cd bld-"$1"; }
p_shadow(){ unp shadow
sed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \; 2>/dev/null || true
sed -e 's:#ENCRYPT_METHOD DES:ENCRYPT_METHOD YESCRYPT:' \
-e 's:/var/spool/mail:/var/mail:' -i etc/login.defs
touch /usr/bin/passwd
./configure --sysconfdir=/etc --disable-static --with-{b,yes}crypt \
--without-libbsd --with-group-name-max-length=32
make; make exec_prefix=/usr install; make -C man install-man || true
pwconv; grpconv
echo "root:${AEROS_ROOT_PASS:-root}" | chpasswd
cd /; }
p_dbus(){ unp dbus
meson setup build --prefix=/usr --libdir=lib --sysconfdir=/etc --localstatedir=/var \
-Druntime_dir=/run \
-Dsystem_pid_file=/run/dbus/pid \
-Dsystem_socket=/run/dbus/system_bus_socket \
-Dsystemd=enabled \
-Dsystemd_system_unitdir=/usr/lib/systemd/system \
-Dsystemd_user_unitdir=/usr/lib/systemd/user \
-Dmodular_tests=disabled -Dinstalled_tests=false \
-Dxml_docs=disabled -Ddoxygen_docs=disabled -Dducktype_docs=disabled -Dqt_help=disabled \
-Dselinux=disabled -Dapparmor=disabled -Dlibaudit=disabled \
-Dx11_autolaunch=disabled -Dlaunchd=disabled
ninja -C build
ninja -C build install
cd /; }
p_systemd(){ unp systemd
sed -i "s/'-Werror=override-init'/'-Wno-error=override-init'/" meson.build
cp -f /usr/include/linux/input-event-codes.h src/basic/linux/input-event-codes.h
meson setup build --prefix=/usr --libdir=lib --buildtype=release \
-Dmode=release -Dlink-udev-shared=true \
-Ddefault-dnssec=no -Dfirstboot=true -Dinstall-tests=false \
-Dldconfig=true -Dsysusers=true -Drpmmacrosdir=no \
-Dhomed=disabled -Duserdb=true -Dman=disabled \
-Dpamconfdir=no -Dnss-systemd=true \
-Ddbus=disabled -Dglib=disabled
ninja -C build
ninja -C build install
# enable getty + basic targets
systemctl preset-all 2>/dev/null || true
cd /; }
p_grub(){ unp grub
: > grub-core/extra_deps.lst
# BIOS + UEFI (x86_64-efi) targets
./configure --prefix=/usr --sysconfdir=/etc --disable-efiemu --enable-grub-mkfont=no \
--with-platform=pc --disable-werror || ./configure --prefix=/usr --sysconfdir=/etc --disable-werror
make; make install
cd /; rm -rf /tmp/bld-grub; unp grub
: > grub-core/extra_deps.lst
./configure --prefix=/usr --sysconfdir=/etc --with-platform=efi \
--target=x86_64 --program-prefix="" --disable-werror || true
make 2>/dev/null && make install 2>/dev/null || echo "grub-efi optional build skipped"
cd /; }
configure_system(){
say "Base system configuration"
# hostname
echo "${AEROS_HOSTNAME:-aeros}" > /etc/hostname
# hosts
cat > /etc/hosts <<EOF
127.0.0.1 localhost ${AEROS_HOSTNAME:-aeros}
::1 localhost ip6-localhost ip6-loopback
EOF
# os-release branding
cat > /etc/os-release <<EOF
NAME="${AEROS_NAME:-AeroOS}"
PRETTY_NAME="${AEROS_NAME:-AeroOS} ${AEROS_VERSION:-1.0} (${AEROS_CODENAME:-Frutiger})"
ID=${AEROS_DISTRO_ID:-aeros}
VERSION_ID=${AEROS_VERSION:-1.0}
VERSION_CODENAME=${AEROS_CODENAME:-frutiger}
HOME_URL="https://aeros.example"
ANSI_COLOR="1;36"
EOF
cat > /etc/lsb-release <<EOF
DISTRIB_ID=${AEROS_DISTRO_ID:-aeros}
DISTRIB_RELEASE=${AEROS_VERSION:-1.0}
DISTRIB_CODENAME=${AEROS_CODENAME:-Frutiger}
DISTRIB_DESCRIPTION="${AEROS_NAME:-AeroOS}"
EOF
# locale
cat > /etc/locale.conf <<EOF
LANG=${AEROS_LOCALE:-en_US.UTF-8}
EOF
# vconsole / time
echo "KEYMAP=${AEROS_KEYMAP:-us}" > /etc/vconsole.conf
ln -sfv "/usr/share/zoneinfo/${AEROS_TIMEZONE:-UTC}" /etc/localtime
# fstab (live image overlays root; this is for installed systems)
cat > /etc/fstab <<EOF
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sda2 / ext4 defaults,noatime 0 1
/dev/sda1 /boot/efi vfat umask=0077 0 2
tmpfs /tmp tmpfs nosuid,nodev 0 0
EOF
# default target = graphical (lands on the Aero home screen)
systemctl set-default graphical.target 2>/dev/null || \
ln -sfv /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target
# enable networking + resolved
systemctl enable systemd-networkd systemd-resolved 2>/dev/null || true
ln -sfv /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf 2>/dev/null || true
cat > /etc/systemd/network/20-wired.network <<EOF
[Match]
Name=en* eth*
[Network]
DHCP=yes
EOF
# ld cache
cat > /etc/ld.so.conf <<EOF
/usr/local/lib
/usr/lib
/usr/lib64
EOF
ldconfig || true
}
say "AeroOS init + boot layer"
once s-shadow p_shadow
once s-systemd p_systemd
once s-dbus p_dbus
once s-grub p_grub
once s-config configure_system
echo "systemd/boot layer complete."