added bash script that uses openssl in place of curl
[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
9 tmpfile=$(mktemp /tmp/not.XXXXXX)
10                  url="gemini://station.martinrue.com/frrobert"
11 lasttime=0
12 trap ctrl_c INT
13 function ctrl_c() {
14 rm -f $tmpfile
15 exit 0
16 }
17 while [ true ]
18 do
19                 if [[ "$url" != *://* ]];then
20                         domain="$url"
21                         url="gemini://$url"
22                 else
23                                 domain=$(sed 's/gemini:\/\///' <<< "$url")
24                         fi
25                         if [[ "$url" != *.*/*.* ]] && [[ $url != */ ]];then
26                                 url="$url/"
27                         fi
28                         domain=$(sed 's/\/.*$//' <<< "$domain")
29                         timeout $connectto openssl s_client -crlf -quiet -key $key -cert $cert -connect "$domain:1965" <<<"$url" 2>/dev/null >> $tmpfile
30             
31                 
32                 
33                 IFS=' ' read -ra my_array <<< $(cat $tmpfile | grep '/notifications')
34     notifications=${my_array[2]}
35     echo "" > $tmpfile
36     if [[ $notifications -gt $lasttime ]]; then
37         echo -en "\007"
38         echo "You have new notifications!"
39         read -p "Press enter to continue or amfora to go to notifications" answer
40         case $answer in
41                 amfora) $(amfora gemini://station.martinrue.com/frrobert)
42                         ;;
43         esac
44
45         lasttime=$notifications
46         unset my_array
47     fi
48     sleep 60
49 done
50