48 lines
1.5 KiB
Bash
Executable file
48 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env zsh
|
|
|
|
# author: Daniel Sommer <daniel.sommer@velvettear.de>
|
|
# license: MIT
|
|
|
|
# exit on error
|
|
set -e
|
|
|
|
# check permissions
|
|
[[ "$EUID" != 0 ]] && printf "error: permission denied!\n" >&2 && exit 1
|
|
|
|
# check which action to execute
|
|
[[ -n "$1" ]] && action="$1" || action="backup"
|
|
|
|
# check if script exists
|
|
script="$(dirname $(realpath "$0"))/$action.sh"
|
|
[[ ! -x "$script" ]] && printf "error: script '"$script"' does not exist or is not executable!\n" >&2 && exit 1
|
|
|
|
# get the "home" directory
|
|
home="$(dirname $(realpath "$0"))"
|
|
|
|
# setup restic
|
|
export RESTIC_USER="$(whoami)"
|
|
export RESTIC_REPOSITORY="rest:http://192.168.100.101:8000"
|
|
export RESTIC_PASSWORD="\$Velvet90"
|
|
export RESTIC_COMPRESSION="auto"
|
|
export RESTIC_CACHE_DIR="/var/cache/restic"
|
|
export RESTIC_LOG="/var/log/restic-$action.log"
|
|
|
|
# check if .env file exists and source it
|
|
env="$home/$(hostname).env"
|
|
[[ -r "$env" ]] && source "$env"
|
|
|
|
# set default values for the notification if undefined
|
|
[[ -z "$RESTIC_NTFY_TITLE" ]] && RESTIC_NTFY_TITLE="$(hostname)"
|
|
[[ -z "$RESTIC_NTFY_ICON" ]] && RESTIC_NTFY_ICON="white_circle"
|
|
|
|
# execute "pre" action if defined
|
|
[[ -n "$RESTIC_ACTION_PRE" ]] && eval "$RESTIC_ACTION_PRE"
|
|
|
|
# source / execute restic script
|
|
source "$script" > >(tee "$RESTIC_LOG") 2>&1
|
|
|
|
# execute "post" action if defined
|
|
[[ -n "$RESTIC_ACTION_POST" ]] && eval "$RESTIC_ACTION_POST"
|
|
|
|
# send a notification
|
|
/etc/velvettear/scripts/notify.sh "restic" "$RESTIC_LOG" --title "$RESTIC_NTFY_TITLE" --icon "$RESTIC_NTFY_ICON" > /dev/null
|