Truly support custom PREFIX= install

* Before, doing `$ PREFIX=/usr/local make install` would install files to`/usr/local/usr/local..` which is wrong
* With this PR, files will be installed to the expected location e.g. `/usr/local/etc/restic`
* `Makefile` almost completely rewritten
   * As e.g. `default.env` would source `_global.env`, `default.env` must be edited to find the right location of `_global.env` depending on what `$PREFIX` was set to.
   * see documented build stages in the `Makefile` itself.
   *  Made sure that the rules are correct so that only modifed files are installed, not all at once unnecessarily like before.
* A sub-goal was that the [PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=restic-systemd-automatic-backup#n20) for Arch should not need to do any custom install configuration, to keep everything easier to maintain. `$ make install` should work out of the box for Arch.
* Additionally added the `-b` flag to `install(1)` that makes a backup of existing `etc/restic/*` files before installing a newer version.

Fixes #49
This commit is contained in:
Erik Westrup
2022-01-18 20:22:54 +01:00
parent 3852e305b6
commit 9760cd05ec
20 changed files with 158 additions and 60 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:/usr/local/sbin/
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/sbin/
# Order of crontab fields
# minute hour mday month wday command
# Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html
@@ -8,9 +8,9 @@
# The restic repository encryption key
export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt"
export RESTIC_PASSWORD_FILE="$INSTALL_PREFIX/etc/restic/pw.txt"
# The global restic exclude file
export RESTIC_BACKUP_EXCLUDE_FILE="/etc/restic/backup_exclude.txt"
export RESTIC_BACKUP_EXCLUDE_FILE="$INSTALL_PREFIX/etc/restic/backup_exclude.txt"
# Backblaze B2 credentials keyID & applicationKey pair.
# Restic environment variables are documented at https://restic.readthedocs.io/en/latest/040_backup.html#environment-variables
@@ -9,7 +9,7 @@
# Thus you don't have to provide all the arguments like
# $ restic --repo ... --password-file ...
source /etc/restic/_global.env
source $INSTALL_PREFIX/etc/restic/_global.env
# Below envvar will override those in _global.env
@@ -1,7 +0,0 @@
[Unit]
Description=Check if the current NetworkManager connection is metered
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/nm-unmetered-connection.sh
-13
View File
@@ -1,13 +0,0 @@
[Unit]
Description=Backup with restic to Backblaze B2
OnFailure=status-email-user@%n.service
Requires=nm-unmetered-connection.service
[Service]
Type=simple
Nice=10
# $HOME or $XDG_CACHE_HOME must be set for restic to find /root/.cache/restic/
Environment="HOME=/root"
# The random sleep (in seconds) is in the case of multiple backup profiles. Many restic instances started at the same time could case high load or network bandwith usage.
# `systemd-cat` allows showing the restic output to the systemd journal
ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source /etc/restic/%I.env && /usr/local/sbin/restic_backup.sh | systemd-cat'
-10
View File
@@ -1,10 +0,0 @@
[Unit]
Description=Backup with restic on schedule
Requires=nm-unmetered-connection.service
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
-11
View File
@@ -1,11 +0,0 @@
[Unit]
Description=Check restic backup Backblaze B2 for errors
OnFailure=status-email-user@%n.service
Conflicts=restic-backup.service
Requires=nm-unmetered-connection.service
[Service]
Type=simple
Nice=10
# `systemd-cat` allows showing the restic output to the systemd journal
ExecStart=bash -c 'source /etc/restic/%I.env && /usr/local/sbin/restic_check.sh | systemd-cat'
-10
View File
@@ -1,10 +0,0 @@
[Unit]
Description=Check restic backup Backblaze B2 for errors on a schedule
Requires=nm-unmetered-connection.service
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=timers.target
@@ -1,11 +0,0 @@
# Source: https://serverfault.com/questions/876233/how-to-send-an-email-if-a-systemd-service-is-restarted
# Source: https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO
[Unit]
Description=Send status email for %i to user
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/systemd-email abc@gmail.com %i
User=root
Group=systemd-journal