one part of the hoist/yoink system for transferring files over the gemini protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
808 B

#!/bin/sh
yoink_url="gemini://illegaldrugs.net/cgi-bin/yoink"
jetforce_pid=""
prev_dir="$PWD"
file_path="$1"
[ -z "$1" ] && echo "specify a file path." && exit
external_ip="$(gmni -lj always gemini://illegaldrugs.net/cgi-bin/ip | tr -d '\n')"
filename="$(basename "$file_path")"
temp_dir="$(mktemp -d)"
file_ext="$(echo "$filename" | rev | cut -f 1 -d '.' | rev )"
if echo "$file_ext" | grep -qvx "[a-z]*"
then
echo "the file extension $file_ext is not valid."
exit
fi
cp "$file_path" "$temp_dir"
cd "$temp_dir"
echo "hoisting."
jetforce --dir . --host $external_ip --hostname $external_ip >/dev/null 2>&1 &
jetforce_pid="$!"
sleep 2 # give jetforce enough time to start up
echo "requesting yoink."
gmni -j always "$yoink_url?$external_ip/$filename"
kill $jetforce_pid
cd "$prev_dir"
rm -r "$temp_dir"