aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2020-04-28 08:37:25 +0200
committerDennis Eriksen <d@ennis.no>2020-04-28 08:37:25 +0200
commit36a53f61c12e874f6052e141a22dc5fc7e5b08f4 (patch)
tree76b2c4a3bafa35e4d25eb47dac8f12df490769b3
parentshow all backups and sizes when run manually (diff)
downloadmkosibuild-36a53f61c12e874f6052e141a22dc5fc7e5b08f4.tar.gz
add symlink to nspawn-dir, and other small fixes
-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"