diff --git a/arch-desktop_borg.sh b/arch-desktop_borg.sh index b8e91c5..a00d03e 100755 --- a/arch-desktop_borg.sh +++ b/arch-desktop_borg.sh @@ -1,16 +1,40 @@ #!/bin/sh -# We only want this file to be executed at most once per day, so we stat a cache -# file before running the rest of the code -cache_file='/home/flyingscorpio/.cache/borg_backup_hook_last_executed' -if [ -f "$cache_file" ]; then - cache_stat=$(stat -c %y "$cache_file" | cut -d' ' -f1) - today=$(date +%Y-%m-%d) - if [ "$cache_stat" = "$today" ]; then - echo "The borg backup was already executed today" && exit 0 +### +### arch-desktop_borg.sh +### +### Usage: +### "$0" [-f] +### +### Options: +### -f Force an update, even if one was already made today. +### -h Print this help message and quit. +### + + +print_help() { + awk -F'### ' '/^###/ { print $2 }' "$0" +} + +stat_cache_file() { + # We only want this file to be executed at most once per day, so we stat a cache + # file before running the rest of the code + cache_file='/home/flyingscorpio/.cache/borg_backup_hook_last_executed' + if [ -f "$cache_file" ]; then + cache_stat=$(stat -c %y "$cache_file" | cut -d' ' -f1) + today=$(date +%Y-%m-%d) + if [ "$cache_stat" = "$today" ]; then + echo "The borg backup was already executed today" && exit 0 + fi fi + touch "$cache_file" +} + +if [ "$1" = '-h' ]; then + print_help && exit 1 fi -touch "$cache_file" + +[ "$1" = '-f' ] || stat_cache_file # Setting this so the repo does not need to be given on the command line: BORG_REPO=ssh://flyingscorpio@2px.info:22/~/"$(hostname)".borg