aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmkosibuild21
1 files changed, 12 insertions, 9 deletions
diff --git a/mkosibuild b/mkosibuild
index ec12449..8c85fd7 100755
--- a/mkosibuild
+++ b/mkosibuild
@@ -11,7 +11,7 @@ set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
-
+# Set backupdir if not set
: "${BACKUPDIR:=/var/lib/machines/.backup}"
function die {
@@ -29,25 +29,28 @@ function main {
cd /srv/mkosi/"${NAME}"
/bin/mkosi -o "/var/lib/machines/${NAME}.new"
- # Stop machine if it is running
- if /bin/machinectl status "${NAME}" >/dev/null; then
- /bin/machinectl stop "${NAME}"
- local START=true
- fi
-
cd /var/lib/machines
+ # If machine exists
if [[ -e "${NAME}" ]]; then
+
+ # Stop machine if it is running
+ if /bin/machinectl status "${NAME}" &> /dev/null; then
+ /bin/machinectl stop "${NAME}"
+ local START=true
+ fi
+
mv "${NAME}" "${BACKUPDIR}/"
rm -f "${NAME}.nspawn"
fi
mv "${NAME}.new" "${NAME}"
mv "${NAME}.new.nspawn" "${NAME}.nspawn"
+ ln -s -f "/var/lib/machines/${NAME}.nspawn" "/etc/systemd/nspawn/${NAME}.nspawn"
echo "Done building."
echo ""
sleep 1
# Start machine if it was running before
- if [[ ${START:=false} = true ]]; then
+ if [[ "${START:=false}" = true ]]; then
echo "Starting"
/bin/machinectl start "${NAME}"
sleep 2
@@ -56,7 +59,7 @@ function main {
# Backup old machine
[[ -d "${BACKUPDIR}" ]] || mkdir -p "${BACKUPDIR}"
- if [[ -e ".backup/${NAME}" ]]; then
+ if [[ -e "${BACKUPDIR}/${NAME}" ]]; then
TS="$(date +%Y%m%d%H%M%S)"
echo ""
echo "Now zipping up the old machine, for backup"