forked from stove/risotto
49 lines
1.7 KiB
Bash
Executable file
49 lines
1.7 KiB
Bash
Executable file
#!/bin/bash -e
|
|
|
|
# root dir configuration
|
|
RISOTTO_DIR="/var/lib/risotto"
|
|
RISOTTO_IMAGE_DIR="$RISOTTO_DIR/images"
|
|
# image configuration
|
|
IMAGE_BASE_RISOTTO_BASE_DIR="$RISOTTO_IMAGE_DIR/image_bases"
|
|
|
|
if [ -z "$1" ]; then
|
|
rm -f $IMAGE_BASE_RISOTTO_BASE_DIR*.build
|
|
fi
|
|
|
|
mkdir -p /var/log/risotto
|
|
|
|
ls /var/lib/risotto/images_files/ | while read image; do
|
|
if [ -d /var/lib/risotto/images_files/"$image" ]; then
|
|
echo
|
|
echo "Install image $image" | tee -a /var/log/risotto/update_images.log
|
|
/usr/local/sbin/build_image "$image" "$1" | tee -a /var/log/risotto/update_images.log || (echo "PROBLEME" | tee -a /var/log/risotto/update_images.log; true)
|
|
fi
|
|
done
|
|
|
|
MACHINES=""
|
|
for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do
|
|
nspawn_file=$(basename $nspawn)
|
|
machine=${nspawn_file%.*}
|
|
MACHINES="$MACHINES$machine "
|
|
MACHINE_MACHINES_DIR="/var/lib/machines/$machine"
|
|
IMAGE_NAME_RISOTTO_IMAGE_NAME="$(cat $RISOTTO_DIR/machines_informations/$machine.image)"
|
|
MACHINE_INFO="$RISOTTO_DIR/machines_informations/"
|
|
VERSION_MACHINE="$MACHINE_INFO/$machine.version"
|
|
diff -q "$RISOTTO_IMAGE_DIR/$IMAGE_NAME_RISOTTO_IMAGE_NAME".version "$VERSION_MACHINE" &> /dev/null || (
|
|
echo "Reinstall machine $machine"
|
|
machinectl stop $machine || true
|
|
while true; do
|
|
machinectl status "$machine" > /dev/null 2>&1 || break
|
|
sleep 1
|
|
done
|
|
rm -rf "$MACHINE_MACHINES_DIR"
|
|
mkdir "$MACHINE_MACHINES_DIR"
|
|
cp -a --reflink=auto $RISOTTO_IMAGE_DIR/$IMAGE_NAME_RISOTTO_IMAGE_NAME/* $MACHINE_MACHINES_DIR
|
|
cp -a --reflink=auto "$RISOTTO_IMAGE_DIR/$IMAGE_NAME_RISOTTO_IMAGE_NAME".version "$VERSION_MACHINE"
|
|
)
|
|
done
|
|
if [ -z "$1" ]; then
|
|
machinectl start $MACHINES
|
|
diagnose
|
|
fi
|
|
exit 0
|