commit 4a32febf299c21eab605bcdc300090ab2831b811
parent e101e422148c8fbc4d9de7d575aaaf7fcaddc9d3
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Wed, 24 Mar 2021 12:16:27 +0100

Add scripts

Diffstat:
A.local/bin/dwmblocks/dwmb-backups | 26++++++++++++++++++++++++++
A.local/bin/wallabag-to-ebook | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/.local/bin/dwmblocks/dwmb-backups b/.local/bin/dwmblocks/dwmb-backups @@ -0,0 +1,26 @@ +#!/bin/sh + +outfile="/home/oscar/.local/share/backups" + +if [ ! -f "$outfile" ]; then + lastdate="0" + lasterr="0" +else + tmp="$(cat "$outfile")" + lastdate="${tmp%% *}" + lasterr="${tmp##* }" +fi + +if [ "$(date --date="12 hours ago" +%s)" -ge "$lastdate" ]; then + echo "" + restic-daily & + exit 0 +else + if [ "$lasterr" = "0" ]; then + exit 0 + elif [ "$lasterr" = "2" ] && [ "$lastdate" -ge "$(date --date="20 mins ago" +%s)" ]; then + echo "" + else + echo "" + fi +fi diff --git a/.local/bin/wallabag-to-ebook b/.local/bin/wallabag-to-ebook @@ -0,0 +1,45 @@ +#!/bin/sh + +domain="" +phpsessid="" +rememberme="" +ebookpath="" +notify-send -u critical "Wallabag" "Script variables are not set." +exit 1 + +override_notify() { + sub="$1" + shift + notify-send -h "string:x-canonical-private-synchronous:wallabag" $@ "Wallabag" "$sub" +} + +# check if ebook exists before starting download +deviceinfo="$(lsblk | grep "1.2G")" +[ -z "$deviceinfo" ] && { override_notify "Ebook not connected." -u critical; exit 1; } +[ "$(echo "$deviceinfo" | wc -l)" != "1" ] && { override_notify "Multiple devices might be ebook, mount manually." -u critical; exit 1; } + +# download new epub file +outfile=$(mktemp) +curl -s "https://$domain/export/unread.epub" \ + -H "cookie: PHPSESSID=$phpsessid; REMEMBERME=$rememberme" \ + -o "$outfile" \ + & +pid="$!" + +override_notify "Downloading..." -t 0 + +# mount ebook and remove last entry if existent +udisksctl mount -b "/dev/${deviceinfo%% *}" || { override_notify "Error mounting ebook." -u critical; exit 1; } +rm -f $ebookpath/unread_articles_????-??-??.epub + +override_notify "Downloading...\nEbook mounted." -t 0 + +# wait for download to finish +wait "$pid" + +override_notify "Transferring files." -t 0 + +mv "$outfile" "$ebookpath/unread_articles_$(date +"%Y-%m-%d").epub" +udisksctl unmount -b "/dev/${deviceinfo%% *}" || { override_notify "Error unmounting ebook." -u critical; exit 1; } + +override_notify "Finished successfully." -u low