From 1502743b544feb5fea706c5d09bd496e8f569ccb Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Tue, 8 Sep 2020 14:36:27 +0200 Subject: [PATCH] Add args to borg script --- arch-desktop_borg.sh | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) 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