wallabag-to-ebook (1625B) - raw
1 #!/bin/sh 2 3 domain="" 4 phpsessid="" 5 rememberme="" 6 ebookpath="" 7 uuid="" # ebook UUID 8 9 override_notify() { 10 sub="$1" 11 shift 12 notify-send -h "string:x-canonical-private-synchronous:wallabag" $@ "Wallabag" "$sub" 13 } 14 15 # check if ebook exists before starting download 16 [ ! -e "/dev/disk/by-uuid/$uuid" ] && { override_notify "Ebook not connected." -u critical; exit 1; } 17 18 # mount ebook and remove last entry if existent 19 udisksctl mount -b "/dev/disk/by-uuid/$uuid" || { override_notify "Error mounting ebook." -u critical; exit 1; } 20 rm -f $ebookpath/unread_articles_????-??-??.epub 21 22 override_notify "Ebook mounted.\nDownloading..." -t 0 23 24 # download new epub file 25 outfile=$(mktemp) 26 curl -s "https://$domain/export/unread.json" \ 27 -H "cookie: PHPSESSID=$phpsessid; REMEMBERME=$rememberme" \ 28 -o "$outfile" \ 29 || { override_notify "Download failed." -u critical; exit 1; } 30 31 # if there new entries, download and transfer epub file 32 if [ "0" != "$(jq length "$outfile")" ]; then 33 curl -s "https://$domain/export/unread.epub" \ 34 -H "cookie: PHPSESSID=$phpsessid; REMEMBERME=$rememberme" \ 35 -o "$outfile" \ 36 || { override_notify "Download failed." -u critical; exit 1; } 37 38 override_notify "Transferring files." -t 0 39 40 mv "$outfile" "$ebookpath/unread_articles_$(date +"%Y-%m-%d").epub" 41 fi 42 43 # if unmount failed check 1 second later, it normally fixes it 44 udisksctl unmount -b "/dev/disk/by-uuid/$uuid" \ 45 || { sleep 1; udisksctl unmount -b "/dev/disk/by-uuid/$uuid"; } \ 46 || { override_notify "Error unmounting ebook." -u critical; exit 1; } 47 48 override_notify "Finished successfully." -u low