gopher.sh - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       gopher.sh (473B)
       ---
            1 #!/bin/sh
            2 # fetch files via gopher.
            3 # Dependencies: netcat
            4 
            5 if test "$1" = ""; then
            6         echo "$0 <url>" >&2
            7         exit 1
            8 fi
            9 
           10 u=$(echo "$1" | sed 's@^gopher://@@g')
           11 host=$(echo "$u" | sed 's@/.*$@@g')
           12 port=$(echo "$host" | cut -s -d ':' -f 2)
           13 host=$(echo "$host" | cut -d ':' -f 1)
           14 path=$(echo "$u" | sed -E 's@^[^/]*(/|/./?)?@@g')
           15 
           16 test x"$port" = x"" && port="70"
           17 
           18 # DEBUG
           19 #echo "host: $host"
           20 #echo "port: $port"
           21 #echo "path: $path"
           22 
           23 printf '/%s\r\n' "$path" | nc "$host" "$port"