added brew p7zip and ffmpeg

This commit is contained in:
Nathaniel Landau
2016-01-03 19:24:25 -05:00
parent a3406fa571
commit 50168bc30f

View File

@@ -3,24 +3,9 @@
# ################################################## # ##################################################
# My Generic BASH script template # My Generic BASH script template
# #
version="1.0.0" # Sets version variable for this script version="1.0.0" # Sets version variable
# #
scriptTemplateVersion="1.0.1" # Version of scriptTemplate.sh scriptTemplateVersion="1.5.0" # Version of scriptTemplate.sh that this script is based on
# that this script is based on
#
# Installs Homebrew and all its prerequisites, then installs a number of packages.
#
# For logging levels use the following functions:
# - header: Prints a script header
# - input: Ask for user input
# - success: Print script success
# - info: Print information to the user
# - notice: Notify the user of something
# - warning: Warn the user of something
# - error: Print a non-fatal error
# - die: A fatal error. Will exit the script
# - debug: Debug information
# - verbose: Debug info only printed when 'verbose' flag is set to 'true'.
# #
# HISTORY: # HISTORY:
# #
@@ -28,13 +13,20 @@ scriptTemplateVersion="1.0.1" # Version of scriptTemplate.sh
# #
# ################################################## # ##################################################
# Provide a variable with the location of this script.
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Source Scripting Utilities # Source Scripting Utilities
# ----------------------------------- # -----------------------------------
# If these can't be found, update the path to the file # These shared utilities provide many functions which are needed to provide
# the functionality in this boilerplate. This script will fail if they can
# not be found.
# ----------------------------------- # -----------------------------------
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then utilsLocation="${scriptPath}/../lib/utils.sh" # Update this path to find the utilities.
source "${SCRIPTDIR}/../lib/utils.sh"
if [ -f "${utilsLocation}" ]; then
source "${utilsLocation}"
else else
echo "Please find the file util.sh and add a reference to it in this script. Exiting." echo "Please find the file util.sh and add a reference to it in this script. Exiting."
exit 1 exit 1
@@ -47,45 +39,49 @@ fi
# ----------------------------------- # -----------------------------------
function trapCleanup() { function trapCleanup() {
echo "" echo ""
# Delete temp files, if any
if is_dir "${tmpDir}"; then if is_dir "${tmpDir}"; then
rm -r "${tmpDir}" rm -r "${tmpDir}"
fi fi
die "Exit trapped." # Edit this if you like. die "Exit trapped." # Edit this if you like.
} }
# safeExit
# -----------------------------------
# Non destructive exit for when script exits naturally.
# Usage: Add this function at the end of every script.
# -----------------------------------
function safeExit() {
# Delete temp files, if any
if is_dir "${tmpDir}"; then
rm -r "${tmpDir}"
fi
trap - INT TERM EXIT
exit
}
# Set Flags # Set Flags
# ----------------------------------- # -----------------------------------
# Flags which can be overridden by user input. # Flags which can be overridden by user input.
# Default values are below # Default values are below
# ----------------------------------- # -----------------------------------
quiet=0 quiet=false
printLog=0 printLog=false
verbose=0 verbose=false
force=0 force=false
strict=0 strict=false
debug=false
args=()
# Set Temp Directory
# Set Local Variables
# ----------------------------------- # -----------------------------------
# A set of variables used by many scripts
# -----------------------------------
# Set Script name and location variables
scriptName=`basename ${0}` # Full name
scriptBasename="$(basename ${scriptName} .sh)" # Strips '.sh' from name
scriptPath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Set time stamp
now=$(date +"%m-%d-%Y %r")
# Set hostname
thisHost=$(hostname)
# Create temp directory with three random numbers and the process ID # Create temp directory with three random numbers and the process ID
# in the name. This directory is removed automatically at exit. # in the name. This directory is removed automatically at exit.
tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" # -----------------------------------
(umask 077 && mkdir "${tmpDir}") || { tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$"
die "Could not create temporary directory! Exiting." (umask 077 && mkdir "${tmpDir}") || {
} die "Could not create temporary directory! Exiting."
}
# Logging # Logging
# ----------------------------------- # -----------------------------------
@@ -97,11 +93,23 @@ thisHost=$(hostname)
# ----------------------------------- # -----------------------------------
logFile="$HOME/Library/Logs/${scriptBasename}.log" logFile="$HOME/Library/Logs/${scriptBasename}.log"
# Check for Dependencies
# -----------------------------------
# Arrays containing package dependencies needed to execute this script.
# The script will fail if dependencies are not installed. For Mac users,
# most dependencies can be installed automatically using the package
# manager 'Homebrew'. Mac applications will be installed using
# Homebrew Casks. Ruby and gems via RVM.
# -----------------------------------
homebrewDependencies=()
caskDependencies=()
gemDependencies=()
function mainScript() { function mainScript() {
############## Begin Script Here ################### ############## Begin Script Here ###################
####################################################
header "Beginning ${scriptName}" notice "Beginning ${scriptName}"
# Set Variables # Set Variables
LISTINSTALLED="brew list" LISTINSTALLED="brew list"
@@ -114,6 +122,7 @@ RECIPES=(
bash-completion bash-completion
colordiff colordiff
coreutils coreutils
ffmpeg
gifsicle gifsicle
git git
git-extras git-extras
@@ -136,6 +145,7 @@ RECIPES=(
optipng optipng
pkg-config pkg-config
pngcrush pngcrush
p7zip
readline readline
rename rename
shellcheck shellcheck
@@ -169,9 +179,10 @@ doInstall
htopPermissions htopPermissions
brewCleanup brewCleanup
header "Ending ${scriptName}" notice "${scriptName} completed"
############## End Script Here ################### ####################################################
############### End Script Here ####################
} }
############## Begin Options and Usage ################### ############## Begin Options and Usage ###################
@@ -184,12 +195,12 @@ usage() {
Installs Homebrew and all its prerequisites, then installs a number of packages. Installs Homebrew and all its prerequisites, then installs a number of packages.
Options: Options:
-f, --force Skip all user interaction. Implied 'Yes' to all actions
-q, --quiet Quiet (no output) -q, --quiet Quiet (no output)
-l, --log Print log to file -l, --log Print log to file
-s, --strict Exit script with null variables. i.e 'set -o nounset' -s, --strict Exit script with null variables. i.e 'set -o nounset'
-v, --verbose Output more information. (Items echoed to 'verbose') -v, --verbose Output more information. (Items echoed to 'verbose')
-h, --help Display this help and exit -h, --help Display this help and exit
--force Skip all user interaction. Implied 'Yes' to all actions
--version Output version information and exit --version Output version information and exit
" "
} }
@@ -238,26 +249,26 @@ unset options
while [[ $1 = -?* ]]; do while [[ $1 = -?* ]]; do
case $1 in case $1 in
-h|--help) usage >&2; safeExit ;; -h|--help) usage >&2; safeExit ;;
--version) echo "$(basename $0) $version"; safeExit ;; --version) echo "$(basename $0) ${version}"; safeExit ;;
-u|--username) shift; username=$1 ;; -v|--verbose) verbose=true ;;
-p|--password) shift; password=$1 ;; -l|--log) printLog=true ;;
-v|--verbose) verbose=1 ;; -q|--quiet) quiet=true ;;
-l|--log) printLog=1 ;; -s|--strict) strict=true;;
-q|--quiet) quiet=1 ;; -d|--debug) debug=true;;
-s|--strict) strict=1;; --force) force=true ;;
-f|--force) force=1 ;;
--endopts) shift; break ;; --endopts) shift; break ;;
*) die "invalid option: '$1'." ;; *) die "invalid option: '$1'." ;;
esac esac
shift shift
done done
# Store the remaining part as arguments.
args+=("$@")
############## End Options and Usage ################### ############## End Options and Usage ###################
# ############# ############# ############# # ############# ############# #############
# ## TIME TO RUN THE SCRIPT ## # ## TIME TO RUN THE SCRIPT ##
# ## ## # ## ##
@@ -269,19 +280,27 @@ done
# Trap bad exits with your cleanup function # Trap bad exits with your cleanup function
trap trapCleanup EXIT INT TERM trap trapCleanup EXIT INT TERM
# Exit on error. Append ||true if you expect an error. # Set IFS to preferred implementation
IFS=$' \n\t'
# Exit on error. Append '||true' when you run the script if you expect an error.
set -o errexit set -o errexit
# Run in debug mode, if set
if ${debug}; then set -x ; fi
# Exit on empty variable # Exit on empty variable
if [ "${strict}" = "1" ]; then if ${strict}; then set -o nounset ; fi
set -o nounset
fi
# Bash will remember & return the highest exitcode in a chain of pipes. # Bash will remember & return the highest exitcode in a chain of pipes.
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip` # This way you can catch the error in case mysqldump fails in `mysqldump |gzip`, for example.
set -o pipefail set -o pipefail
# Invoke the checkDependenices function to test for Bash packages. Uncomment if needed.
# checkDependencies
mainScript # Run your script # Run your script
mainScript
safeExit # Exit cleanly # Exit cleanlyd
safeExit