dataset/seed/base-machine/manual/install/install_machine

68 lines
2.1 KiB
Text
Raw Permalink Normal View History

2022-05-04 10:29:03 +02:00
#!/bin/bash -e
2022-03-08 19:42:28 +01:00
HOST_NAME=$1
IMAGE_NAME=$2
MACHINE=$3
2022-10-01 19:29:50 +02:00
exit 0
2022-03-08 19:42:28 +01:00
. config.sh
. config_machine.sh
if [ -z "$MACHINE" ]; then
echo "usage: $0 name pkg dns_name"
exit 1
fi
if [ ! -f "$MACHINE_NAME_NSPAWN_LOCAL" ]; then
echo "PAS DE CONFIG NSPAWN $MACHINE_NAME_NSPAWN_LOCAL"
exit 0
fi
if [ ! -f "$IMAGE_NAME_RISOTTO_IMAGE_NAME" ]; then
echo "PAS D'IMAGE $IMAGE_NAME_RISOTTO_IMAGE_NAME"
exit 1
fi
2022-04-28 21:48:16 +02:00
NEW_IMAGE=false
NEW_CONF=false
2022-03-08 19:42:28 +01:00
if [ -L "$MACHINE_MACHINES_DIR" ] || [ -d "$MACHINE_MACHINES_DIR" ]; then
2022-04-28 21:48:16 +02:00
# is the base image divergent?
diff -q "$IMAGE_NAME_RISOTTO_IMAGE_NAME".sha "$SHA_MACHINE" || NEW_IMAGE=true
# is the configuration divergent?
diff -q --no-dereference -Nru "$MACHINE_RISOTTO_CONFIG_DIR" "$MACHINE_RISOTTO_CONFIG_DIR_LOCAL" || NEW_CONF=true
fi
if [ "$NEW_IMAGE" = true ] || [ "$NEW_CONF" = true ]; then
2022-05-04 10:29:03 +02:00
echo " - stop $IMAGE_NAME"
2022-03-08 19:42:28 +01:00
machinectl stop "$MACHINE" 2> /dev/null || true
while true; do
machinectl status "$MACHINE" > /dev/null 2>&1 || break
sleep 1
done
fi
2022-04-28 21:48:16 +02:00
if [ "$NEW_IMAGE" = true ]; then
2022-05-04 10:29:03 +02:00
echo " - delete old image"
2022-04-28 21:48:16 +02:00
rm -rf "$MACHINE_MACHINES_DIR"
fi
if [ "$NEW_CONF" = true ]; then
2022-05-04 10:29:03 +02:00
echo " - delete old settings"
2022-04-28 21:48:16 +02:00
./diff.py "$MACHINE" "$MACHINE_RISOTTO_CONFIG_DIR" "$MACHINE_RISOTTO_CONFIG_DIR_LOCAL" > "$MACHINE_RISOTTO_CONFIG_DIR"_changelog.md
2022-10-01 19:29:50 +02:00
# rm -rf "$MACHINE_RISOTTO_CONFIG_DIR"
2022-03-08 19:42:28 +01:00
fi
2022-10-01 19:29:50 +02:00
#cp -a "$MACHINE_NAME_NSPAWN_LOCAL" "$MACHINE_NAME_NSPAWN"
#cp -a "$MACHINE_NAME_SCRIPT_LOCAL" "$MACHINE_NAME_SCRIPT"
#if [ ! -d "$MACHINE_RISOTTO_CONFIG_DIR" ]; then
# cp -a "$MACHINE_RISOTTO_CONFIG_DIR_LOCAL" "$MACHINE_RISOTTO_CONFIG_DIR"
#fi
#if [ ! -d "$MACHINE_RISOTTO_SRV_DIR" ] && [ -d "$MACHINE_RISOTTO_SRV_DIR_LOCAL" ]; then
# mkdir -p "$MACHINE_RISOTTO_SRV_DIR"
#fi
#mkdir -p "$RISOTTO_JOURNALD_DIR"
2022-03-08 19:42:28 +01:00
if [ ! -d "$MACHINE_MACHINES_DIR" ]; then
cd "$MACHINES_DIR"
2022-10-01 19:29:50 +02:00
mkdir "$IMAGE_NAME"
cd "$IMAGE_NAME"
2022-03-08 19:42:28 +01:00
tar xf "$IMAGE_NAME_RISOTTO_IMAGE_NAME"
mkdir -p "$SHA_MACHINE_DIR"
cp -a "$IMAGE_NAME_RISOTTO_IMAGE_NAME".sha "$SHA_MACHINE"
2022-05-04 10:29:03 +02:00
cd - > /dev/null
2022-03-08 19:42:28 +01:00
fi
2022-05-04 10:29:03 +02:00
echo " => OK"
2022-03-08 19:42:28 +01:00
exit 0