checking preinit hooks return value, fixing ethernet-dhcp hook for interfaces that are not eth0

This commit is contained in:
Andreas Grapentin 2019-03-17 20:59:59 +01:00
parent bc7a570477
commit 1c59af21a6
No known key found for this signature in database
GPG Key ID: 7171986E4B745536
3 changed files with 36 additions and 7 deletions

@ -3,11 +3,15 @@
set -e
# setup systemd-resolved
systemctl start systemd-resolved.service
systemctl start systemd-resolved.service || return
systemctl enable systemd-resolved.service
ln -sf /var/run/systemd/resolve/resolv.conf /etc/resolv.conf
# determine first ethernet device
eth="$(basename "$(find /sys/class/net/ -mindepth 1 -maxdepth 1 -iname 'e*' | head -n1)")"
[ -n "$eth" ] || eth="eth0"
# setup netctl for ethernet-dhcp
cp /etc/netctl/examples/ethernet-dhcp /etc/netctl/
netctl start ethernet-dhcp
sed "s/eth0/$eth/" /etc/netctl/examples/ethernet-dhcp > /etc/netctl/ethernet-dhcp
netctl start ethernet-dhcp || return
netctl enable ethernet-dhcp

@ -193,6 +193,9 @@ main() {
qemu_args+=("$@")
(set -x; qemu-system-"$arch" "${qemu_args[@]}")
# clean up the terminal, in case SeaBIOS did something weird
echo -n "[?7h"
pvm_umount
}

@ -193,9 +193,17 @@ EOF
# install a boot loader
case "$arch" in
i686|x86_64)
# install grub to the VM
sudo sed -i 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0"/' \
# enable serial console
local field=GRUB_CMDLINE_LINUX_DEFAULT
local value="console=tty0 console=ttyS0"
sudo sed -i "s/.*$field=.*/$field=\"$value\"/" \
"$workdir"/etc/default/grub || return
# disable boot menu timeout
local field=GRUB_TIMEOUT
local value=0
sudo sed -i "s/.*$field=.*/$field=$value/" \
"$workdir"/etc/default/grub || return
# install grub to the VM
sudo arch-chroot "$workdir" grub-install --target=i386-pc "$loopdev" || return
sudo arch-chroot "$workdir" grub-mkconfig -o /boot/grub/grub.cfg || return
;;
@ -248,6 +256,8 @@ done
rm -rf /root/hooks
rm -f /root/hooks.sh
rm -f /usr/lib/systemd/system/preinit.service
echo "preinit hooks successful"
EOF
# create a preinit service to run the hooks
@ -275,14 +285,26 @@ EOF
# boot the machine, and run the preinit scripts
local qemu_flags=(-no-reboot)
local pvmboot
if [ -f "./src/pvmboot.sh" ]; then
DISPLAY='' bash ./src/pvmboot.sh "$file" "${qemu_flags[@]}" || return
pvmboot=(bash ./src/pvmboot.sh)
elif type -p pvmboot &>/dev/null; then
DISPLAY='' pvmboot "$file" "${qemu_flags[@]}" || return
pvmboot=(pvmboot)
else
error "%s: pvmboot not available -- unable to run hooks" "$file"
return "$EXIT_FAILURE"
fi
exec 3>&1
DISPLAY='' "${pvmboot[@]}" "$file" "${qemu_flags[@]}" \
| tee /dev/fd/3 | grep -q "preinit hooks successful"
local res=$?
exec 3>&-
if [ "$res" -ne 0 ]; then
error "%s: failed to complete preinit hooks" "$file"
return "$res"
fi
}
pvm_cleanup() {