diff --git a/examples/reboot/firstboot.sh b/examples/reboot/firstboot.sh new file mode 100644 index 0000000..d8d799a --- /dev/null +++ b/examples/reboot/firstboot.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +LOGFILE="/boot/firstboot.log" + +# Log everything: https://serverfault.com/a/103569/662521 +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>${LOGFILE} 2>&1 + +# update APT packages +export DEBIAN_FRONTEND=noninteractive +apt-get update -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false +apt-get install -y upgrade + +# set timezone and update time +timedatectl set-timezone UTC +ntpdate ntp.ubuntu.com + +# Reboot delayed, so that we can exit with success to complete firstboot.service +systemd-run --no-block sh -c "sleep 3 && touch /boot/reboot && reboot" + +echo "Done firstboot, exit, but reboot in 3 seconds" +exit 0 + +# check /boot/reboot and /boot/firstboot.log