update
[stationnotifier] / notificatorossl
1 #!/usr/bin/env bash
2 # notifitcatorossl is a fork of https://github.com/ThatsRedacted/StationNotifier
3 # This program uses openssl rather than curl to connect to a gemini site`
4
5 key='/home/frrobert/.config/amfora/7debbb3fae40dbe77746aa465300febaec5abb778faa8a550f8e5924f0977983.key'
6 cert='/home/frrobert/.config/amfora/7debbb3fae40dbe77746aa465300febaec5abb778faa8a550f8e5924f0977983.crt'
7 connectto=30
8 howoften=
9
10 tmpfile=$(mktemp /tmp/not.XXXXXX)
11                  url="gemini://station.martinrue.com/frrobert"
12 lasttime=0
13 trap ctrl_c INT
14 function ctrl_c() {
15 rm -f $tmpfile
16 exit 0
17 }
18 while [ true ]
19 do
20                 if [[ "$url" != *://* ]];then
21                         domain="$url"
22                         url="gemini://$url"
23                 else
24                                 domain=$(sed 's/gemini:\/\///' <<< "$url")
25                         fi
26                         if [[ "$url" != *.*/*.* ]] && [[ $url != */ ]];then
27                                 url="$url/"
28                         fi
29                         domain=$(sed 's/\/.*$//' <<< "$domain")
30                         timeout $connectto openssl s_client -crlf -quiet -key $key -cert $cert -connect "$domain:1965" <<<"$url" 2>/dev/null >> $tmpfile
31             
32                 
33                 
34                 IFS=' ' read -ra my_array <<< $(cat $tmpfile | grep '/notifications')
35     notifications=${my_array[2]}
36     echo "" > $tmpfile
37     if [[ $notifications -gt $lasttime ]]; then
38             new=$(expr $notifications - $lasttime)
39         echo -en "\007"
40         echo "You have $notifications notifications and $new new notifications!"
41         read -p "Press enter to continue, or either type amfora or lagrange to go to notifications" answer
42         case $answer in
43                 amfora)
44                        amfora $url
45                        clear
46                       ;;
47                 lagrange)
48                         lagrange $url
49                         clear
50                         ;;
51                 *)
52                         clear
53                         ;;
54         esac
55 echo "waiting for new notifications"
56         lasttime=$notifications
57         unset my_array
58     fi
59     sleep 600
60 done
61