Add functional for opening full urls

This commit is contained in:
g1n 2021-07-06 08:11:28 +00:00
parent 0877a810e9
commit 46e53a5f74
1 changed files with 11 additions and 3 deletions

14
laconia
View File

@ -2,7 +2,12 @@
PROGNAME=${0##*/}
VERSION="0.0.1"
URI=$( echo $1 | sed -e 's/spartan:\/\///' )
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url=$(echo $1 | sed -e 's,$proto,,g')
host=$(echo "$url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
path="$(echo $url | grep / | cut -d/ -f2-)"
port=300
error_exit() {
printf "%s: %s\n" "$PROGNAME" "${1:-"Unknown Error"}" >&2
@ -10,16 +15,19 @@ error_exit() {
}
usage() {
printf "usage: %s [OPTIONS] URL [ARGS]\n" "$PROGNAME"
printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME"
printf "Simple client for spartan protocol\n"
}
case $1 in
-h | --help)
usage; exit ;;
-p | --port)
export PORT=$3 ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
printf "$1 / 0\r\n" | nc $1 300 -4
echo $proto $host $path $port
printf "$host /$path 0\r\n" | nc $host $port
;;
esac