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
bin

View File

@ -15,7 +15,11 @@ if [ -n "$i" ];then
domain="$(echo "$a"|cut -d / -f 1)"
url="$(echo "$a"|cut -d / -f 2-)"
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
echo "no gemini:// url detected!"

View File

@ -1,29 +1,24 @@
#!/bin/sh
#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
domain="$(echo "$1"|cut -d / -f 3)"
file="/tmp/$domain-$(uuidgen)"
mkfifo "$file"
echo "downloading $1 from $domain" >&2
socat openssl-connect:"$domain":1965,verify=0 pipe:"$file"&pid="$!"
sleep 1 #you might need to tweak this depending on your machine and internet speeds >0.5 seconds seems to work
printf "%s\r\n" "$1" >"$file"
sleep 1
cat "$file"
kill "$pid" 2>/dev/null;true #kill it if not already dead, probably not needed
rm -f "$file"
}
#detect if it's ran directly
case $- in
*i*) : ;;
*) gemini_get "$@";;
esac
if [ -z "$i" ];then
if [ -n "$1" ];then #if command-line argument
i="$1"
else #ask user
printf "gemini:// URL: " >&2;
read -r i;
fi
fi
if [ -n "$i" ];then
echo "$i"|cut -d / -f 3-|{
read -r a
domain="$(echo "$a"|cut -d / -f 1)"
url="$(echo "$a"|cut -d / -f 2-)"
printf "%s\r\n" "gemini://$domain/$url"|
socat openssl-connect:"$domain":1965,verify=0 stdio
}
else
echo "no gemini:// url detected!"
fi
i=""