#!/usr/bin/env bash set -euo pipefail umask 077 ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) config=${1:-"$ROOT/tmp/production-operations/backup.env"} unit_dir=${SYSTEMD_USER_UNIT_DIR:-"$HOME/.config/systemd/user"} if [[ "$config" != /* ]]; then config="$ROOT/$config" fi if [[ ! -f "$config" || "$(stat -c '%a' "$config")" != 600 ]]; then echo "The backup configuration must exist with mode 0600: $config" >&2 exit 2 fi # shellcheck source=/dev/null source "$config" : "${BACKUP_ON_CALENDAR:?Set BACKUP_ON_CALENDAR}" case "$BACKUP_ON_CALENDAR" in *$'\n'* | *$'\r'*) echo "BACKUP_ON_CALENDAR must be one line." >&2; exit 2 ;; esac monitor_target=${MONITOR_SSH_TARGET:-buyvm-maya} remote_monitor=${MONITOR_REMOTE_ROOT:-/home/simple/.local/lib/who-need-help}/production-external-monitor.py remote_config=${MONITOR_REMOTE_CONFIG:-/home/simple/.config/who-need-help/monitor.json} ssh_path=$(command -v ssh) mkdir -p "$unit_dir" chmod 700 "$HOME/.config" "$HOME/.config/systemd" "$unit_dir" cat >"$unit_dir/who-need-help-production-backup.service" <"$unit_dir/who-need-help-production-backup-alert.service" <"$unit_dir/who-need-help-production-backup.timer" <