diff options
author | Dennis Eriksen <d@ennis.no> | 2020-04-28 08:37:25 +0200 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2020-04-28 08:37:25 +0200 |
commit | 36a53f61c12e874f6052e141a22dc5fc7e5b08f4 (patch) | |
tree | 76b2c4a3bafa35e4d25eb47dac8f12df490769b3 | |
parent | show all backups and sizes when run manually (diff) | |
download | mkosibuild-36a53f61c12e874f6052e141a22dc5fc7e5b08f4.tar.gz |
add symlink to nspawn-dir, and other small fixes
-rwxr-xr-x | mkosibuild | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -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" |