-#!/bin/sh -e
-
-# call rsnapshot daily/weekly/monthly regularly
-# this should be called from cron very often (several times a day) to not miss
-# a cycle when the machine is powered down for extended times.
-#
-# Author: Martin Pitt <martin@piware.de>
-# License: Public Domain
-
-backupdir=`grep ^snapshot_root ~/.rsnapshotrc | awk '{print $2}'`
-
-now=`date +%s`
-
-get_age() {
- if [ -e $backupdir/$1 ]; then
- age=$(($now - `stat -c %Y $backupdir/$1`))
- else
- unset age
+#!/bin/sh
+set -eu
+cd $HOME
+LOG=.cache/duplicity/log
+PATH=$PATH:/sbin:/usr/sbin
+
+# do backup every day
+if [ -e "$LOG" ] && [ $(( `date +%s` - `stat -c %Y $LOG` )) -lt 86300 ]; then
+ exit 0
+fi
+
+# figure out $DISPLAY when running from cron
+export DISPLAY="${DISPLAY:-:0}"
+
+if ! ip route | grep -q '^default.*wl'; then
+ notify-send "Backup skipped, not on WLAN"
+ exit 0
+fi
+
+# figure out ssh agent when running from cron
+if [ -z "${SSH_AUTH_SOCK:-}" ]; then
+ ssh_socket=$(ls /run/user/`id -u`/keyring*/ssh 2>/dev/null)
+ if [ -S "$ssh_socket" ]; then
+ export SSH_AUTH_SOCK="$ssh_socket"