Title: ericcurl.sh.2013.11.13
Created: 2018-04-29 22:31:26 +0000

#!/bin/bash

# File: ericcurl.sh

# clear the screen so we have a nice neat terminal window
clear

echo ericurl.sh version 1.0
echo

OUTPUTFILE=""
URL=""
YESNO="N"


echo "Type 'man curl' on the command line for more information about how to use wildcards, etc."
echo
echo "On the next line, type or paste in the exact URL (no spaces) of the file(s) on the internet you want to get, (starting with http:// or ftp:// etc.):"
read URL

echo
echo "On the next line, type or paste in the exact path and file name (no spaces) you want the file to be saved as, existing files will be appended to!  Full path names starting with root (/) are the safest way to enter your file name:"
read OUTPUTFILE

COMMAND="curl -C - --output $OUTPUTFILE $URL"

echo
echo "The following line is excactly how the curl command will be issued, please verify this is what you want to do:"
echo
echo $COMMAND
echo

while true
do
  # (1) prompt user, and read command line argument
  read -p "Do you want to continue (Y/N)? " YESNO
  echo

  # (2) handle the input we were given
  case $YESNO in
   [yY]* ) # main loop (infinite loop)
        while :

        do
                # timestamp the loop
                echo -n "Start time/date: "
            date
                echo

                # here is where we attempt to download something
                # example:  curl -C - --output "/Users/ericswanson/Downloads/BigFile.dmg" http://download.greatwebsite.com/BigFile.dmg

                `$COMMAND`

                # see what exit code curl gave
                if [ "$?" = "0" ]; then
                        # exit without errors
                        echo
                        echo -n "Download completed at: "
                        date
                        echo

                        exit 0
                else
                        # exit with errors, retry
                        echo
                        echo "curl exited with errors, will retry where we left off..."
                        echo

                        # pause a few seconds so we minimize runaway errors on fast systems (like if the HDD is full, or something like that)
                        sleep 5
                fi     

        # main while loop ends here
        done 


           break;;

   [nN]* ) exit;;

   * )     echo "Just enter Y or N, please.";;
  esac
done

exit 0