brought socat version in line with openssl

This commit is contained in:
jan6 2021-09-08 20:16:36 +03:00
parent 6cb59a93c7
commit 137481141d
3 changed files with 26 additions and 26 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
konpeito konpeito
bin

View File

@ -15,7 +15,11 @@ if [ -n "$i" ];then
domain="$(echo "$a"|cut -d / -f 1)" domain="$(echo "$a"|cut -d / -f 1)"
url="$(echo "$a"|cut -d / -f 2-)" url="$(echo "$a"|cut -d / -f 2-)"
printf "%s\r\n" "gemini://$domain/$url"| printf "%s\r\n" "gemini://$domain/$url"|
openssl s_client -connect "$domain":1965 -quiet -verify_quiet #it will still have a lil warning on self-signed certs #it will still have a lil warning on self-signed certs
openssl s_client -connect "$domain":1965 -quiet -verify_quiet \
2>/dev/null
#2>&1|sed "\$s/^read:errno=0\$//"
#^stderr ignoring, or, stderr combining with stdout and filtering the normal-end
} }
else else
echo "no gemini:// url detected!" echo "no gemini:// url detected!"

View File

@ -1,29 +1,24 @@
#!/bin/sh #!/bin/sh
#required: socat #required: socat
# netcat (any version will work, as long as "program" "host" "port" is a valid syntax)
#planning to get rid of netcat, possibly also merge grep and awk, maybe make basename swappable with cut
gemini_get(){ #blindly assumes it gets a gemini url as the first argument if [ -z "$i" ];then
if [ -n "$1" ];then #if command-line argument
domain="$(echo "$1"|cut -d / -f 3)" i="$1"
file="/tmp/$domain-$(uuidgen)" else #ask user
mkfifo "$file" printf "gemini:// URL: " >&2;
read -r i;
echo "downloading $1 from $domain" >&2 fi
socat openssl-connect:"$domain":1965,verify=0 pipe:"$file"&pid="$!" fi
if [ -n "$i" ];then
sleep 1 #you might need to tweak this depending on your machine and internet speeds >0.5 seconds seems to work echo "$i"|cut -d / -f 3-|{
read -r a
printf "%s\r\n" "$1" >"$file" domain="$(echo "$a"|cut -d / -f 1)"
sleep 1 url="$(echo "$a"|cut -d / -f 2-)"
cat "$file" printf "%s\r\n" "gemini://$domain/$url"|
kill "$pid" 2>/dev/null;true #kill it if not already dead, probably not needed socat openssl-connect:"$domain":1965,verify=0 stdio
rm -f "$file" }
} else
echo "no gemini:// url detected!"
#detect if it's ran directly fi
case $- in i=""
*i*) : ;;
*) gemini_get "$@";;
esac