unifios-utilities/nspawn-container/scripts/0-setup-system.sh
Micah Hausler 070ff2ade6
fix(nspawn-container): Retry 0-setup-system.sh on failure (#586)
Other system processes can acquire a dpkg frontend lock on startup that
will cause the downloaded package install to fail. The setup script
continues without exiting and machinectl is not found.

This change forces the script to exit early on error, and adds 5 retries
to the systemd unit at 30s intervals.

Signed-off-by: Micah Hausler <hausler.m@gmail.com>
2024-01-11 10:05:01 -08:00

21 lines
588 B
Bash

#!/bin/bash
# This script installs systemd-container if it's not installed.
# Also links any containers from /data/custom/machines to /var/lib/machines.
set -e
if ! dpkg -l systemd-container | grep ii >/dev/null; then
if ! apt -y install systemd-container debootstrap; then
yes | dpkg -i /data/custom/dpkg/*.deb
fi
fi
mkdir -p /var/lib/machines
for machine in $(ls /data/custom/machines/); do
if [ ! -e "/var/lib/machines/$machine" ]; then
ln -s "/data/custom/machines/$machine" "/var/lib/machines/"
machinectl enable $machine
machinectl start $machine
fi
done