aboutsummaryrefslogtreecommitdiffstats
path: root/mkosibuild-cron
diff options
context:
space:
mode:
Diffstat (limited to 'mkosibuild-cron')
-rwxr-xr-xmkosibuild-cron44
1 files changed, 44 insertions, 0 deletions
diff --git a/mkosibuild-cron b/mkosibuild-cron
new file mode 100755
index 0000000..8b45a1a
--- /dev/null
+++ b/mkosibuild-cron
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+#
+# made by Dennis Eriksen <dnns.no> in 2020.
+
+# Exit on error. Append "|| true" if you expect an error.
+set -o errexit
+# Exit on error inside any functions or subshells.
+set -o errtrace
+# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
+set -o nounset
+# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
+set -o pipefail
+
+
+LOGDIR=/var/log/mkosibuild/
+BACKUPDIR=/var/lib/machines/.backup
+BACKUPNUM=5
+EXEC=mkosibuild # This provides the exec is in your $PATH
+CRONSUFFIX="-cron" # Suffix for backups made through cron
+
+export CRON=true
+export CRONSUFFIX
+
+MACHINES=()
+
+# Import config to override above config
+[[ -r /etc/mkosibuild ]] && . /etc/mkosibuild
+
+# Check if logdir exists, and create it if not
+[[ -d "${LOGDIR}" ]] || mkdir "${LOGDIR}"
+
+for machine in ${MACHINES[*]}; do
+ LOG="${LOGDIR}/${machine}.log"
+ BUILDLOG="${LOGDIR}/${machine}.buildlog.$(date +%Y%m%d%H%M%S)"
+ touch "${LOG}" && chmod 600 "${LOG}"
+ #exec >> "${LOG}"
+ echo "" >> "${LOG}"
+ echo "Starting build $(date +%Y-%m-%d_%H:%M:%S)" >> "${LOG}"
+ ${EXEC} "$machine" &>> "${BUILDLOG}"
+
+ # Delete old backups
+ find "${BACKUPDIR}" -name "${machine}.*${CRONSUFFIX}" | tail -n +$((BACKUPNUM + 1)) | xargs rm -fv -- >> "${LOG}"
+
+done