aboutsummaryrefslogtreecommitdiff
path: root/stow/waybar/.local/bin/checkbackup
blob: 24393d1cc827b7d819e4f78f0839237e854f04ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

set -euo pipefail

if command -v systemctl > /dev/null; then
    SYSTEMCTLCMD="systemctl"
fi
if command -v jq > /dev/null; then
    JQCMD="jq"
fi
if [ -z "${SYSTEMCTLCMD+x}" ] || [ -z "${JQCMD+x}" ]; then
    echo "{\"tooltip\": \"requires 'jq' and 'systemctl'\", \"text\": \"\"}"
    exit 1
fi

backup_metadata_file=/var/cache/borgbackup/last.txt

if [ ! -f "$backup_metadata_file" ]; then
    echo "{\"tooltip\": \"backup metadata missing\", \"text\": \"\"}"
    exit 1
fi

now_ts="$(date +%s)"
last_backup_ts="$(stat -c %Y "$backup_metadata_file")"

icon=""
class=""
output="$(cat "$backup_metadata_file")"
if [ $(( now_ts - last_backup_ts)) -gt $(( 25 * 60 * 60 )) ]; then
  class="script-error"
fi
# this is a literal expression for `jq`
# shellcheck disable=SC2016
$JQCMD --unbuffered -n -c '{tooltip: $ARGS.positional[0], text: $ARGS.positional[1], class: $ARGS.positional[2]}' --args "$output" "$icon" "$class"