diff --git a/Scripts/wget.sh b/Scripts/wget.sh index 758243e..10b5710 100755 --- a/Scripts/wget.sh +++ b/Scripts/wget.sh @@ -20,23 +20,39 @@ # REVISION: --- #=============================================================================== +force=0 +verbose=0 +output="" + +function debug +{ + [ "$verbose" == "1" ] && echo "$@" +} + function show_help { echo - echo "Usage: $0 [flags] URL" - echo "Flags:" + echo "Usage: `basename $0` [OPTION]... [URL]..." + echo + echo "Options:" echo " -v verbose" echo " -f force overwriting of existing files" - echo " -o file specify output filename (default is name on server)" + echo " -o FILE specify output filename (default is name on server)" echo " --help displays this help" echo exit } -force=0 -verbose=0 -output="" +function error +{ + echo "$@" + echo "Usage: `basename $0` [OPTION]... [URL]..." + echo + echo "Try \``basename $0` --help' for more options." + exit +} +# Parse Arguments for (( i=0 ; $i < $# ; i++ )) do var="${@:$((i+1)):1}" @@ -51,23 +67,18 @@ esac done -[ "$url" == "" ] && echo && echo "Error: No URL specified" && show_help +[ "$url" == "" ] && error "Error: No URL specified" protocol=`echo $url | cut -d ':' -f 1` method="GET" server=`echo $url | cut -d '/' -f 3` path_offset=`expr ${#protocol} + ${#server} + 4` path=`echo $url | cut -c $path_offset-4000` -[ "$protocol" == "" ] && echo && echo "Error: Invalid URL" && show_help -[ "$server" == "" ] && echo && echo "Error: Invalid URL" && show_help +[ "$protocol" == "" ] && error "Error: Invalid URL" +[ "$server" == "" ] && error "Error: Invalid URL" [ "$path" == "" ] && path="/" [ "$output" == "" ] && output=`basename $path` [ "$output" == "/" ] && output="index.html" -function debug -{ - [ "$verbose" == "1" ] && echo "$@" -} - function filter_header { read status