Files
backup/install.sh

47 lines
1.2 KiB
Bash

#!/bin/bash
baseurl="https://git.housh.dev/homelab/backup/raw/branch/main"
systemdir="/etc/systemd/system"
bindir="/usr/local/bin"
function downloadScripts() {
local script="docker-backup"
local scriptsToRemove=(
"docker-restore"
"docker-restart"
)
# set the destination of the script.
local dest="$bindir/$script"
# Remove the file if it exists.
[ -f "$dest" ] && rm -f "$dest"
# download the script to the destination.
wget "$baseurl/$script.sh" -O "$dest"
# make the script executable.
chmod +x "$dest"
for script in "${scriptsToRemove[@]}"; do
[ -f "$script" ] && rm -f "$script"
done
}
# Remove backup service file if it exists and install the service file.
[ -f "$systemdir/backup.service" ] &&
systemctl stop backup.timer &&
systemctl stop backup.service &&
rm -f "$systemdir/backup.service"
wget "$baseurl/backup.service" -O "$systemdir/backup.service"
# Only download the timer file if it doesn't exist.
[ ! -f "$systemdir/backup.timer" ] &&
wget "$baseurl/backup.timer" -O "$systemdir/backup.timer"
downloadScripts
# Start services
systemctl daemon-reload
systemctl start backup.timer
systemctl start backup.service
systemctl status backup.service