dotfiles.git

commit 3daa938dcbc2cc8e6b009ec40cef0bfe88dab2bd

Author: Adam Evyčędo <git@apiote.xyz>

pass and backup daily run on start when network is up

 .local/bin/network_backup | 55 +++++++++++++++++++++++++++++++++++++++++


diff --git a/.local/bin/network_backup b/.local/bin/network_backup
new file mode 100755
index 0000000000000000000000000000000000000000..9ed70d3c4bfb6878f89dcbbf53f36693a2d30650
--- /dev/null
+++ b/.local/bin/network_backup
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+connected() {
+  if connmanctl services | grep -qE '(O|R) '
+  then
+    return 0
+  else
+    return 1
+  fi
+}
+
+shouldBackupNow() {
+  if [ ! -f ~/.cache/lastBackup ]
+  then
+    return 0
+  fi
+
+  now=$(date '%+s')
+  then=$(cat ~/.cache/lastBackup)
+
+  test $((now - then)) -gt 86400
+}
+
+shouldPassNow() {
+  cd ~/Code/current/joeblack || return 1
+  passLastDate=$(git log --date=unix | grep Date | tr -s ' ' |cut -d ' ' -f2- | head -n1)
+  cd ~/.local/share/eeze || return 1
+  eezeLastDate=$(git log --date=unix | grep Date | tr -s ' ' |cut -d ' ' -f2- | head -n1)
+  test "$passLastDate" -lt "$eezeLastDate"
+}
+
+if connected
+then
+  shouldPassNow && notify-send -i backup -u critical 'JoeBlack should be run' 'There are changes to passwords since last JoeBlack sync'
+  shouldBackupNow && (
+    notify-send -i backup 'Running daily backup'
+    backup daily
+    notify-send -i backup 'Finished daily backup'
+    date '%+s' >~/.cache/lastBackup
+  )
+fi
+
+
+ip monitor address | while read -r _
+do
+  if connected
+  then
+    shouldPassNow && notify-send -i backup -u critical 'JoeBlack should be run' 'There are changes to passwords since last JoeBlack sync'
+    shouldBackupNow && (
+      notify-send -i backup 'Running daily backup'
+      backup daily
+      notify-send -i backup 'Finished daily backup'
+    )
+  fi
+done