5ade715bab70900bb851d0422bf7e53f689c5a03
[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=''
6 cert=''
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         echo -en "\007"
39         echo "You have new notifications!"
40         read -p "Press enter to continue, or either type amfora or lagrange to go to notifications" answer
41         case $answer in
42                 amfora)
43                        amfora $url
44                        clear
45                       ;;
46                 lagrange)
47                         lagrange $url
48                         clear
49                         ;;
50                 *)
51                         clear
52                         ;;
53         esac
54 echo "waiting for new notifications"
55         lasttime=$notifications
56         unset my_array
57     fi
58     sleep 60
59 done
60