diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2023-08-17 10:05:39 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2023-08-17 21:22:58 -0400 |
commit | 890b6c00263a242c33e155354320b1218a0bf036 (patch) | |
tree | 93a25bbd807690cf47b387613b2f97f8dc92dc98 | |
parent | 32078c3bfac9cb7d46dafb814a385efbd993da3e (diff) |
WIP - nonsystemd hookswip-nonsystemd
-rw-r--r-- | src/hooks/hook-ethernet-dhcp.sh | 18 | ||||
-rwxr-xr-x | src/pvmbootstrap.sh | 46 |
2 files changed, 48 insertions, 16 deletions
diff --git a/src/hooks/hook-ethernet-dhcp.sh b/src/hooks/hook-ethernet-dhcp.sh index 65e64f1..0085099 100644 --- a/src/hooks/hook-ethernet-dhcp.sh +++ b/src/hooks/hook-ethernet-dhcp.sh @@ -2,21 +2,29 @@ set -e +# determine init-system +IsNonsystemd=$(grep -E 'VARIANT_ID=.*-openrc"?$' /etc/os-release ; echo $((! $?)) ;) + # determine first ethernet device eth="$(basename "$(find /sys/class/net/ -mindepth 1 -maxdepth 1 -iname 'e*' | head -n1)")" [ -n "$eth" ] || eth="eth0" # create a network configuration -cat > /etc/systemd/network/$eth.network << EOF +if (( IsNonsystemd )) +then echo "WARNING: non-systemd networking auto-setup NYI" # TODO: +else cat > /etc/systemd/network/$eth.network << EOF [Match] Name=$eth [Network] DHCP=yes EOF +fi # enable said network configuration -systemctl enable --now systemd-networkd.service -systemctl enable --now systemd-resolved.service - -ln -sf /var/run/systemd/resolve/resolv.conf /etc/resolv.conf +if (( IsNonsystemd )) +then echo "WARNING: non-systemd networking auto-setup NYI" # TODO: +else systemctl enable --now systemd-networkd.service + systemctl enable --now systemd-resolved.service + ln -sf /var/run/systemd/resolve/resolv.conf /etc/resolv.conf +fi diff --git a/src/pvmbootstrap.sh b/src/pvmbootstrap.sh index 8ca2ad8..a4c8ead 100755 --- a/src/pvmbootstrap.sh +++ b/src/pvmbootstrap.sh @@ -49,6 +49,7 @@ readonly REPOS_STANDARD=( libre core extra ) readonly REPOS_NONSYSTEMD=( nonsystemd ) readonly CACHE_DIR=/var/cache/pacman/pkg # in-chroot readonly PVM_HOOKS_SUCCESS_MSG="[hooks.sh] pre-init hooks successful" +readonly PVM_HOOKS_FAIL_MSG="[hooks.sh] pre-init hooks failed" # options (over-ride defaults per CLI args) @@ -342,13 +343,14 @@ locale-gen for kernel in ${Kernels[*]} ; do mkinitcpio -p \$kernel ; done ; # fix ca-certificates +declare -i was_err=0 certs_pkg=\$(ls ${CACHE_DIR}/ca-certificates-utils-*.pkg.tar.zst) if [[ -f \$certs_pkg ]] then pacman -U --noconfirm \$certs_pkg || ! echo "[hooks.sh] ERROR: 'ca-certificates-utils' install failed" || - exit "$EXIT_FAILURE" + was_err=1 else echo "[hooks.sh] ERROR: could not find 'ca-certificates-utils' package" - exit "$EXIT_FAILURE" + was_err=1 fi # run the hooks @@ -361,22 +363,42 @@ done shopt -u nullglob # clean up after yourself -systemctl disable pre-init.service -#rm -f /etc/init.d/pre-init # TODO: non-systemd hooks NYI +if (( IsNonsystemd )) +then rc-update delete pre-init default ; rm -f /etc/init.d/pre-init ; +else systemctl disable pre-init.service ; rm -f /usr/lib/systemd/system/pre-init.service ; +fi rm -f /root/.bash_history rm -rf /root/hooks rm -f /root/hooks.sh # this file -rm -f /usr/lib/systemd/system/pre-init.service rm -f $CACHE_DIR/* -# report success :) -echo "$PVM_HOOKS_SUCCESS_MSG - powering off" +# report :) +(( was_err )) && echo -n "$PVM_HOOKS_FAIL_MSG" || echo -n "$PVM_HOOKS_SUCCESS_MSG" +echo " - powering off" + +exit 0 EOF # create a pre-init service to run the hooks msg2 "pre-init.service:" if (( IsNonsystemd )) - then ; + then sudo tee "$workdir"/etc/init.d/pre-init << 'EOF' +#!/usr/bin/openrc-run + +name="$RC_SVCNAME" +description="Oneshot VM Pre-init" +command="/usr/bin/bash" +command_args="/root/hooks.sh" + +depend() { + after logger +} + +stop() { + shutdown -r now +} +EOF + chmod +x "$workdir"/etc/init.d/pre-init else sudo tee "$workdir"/usr/lib/systemd/system/pre-init.service << 'EOF' [Unit] Description=Oneshot VM Pre-init @@ -397,7 +419,10 @@ EOF # configure services msg "configuring services" if (( IsNonsystemd )) - then ; + then # enable the entropy daemon, to avoid stalling https + sudo arch-chroot "$workdir" rc-update add haveged default + # enable the pre-init service + sudo arch-chroot "$workdir" rc-update add pre-init default || return "$EXIT_FAILURE" else # disable audit sudo arch-chroot "$workdir" systemctl mask systemd-journald-audit.socket # enable the entropy daemon, to avoid stalling https @@ -462,7 +487,7 @@ main() # ( [cli_options] imagefile arch ) H) Hooks+=( "$(pvm_get_hook $OPTARG)" ) ;; k) Kernels+=($OPTARG) ;; M) Mirror="$OPTARG" ;; - O) IsNonsystemd=0 ;; # TODO: non-systemd hooks NYI + O) IsNonsystemd=0 ;; # TODO: non-systemd networking NYI p) PkgsOptional+=($OPTARG) ;; s) RootSizeMb="$(sed 's|[^0-9]||g' <<<$OPTARG)" ;; S) SwapSizeMb="$(sed 's|[^0-9]||g' <<<$OPTARG)" ;; @@ -513,7 +538,6 @@ main() # ( [cli_options] imagefile arch ) armv7h) pkgs+=( archlinuxarm-keyring ) ;; i686 ) pkgs+=( archlinux32-keyring ) ;; esac - (( IsNonsystemd )) && Hooks=( ${Hooks[*]/*ethernet-dhcp*/} ) # TODO: non-systemd hooks NYI (( IsNonsystemd )) && pkgs+=( ${PKGS_NONSYSTEMD[*]} ) [[ "${Hooks[@]}" =~ ethernet-dhcp ]] && pkgs+=( ${PKGS_NETWORKING[*]} ) |