#!/bin/bash # From Matt Brophy 2/16/2012 --Fred # Download scripts available from the http://www.bristle.com/Tips/ website. # # Assumptions: # - Specified script URL's are simply Apache directory listings. # As of 2/16/12, they are generated by: # Apache/2.2.9 (Fedora) Server at bristle.com Port 80 # - wget is installed and available on the given machine # if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "Usage: ${0} [dir]" echo echo " url Bristle.com URL to download scripts from. For example: " echo " http://www.bristle.com/Tips/Mac/Unix/ " echo echo " dir Where to save the downloaded scripts. Defaults to the " echo " current working directory. Note that all files in [dir] " echo " will be chmod 755'd following the download " echo exit fi URL="${1}" DIR="." if [ $# -eq 2 ]; then DIR="${2}"; if [ ! -e "${DIR}" ]; then echo "The directory ${DIR} does not exist, create it? [y/N]" read ANS if [ "${ANS}" == "y" ] || [ "$ANS" == "Y" ]; then mkdir "${DIR}"; if [ ! -e "${DIR}" ]; then echo "Unable to create directory ${DIR}. Exiting." exit fi else echo "Directory not created. Exiting." exit fi fi if [ ! -d "${DIR}" ]; then echo "${DIR} is not a directory. Exiting." exit; fi if [ ! -w "${DIR}" ]; then echo "No write permissions to dir ${DIR}. Exiting." exit fi fi # wget options: # -r Recursively retrieve files from the specified url # (i.e., those linked to by the page) # -np Do not traverse to parent directories # -l 1 Limit recursive traversal to only the specified directory # -N Turn on timestamping, which will allow newer versions of remote files # to overwrite older, local versions # -nH Do not create a local host directory (i.e., www.bristle.com/) # -nd Do not create a hierarchy of directories, simply save all # files to the working dir # -R "*.*,*/" Reject files with extensions and links to subdirectories # -w 0.5 Wait half a second in between each download pushd "${DIR}" > /dev/null wget -r -np -l 1 -N -nH -nd -R "*.*,*/" -w 0.5 "${URL}" chmod 755 ./* popd > /dev/null