#!/bin/sh # gopher-get.sh version 1 by Ben Collver NETCAT="ncat -vv" #NETCAT="nc -vv" OUT="" URL="$1" if [ -z "$URL" ] then cat <<__EOF__ Usage: gopher-get.sh [options] URL Options: -o filename Exit code 0 on success. __EOF__ exit fi if [ "$URL" = "-o" ] then shift OUT="$1" shift URL="$1" fi if [ -z "$OUT" ] then OUT=$(basename $URL) fi CONN=$(echo "$URL" | awk -F / '{print $3}') HOST=$(echo "$CONN" | awk -F : '{print $1}') PORT=$(echo "$CONN" | awk -F : '{print $2}') SEL=$(echo "$URL" | awk '{ # remove protocol and host sub(/^gopher:\/\/[^:/]*/, "") # remove port sub(/^:[0-9]*/, "") # remove item type sub(/^\/?[0-9a-zA-Z]/, "") print }') if [ -z "$PORT" ] then PORT=70 fi if [ "$OUT" = "-" ] then printf "$SEL\r\n" | $NETCAT $HOST $PORT else if [ -e "$OUT" ] then echo "File already exists: $OUT" exit 1 fi printf "$SEL\r\n" | $NETCAT $HOST $PORT >$OUT fi