From 26e3c3aa2513b32e37557e3947b958b3707994e8 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Wed, 6 Apr 2016 15:02:36 -0400 Subject: [PATCH] A new setup script --- setupScripts/devApps.sh | 254 ------ setupScripts/dropbox.sh | 16 - setupScripts/fileTest.sh | 254 ------ setupScripts/homebrew.sh | 306 ------- setupScripts/install_command_line_tools.sh | 359 -------- setupScripts/macApps.sh | 284 ------ setupScripts/mackup.sh | 300 ------- setupScripts/newMacSetup.sh | 977 +++++++++++++++++++-- setupScripts/ruby.sh | 285 ------ setupScripts/ssh.sh | 252 ------ 10 files changed, 911 insertions(+), 2376 deletions(-) delete mode 100755 setupScripts/devApps.sh delete mode 100755 setupScripts/dropbox.sh delete mode 100755 setupScripts/fileTest.sh delete mode 100755 setupScripts/homebrew.sh delete mode 100755 setupScripts/install_command_line_tools.sh delete mode 100755 setupScripts/macApps.sh delete mode 100755 setupScripts/mackup.sh delete mode 100755 setupScripts/ruby.sh delete mode 100755 setupScripts/ssh.sh diff --git a/setupScripts/devApps.sh b/setupScripts/devApps.sh deleted file mode 100755 index 8a1f688..0000000 --- a/setupScripts/devApps.sh +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.0.1" # Version of scriptTemplate.sh -# that this script is based on -# -# This script installs Homebrew Casks - allowing for command line -# installation of native Mac Applications. Once Homebrew Casks is installed, -# this script then installs a number of applications. -# -# 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: -# -# * 2015-02-07 - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 - - -# 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 -# in the name. This directory is removed automatically at exit. - tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" - (umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." - } - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="${HOME}/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### -header "Beginning ${scriptName}" - - -# Set Variables -LISTINSTALLED="brew cask list" -INSTALLCOMMAND="brew cask install --appdir=/Applications" - -RECIPES=( - charles - codekit - github - imagealpha - imageoptim - istat-menus - java - joinme - kaleidoscope - licecap - mamp - paw - suspicious-package - tower -) - -# Run Functions - -hasHomebrew -hasCasks -brewMaintenance -doInstall -brewCleanup - - -header "Completed ${scriptName}" -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script installs Homebrew Casks - allowing for command line -installation of native Mac Applications. Once Homebrew Casks is installed, -this script then installs a number of applications. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Exit on empty variable -if [ "${strict}" = "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/dropbox.sh b/setupScripts/dropbox.sh deleted file mode 100755 index e2a2b75..0000000 --- a/setupScripts/dropbox.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - - -# Confirm we have Dropbox -# hasDropbox - - - diff --git a/setupScripts/fileTest.sh b/setupScripts/fileTest.sh deleted file mode 100755 index 943a507..0000000 --- a/setupScripts/fileTest.sh +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.1.0" # Version of scriptTemplate.sh that this script is based on -# v.1.1.0 - Added 'debug' option -# -# A Script to test if certain files from Dropbox are synced to the local hard drive. -# This script relies on a text file containing paths to documents. -# -# 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: -# -# * 2015-02-07 - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 -debug=0 - - -# 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 -# in the name. This directory is removed automatically at exit. - tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" - (umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." - } - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="$HOME/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### -header "Beginning ${scriptBasename}" - - -# Variables from config file -if is_file "../etc/mackup.cfg"; then - verbose "Sourcing ../etc/mackup.cfg" && source "../etc/mackup.cfg" - TESTFILE="${TESTCFG}" -else - die "Can not run without config file. Please locate mackup.cfg" -fi - -if is_not_file "${TESTFILE}"; then - die "Could not find ${TESTFILE}. Exiting." -else - notice "Confirming that Dropbox has synced..." - while IFS= read -r file - do - while [ ! -e $HOME/"${file}" ] ; - do - warning "...Waiting for Dropbox to Sync ${file}." - sleep 10 - done - success "Found ${file}" - done < "${TESTFILE}" -fi - - -header "Completed ${scriptBasename}" -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -A Script to test if certain files from Dropbox are synced to the local hard drive. -This script relies on a text file containing paths to documents. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -d, --debug Runs script in BASH debug mode (set -x) - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -d|--debug) debug=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Run in debug mode, if set -if [ "${debug}" == "1" ]; then - set -x -fi - -# Exit on empty variable -if [ "${strict}" == "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/homebrew.sh b/setupScripts/homebrew.sh deleted file mode 100755 index 29ae520..0000000 --- a/setupScripts/homebrew.sh +++ /dev/null @@ -1,306 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable -# -scriptTemplateVersion="1.5.0" # Version of scriptTemplate.sh that this script is based on -# -# HISTORY: -# -# * 2015-02-07 - v1.0.0 - First Creation -# -# ################################################## - -# Provide a variable with the location of this script. -scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Source Scripting Utilities -# ----------------------------------- -# 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. -# ----------------------------------- - -utilsLocation="${scriptPath}/../lib/utils.sh" # Update this path to find the utilities. - -if [ -f "${utilsLocation}" ]; then - source "${utilsLocation}" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - # Delete temp files, if any - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - 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 -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=false -printLog=false -verbose=false -force=false -strict=false -debug=false -args=() - -# Set Temp Directory -# ----------------------------------- -# Create temp directory with three random numbers and the process ID -# in the name. This directory is removed automatically at exit. -# ----------------------------------- -tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" -(umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." -} - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $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() { -############## Begin Script Here ################### -#################################################### - -notice "Beginning ${scriptName}" - -# Set Variables -LISTINSTALLED="brew list" -INSTALLCOMMAND="brew install" - -RECIPES=( - autoconf - automake - bash - bash-completion - colordiff - coreutils - ffmpeg - gifsicle - git - git-extras - git-flow - htop-osx - hub - hr - id3tool - imagemagick - jpegoptim - jq - lesspipe - libksba - libtool - libyaml - mackup - man2html - multimarkdown - openssl - optipng - pkg-config - pngcrush - p7zip - readline - rename - shellcheck - sl - source-highlight - ssh-copy-id - sqlite - tag - terminal-notifier - tldr - tree - unison - z -) - -htopPermissions() { - seek_confirmation "Set HTOP permissions?" - if is_confirmed; then - if [[ "$(type -P $binroot/htop)" && "$(stat -L -f "%Su:%Sg" "$binroot/htop")" != "root:wheel" || ! "$(($(stat -L -f "%DMp" "$binroot/htop") & 4))" ]]; then - notice "Updating htop permissions" - sudo chown root:wheel "$binroot/htop" - sudo chmod u+s "$binroot/htop" - fi - fi -} - -# Run Functions -hasHomebrew -brewMaintenance -doInstall -htopPermissions -brewCleanup - -notice "${scriptName} completed" - -#################################################### -############### End Script Here #################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -Installs Homebrew and all its prerequisites, then installs a number of packages. - - Options: - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -h, --help Display this help and exit - --force Skip all user interaction. Implied 'Yes' to all actions - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) ${version}"; safeExit ;; - -v|--verbose) verbose=true ;; - -l|--log) printLog=true ;; - -q|--quiet) quiet=true ;; - -s|--strict) strict=true;; - -d|--debug) debug=true;; - --force) force=true ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - -# Store the remaining part as arguments. -args+=("$@") - -############## End Options and Usage ################### - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# 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 - -# Run in debug mode, if set -if ${debug}; then set -x ; fi - -# Exit on empty variable -if ${strict}; then set -o nounset ; fi - -# 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`, for example. -set -o pipefail - -# Invoke the checkDependenices function to test for Bash packages. Uncomment if needed. -# checkDependencies - -# Run your script -mainScript - -# Exit cleanlyd -safeExit \ No newline at end of file diff --git a/setupScripts/install_command_line_tools.sh b/setupScripts/install_command_line_tools.sh deleted file mode 100755 index 2f3a445..0000000 --- a/setupScripts/install_command_line_tools.sh +++ /dev/null @@ -1,359 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# -# # This script was taken in its entirety from: -# https://github.com/rtrouton/rtrouton_scripts/ -# -# This script will download and install the Xcode command line -# tools on Macs running 10.7.x and higher. -# -# How the script works: -# -# On 10.9.x and 10.10.x: -# -# 1. Creates a placeholder file in $tmpDir. This file's existence is checked by the -# softwareupdate tool before allowing the installation of the Xcode command line tools. -# -# 2. Runs the softwareupdate tool and checks for the latest version of the Xcode command -# line tools for the OS in question. -# -# 3. Uses the softwareupdate tool to install the latest version of the Xcode command -# line tools for the OS in question. -# -# 4. Removes the placeholder file stored in /tmp. -# -# -# On 10.7.x and 10.8.x: -# -# 1. Uses curl to download a disk image containing the specified Xcode Command Line -# Tools installer from Apple's web site -# -# 2. Renames the downloaded disk image to cltools.dmg. -# -# 2. Mounts the disk image silently in $tmpDir. Disk image will not be visible to any -# logged-in user. -# -# 3. Installs the Xcode Command Line Tools using the installer package stored on the -# disk image -# -# 4. After installation, unmounts the disk image and removes it from the Mac in question. -# -version="1.0.0" # Sets version variable -# -scriptTemplateVersion="1.4.1" # Version of scriptTemplate.sh that this script is based on -# -# HISTORY: -# -# * 2015-06-21 - v1.0.0 - First Creation -# -# ################################################## - -# Provide a variable with the location of this script. -scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Source Scripting Utilities -# ----------------------------------- -# 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. -# ----------------------------------- - -utilsLocation="${scriptPath}/../lib/utils.sh" # Update this path to find the utilities. - -if [ -f "${utilsLocation}" ]; then - source "${utilsLocation}" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 -debug=0 -args=() - -# Set Temp Directory -# ----------------------------------- -# Create temp directory with three random numbers and the process ID -# in the name. This directory is removed automatically at exit. -# ----------------------------------- -tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" -(umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." -} - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $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() { -############## Begin Script Here ################### -#################################################### - -# Installing the Xcode command line tools on 10.7.x or higher - -osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}') -cmd_line_tools_temp_file="${tmpDir}/.com.apple.dt.CommandLineTools.installondemand.in-progress" - -# invoke verbose usage when set -if ${verbose}; then v="-v" ; fi - -# Installing the latest Xcode command line tools on 10.9.x or higher - -if [[ "${osx_vers}" -ge 9 ]]; then - - # Create the placeholder file which is checked by the softwareupdate tool - # before allowing the installation of the Xcode command line tools. - - touch "${cmd_line_tools_temp_file}" - - # Find the last listed update in the Software Update feed with "Command Line Tools" in the name - - cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) - - #Install the command line tools - - softwareupdate -i "${cmd_line_tools}" -v - - # Remove the temp file - - if [[ -f "${cmd_line_tools_temp_file}" ]]; then - rm ${v} "${cmd_line_tools_temp_file}" - fi -fi - -# Installing the latest Xcode command line tools on 10.7.x and 10.8.x - -# on 10.7/10.8, instead of using the software update feed, the command line tools are downloaded -# instead from public download URLs, which can be found in the dvtdownloadableindex: -# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex - -if [[ "${osx_vers}" -eq 7 ]] || [[ "${osx_vers}" -eq 8 ]]; then - - if [[ "${osx_vers}" -eq 7 ]]; then - DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg - fi - - if [[ "${osx_vers}" -eq 8 ]]; then - DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_osx_mountain_lion_april_2014.dmg - fi - - TOOLS=cltools.dmg - curl "${DMGURL}" -o "${TOOLS}" - TMPMOUNT=`/usr/bin/mktemp -d ${tmpDir}/clitools.XXXX` - hdiutil attach "${TOOLS}" -mountpoint "${TMPMOUNT}" -nobrowse - # The "-allowUntrusted" flag has been added to the installer - # command to accomodate for now-expired certificates used - # to sign the downloaded command line tools. - installer -allowUntrusted -pkg "$(find ${TMPMOUNT} -name '*.mpkg')" -target / - hdiutil detach "${TMPMOUNT}" - rm -rf ${v} "${TMPMOUNT}" - rm ${v} "${TOOLS}" -fi - -#################################################### -############### End Script Here #################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script will download and install the Xcode command line tools on Macs -running 10.7.x and higher. - -How the script works: - -On 10.9.x and 10.10.x: - -1. Creates a placeholder file in /tmp. This file's existence is checked by - the softwareupdate tool before allowing the installation of the Xcode command - line tools. - -2. Runs the softwareupdate tool and checks for the latest version of the Xcode - command line tools for the OS in question. - -3. Uses the softwareupdate tool to install the latest version of the Xcode command - line tools for the OS in question. - -4. Removes the placeholder file stored in /tmp. - - -On 10.7.x and 10.8.x: - -1. Uses curl to download a disk image containing the specified Xcode Command Line - Tools installer from Apple's web site - -2. Renames the downloaded disk image to cltools.dmg. - -2. Mounts the disk image silently in /tmp. Disk image will not be visible to any - logged-in user. - -3. Installs the Xcode Command Line Tools using the installer package stored on the -disk image - -4. After installation, unmounts the disk image and removes it from the Mac in question. - -This script was taken in its entirety from: -https://github.com/rtrouton/rtrouton_scripts/ - - Options: - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -d, --debug Runs script in BASH debug mode (set -x) - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed -# and --foo=bar into --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) ${version}"; safeExit ;; - -u|--username) shift; username=${1} ;; - -p|--password) shift; echo "Enter Pass: "; stty -echo; read PASS; stty echo; - echo ;; - -v|--verbose) verbose=true ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -d|--debug) debug=1;; - --force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - -# Store the remaining part as arguments. -args+=("$@") - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# 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 - -# Run in debug mode, if set -if [ "${debug}" == "1" ]; then - set -x -fi - -# Exit on empty variable -if [ "${strict}" == "1" ]; then - set -o nounset -fi - -# 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`, for example. -set -o pipefail - -# Invoke the checkDependenices function to test for Bash packages -# checkDependencies - -# Run your script -mainScript - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/macApps.sh b/setupScripts/macApps.sh deleted file mode 100755 index ea3c8a7..0000000 --- a/setupScripts/macApps.sh +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.0.1" # Version of scriptTemplate.sh -# that this script is based on -# -# This script installs Homebrew Casks - allowing for command line -# installation of native Mac Applications. Once Homebrew Casks is installed, -# this script then installs a number of applications. -# -# 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: -# -# * 2015-02-07 - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 - - -# 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 -# in the name. This directory is removed automatically at exit. - tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" - (umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." - } - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="$HOME/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### -header "Beginning ${scriptName}" - - -# Set Variables -LISTINSTALLED="brew cask list" -INSTALLCOMMAND="brew cask install --appdir=/Applications" - -RECIPES=( - alfred - arq - bartender - betterzipql - capo - carbon-copy-cloner - controlplane - default-folder-x - dropbox - evernote - fantastical - firefox - flux - fluid - google-chrome - hazel - houdahgeo - iterm2 - istat-menus - java - joinme - marked - mailplane - moom - nvalt - omnifocus - omnifocus-clip-o-tron - 1password - plex-home-theater - qlcolorcode - qlmarkdown - qlprettypatch - qlstephen - quicklook-csv - quicklook-json - skitch - spillo - sublime-text3 - textexpander - trickster - vlc - vyprvpn - webpquicklook - xld -) - -# Run Functions - -hasHomebrew -hasCasks -brewMaintenance -doInstall -brewCleanup - - -header "Completed ${scriptName}" -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script installs Homebrew Casks - allowing for command line -installation of native Mac Applications. Once Homebrew Casks is installed, -this script then installs a number of applications. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Exit on empty variable -if [ "${strict}" = "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/mackup.sh b/setupScripts/mackup.sh deleted file mode 100755 index 6b21875..0000000 --- a/setupScripts/mackup.sh +++ /dev/null @@ -1,300 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.1.0" # Version of scriptTemplate.sh -# that this script is based on -# -# This script installs Mackup, symlinks configuration files with Dropbox, -# and then runs Mackup Restore to use a shared configuration on a new computer. -# -# 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: -# -# * 2015-02-07 - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 -debug=0 - -# 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 -# in the name. This directory is removed automatically at exit. -tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" -(umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." -} - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="$HOME/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### -header "Beginning ${scriptName}" - - -# Variables from config file -if is_file "../etc/mackup.cfg"; then - source "../etc/mackup.cfg" - MACKUPDIR="${DIRCFG}" - TESTFILE="${TESTCFG}" -else - die "Can not run without config file. Please find mackup.cfg" -fi - -#Run Dropbox checking function -hasDropbox - -# Confirm we have Dropbox installed by checking for the existence of some synced files. -# IMPORTANT: As time moves, some of these files may be deleted. Ensure this list is kept up-to-date. -# This can be tested by running dropboxFileTest.sh script. - -if [ "${force}" = "0" ]; then #Bypass the Dropbox test when script is forced - if is_not_file "${TESTFILE}"; then - die "Could not find ${TESTFILE}. Exiting." - else - notice "Confirming that Dropbox has synced..." - while IFS= read -r file - do - while [ ! -e ${HOME}/"${file}" ] ; - do - info "...Waiting for Dropbox to Sync files." - sleep 10 - done - done < "${TESTFILE}" - fi - - #Add some additional time just to be sure.... - info "...Waiting for Dropbox to Sync files." - sleep 10 - info "...Waiting for Dropbox to Sync files." - sleep 10 - - # Sync Complete - success "Hooray! Dropbox has synced the necessary files." -fi - - -if type_not_exists 'mackup'; then - warning "Run 'brew install mackup' or run the Homebrew setup script." - die "MACKUP NOT FOUND." -else - verbose "Mackup is installed." -fi - -notice "Checking for Mackup config files..." -if is_not_symlink "$HOME/.mackup"; then - notice "Symlinking ~/.mackup" - ln -s "${MACKUPDIR}"/.mackup "$HOME"/.mackup -else - verbose "~/.mackup is symlinked" -fi -if is_not_symlink "${HOME}/.mackup.cfg"; then - notice "Symlinking ~/.mackup.cfg" - ln -s "${MACKUPDIR}"/.mackup.cfg "${HOME}"/.mackup.cfg -else - verbose "~/.mackup.cfg is symlinked" -fi -success "Mackup config files are symlinked." - -seek_confirmation "Run Mackup Restore?" -if is_confirmed; then - verbose "Running mackup restore" && mackup restore - header "All Done." -fi - - -header "Completed ${scriptName}" -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script installs Mackup, symlinks configuration files with Dropbox, -and then runs Mackup Restore to use a shared configuration on a new computer. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -d, --debug Runs script in BASH debug mode (set-x) - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -d|--debug) debug=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Run in debug mode, if set -if [ "${debug}" == "1" ]; then - set -x -fi - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Exit on empty variable -if [ "${strict}" = "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/newMacSetup.sh b/setupScripts/newMacSetup.sh index 79c7c91..afa27df 100755 --- a/setupScripts/newMacSetup.sh +++ b/setupScripts/newMacSetup.sh @@ -1,83 +1,928 @@ #!/usr/bin/env bash # ################################################## -# This script cycles through all my setup scripts to bootstrap a -# new computer. Run this script when you are starting fresh on -# a computer and it will take care of everything. # -# HISTORY -# * 2015-01-02 - Initial creation -# * 2015-06-21 - Added Flash and XCode command line tools +version="1.0.0" # Sets version variable +# +# HISTORY: +# +# * DATE - v1.0.0 - First Creation # # ################################################## -# Provide a variable with the location of this script. -scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Source Scripting Utilities +function mainScript() { + # invoke verbose usage when set + if ${verbose}; then v="-v" ; fi + + # Helper Functions + # ################### + function isAppInstalled() { + # Feed this function either the bundleID (com.apple.finder) or a name (finder) for a native + # mac app and it will determine whether it is installed or not + # + # usage: if isAppInstalled 'finder' &>/dev/null; then ... + # + # http://stackoverflow.com/questions/6682335/how-can-check-if-particular-application-software-is-installed-in-mac-os + + local appNameOrBundleId="$1" isAppName=0 bundleId + # Determine whether an app *name* or *bundle ID* was specified. + [[ $appNameOrBundleId =~ \.[aA][pP][pP]$ || $appNameOrBundleId =~ ^[^.]+$ ]] && isAppName=1 + if (( isAppName )); then # an application NAME was specified + # Translate to a bundle ID first. + bundleId=$(osascript -e "id of application \"$appNameOrBundleId\"" 2>/dev/null) || + { echo "$FUNCNAME: ERROR: Application with specified name not found: $appNameOrBundleId" 1>&2; return 1; } + else # a BUNDLE ID was specified + bundleId=$appNameOrBundleId + fi + # Let AppleScript determine the full bundle path. + osascript -e "tell application \"Finder\" to POSIX path of (get application file id \"$bundleId\" as alias)" 2>/dev/null || + { echo "$FUNCNAME: ERROR: Application with specified bundle ID not found: $bundleId" 1>&2; return 1; } + } + + function brewMaintenance () { + # brewMaintenance + # ------------------------------------------------------ + # Will run the recommended Homebrew maintenance scripts + # ------------------------------------------------------ + seek_confirmation "Run Homebrew maintenance?" + if is_confirmed; then + brew doctor + brew update + brew upgrade --all + fi + } + + function brewCleanup () { + # This function cleans up an initial Homebrew installation + + notice "Running Homebrew maintenance..." + + # This is where brew stores its binary symlinks + binroot="$(brew --config | awk '/HOMEBREW_PREFIX/ {print $2}')"/bin + + if [[ "$(type -P ${binroot}/bash)" && "$(cat /etc/shells | grep -q "$binroot/bash")" ]]; then + info "Adding ${binroot}/bash to the list of acceptable shells" + echo "$binroot/bash" | sudo tee -a /etc/shells >/dev/null + fi + if [[ "$SHELL" != "${binroot}/bash" ]]; then + info "Making ${binroot}/bash your default shell" + sudo chsh -s "${binroot}/bash" "$USER" >/dev/null 2>&1 + success "Please exit and restart all your shells." + fi + + brew cleanup + + if brew cask > /dev/null; then + brew cask cleanup + fi + } + + function doInstall () { + # Reads a list of items, checks if they are installed, installs + # those which are needed. + # + # Variables needed are: + # LISTINSTALLED: The command to list all previously installed items + # Ex: "brew list" or "gem list | awk '{print $1}'" + # + # INSTALLCOMMAND: The Install command for the desired items. + # Ex: "brew install" or "gem install" + # + # RECIPES: The list of packages to install. + # Ex: RECIPES=( + # package1 + # package2 + # ) + # + # Credit: https://github.com/cowboy/dotfiles + + + + function to_install() { + local desired installed i desired_s installed_s remain + # Convert args to arrays, handling both space- and newline-separated lists. + read -ra desired < <(echo "$1" | tr '\n' ' ') + read -ra installed < <(echo "$2" | tr '\n' ' ') + # Sort desired and installed arrays. + unset i; while read -r; do desired_s[i++]=$REPLY; done < <( + printf "%s\n" "${desired[@]}" | sort + ) + unset i; while read -r; do installed_s[i++]=$REPLY; done < <( + printf "%s\n" "${installed[@]}" | sort + ) + # Get the difference. comm is awesome. + unset i; while read -r; do remain[i++]=$REPLY; done < <( + comm -13 <(printf "%s\n" "${installed_s[@]}") <(printf "%s\n" "${desired_s[@]}") + ) + echo "${remain[@]}" + } + + function checkInstallItems() { + # If we are working with 'cask' we need to dedupe lists + # since apps might be installed by hand + if [[ $INSTALLCOMMAND =~ cask ]]; then + if isAppInstalled "${item}" &>/dev/null; then + continue + fi + fi + # If we installing from mas (mac app store), we need to dedupe the list AND + # sign in to the app store + if [[ $INSTALLCOMMAND =~ mas ]]; then + # Lookup the name of the application being installed + appName="$(curl -s https://itunes.apple.com/lookup?id=803453959 | jq .results[].trackName)" + if isAppInstalled "${appName}" &> /dev/null; then + continue + fi + # Tell the user the name of the app + notice "$item --> $appName" + fi + } + + # Log in to the Mac App Store if using mas + if [[ $INSTALLCOMMAND =~ mas ]]; then + mas signout + input "Please enter your Mac app store username: " + read macStoreUsername + input "Please enter your Mac app store password: " + read -s macStorePass + echo "" + mas signin $macStoreUsername "$macStorePass" + fi + + list=($(to_install "${RECIPES[*]}" "$(${LISTINSTALLED})")) + + if [ ${#list[@]} -gt 0 ]; then + seek_confirmation "Confirm each package before installing?" + if is_confirmed; then + for item in "${list[@]}"; do + checkInstallItems + seek_confirmation "Install ${item}?" + if is_confirmed; then + notice "Installing ${item}" + # FFMPEG takes additional flags + if [[ "${item}" = "ffmpeg" ]]; then + install-ffmpeg + elif [[ "${item}" = "tldr" ]]; then + brew tap tldr-pages/tldr + brew install tldr + else + ${INSTALLCOMMAND} "${item}" + fi + fi + done + else + for item in "${list[@]}"; do + checkInstallItems + notice "Installing ${item}" + # FFMPEG takes additional flags + if [[ "${item}" = "ffmpeg" ]]; then + install-ffmpeg + elif [[ "${item}" = "tldr" ]]; then + brew tap tldr-pages/tldr + brew install tldr + else + ${INSTALLCOMMAND} "${item}" + fi + done + fi + fi + } + + # Installation Commands + # ################### + function installCommandLineTools() { + notice "Checking for Command Line Tools..." + + if [[ ! "$(type -P gcc)" || ! "$(type -P make)" ]]; then + local osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}') + local cmdLineToolsTmp="${tmpDir}/.com.apple.dt.CommandLineTools.installondemand.in-progress" + + # Create the placeholder file which is checked by the software update tool + # before allowing the installation of the Xcode command line tools. + touch "${cmdLineToolsTmp}" + + # Find the last listed update in the Software Update feed with "Command Line Tools" in the name + cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) + + softwareupdate -i "${cmd_line_tools}" -v + + # Remove the temp file + if [ -f "${cmdLineToolsTmp}" ]; then + rm ${v} "${cmdLineToolsTmp}" + fi + fi + + success "Command Line Tools installed" + } + + function installHomebrew () { + # Check for Homebrew + notice "Checking for Homebrew..." + if [ ! "$(type -P brew)" ]; then + notice "No Homebrew. Gots to install it..." + # Ensure that we can actually, like, compile anything. + if [[ ! $(type -P gcc) && "$OSTYPE" =~ ^darwin ]]; then + notice "XCode or the Command Line Tools for XCode must be installed first." + installCommandLineTools + fi + # Check for Git + if [ ! "$(type -P git)" ]; then + notice "XCode or the Command Line Tools for XCode must be installed first." + installCommandLineTools + fi + # Install Homebrew + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + + installHomebrewTaps + fi + + success "Homebrew installed" + } + + function checkTaps() { + + verbose "Confirming we have required Homebrew taps" + if ! brew cask help &>/dev/null; then + installHomebrewTaps + fi + if [ ! "$(type -P mas)" ]; then + installHomebrewTaps + fi + } + + function installHomebrewTaps() { + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap argon/mas + brew tap caskroom/cask + brew tap caskroom/fonts + brew tap caskroom/versions + } + + function installXcode() { + notice "Checking for XCode..." + if ! isAppInstalled 'xcode' &>/dev/null; then + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + checkTaps + + LISTINSTALLED="mas list" + INSTALLCOMMAND="mas install" + RECIPES=( + 497799835 #xCode + ) + doInstall + + # we also accept the license + sudo xcodebuild -license accept + fi + + success "XCode installed" + } + + function installDropbox () { + # This function checks for Dropbox being installed. + # If it is not found, we install it and its prerequisites + notice "Checking for Dropbox..." + + checkTaps + + if ! isAppInstalled 'Dropbox' &>/dev/null; then + unset LISTINSTALLED INSTALLCOMMAND RECIPES + LISTINSTALLED="brew cask list" + INSTALLCOMMAND="brew cask install --appdir=/Applications" + RECIPES=( + dropbox + ) + doInstall + open -a dropbox + fi + + success "Dropbox installed" + } + + function installffmpeg () { + + notice "Checking for ffmpeg...." + # My preferred install of ffmpeg + if [ ! $(type -P "ffmpeg") ]; then + brew install ffmpeg --with-faac --with-fdk-aac --with-ffplay --with-fontconfig --with-freetype --with-libcaca --with-libass --with-frei0r --with-libass --with-libbluray --with-libcaca --with-libquvi --with-libvidstab --with-libsoxr --with-libssh --with-libvo-aacenc --with-libvidstab --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-webp --with-x265 + fi + + success "Done ffmpeg installed" + } + + function installCaskApps() { + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + notice "Checking for casks to install..." + + checkTaps + + LISTINSTALLED="brew cask list" + INSTALLCOMMAND="brew cask install --appdir=/Applications" + RECIPES=( + alfred + arq + bartender + betterzipql + carbon-copy-cloner + controlplane + dash + default-folder-x + fantastical + firefox + flux + fluid + google-chrome + hazel + houdahgeo + iterm2 + istat-menus + java + marked + mailplane + moom + nvalt + omnifocus + omnifocus-clip-o-tron + 1password + plex-home-theater + qlcolorcode + qlmarkdown + qlprettypatch + qlstephen + quicklook-csv + quicklook-json + skitch + spillo + sublime-text3 + textexpander + trickster + vlc + vyprvpn + webpquicklook + xld + ) + + # for item in "${RECIPES[@]}"; do + # info "$item" + # done + doInstall + + success "Done installing cask apps" + } + + function installAppStoreApps() { + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + notice "Checking for App Store apps to install..." + + checkTaps + + LISTINSTALLED="mas list" + INSTALLCOMMAND="mas install" + RECIPES=( + 836505650 # Battery Monitor + 420212497 # Byword + 696977615 # Capo + 411643860 # DaisyDisk + 498944723 # JPEGmini + 711830901 # OmniGraffle + 429449079 # Patterns - RegEx Validation + 445189367 # PopClip + 803453959 # Slack + 403388562 # Transmit + 494803304 # WiFi Explorer + 848311469 # Write + ) + doInstall + + success "Done installing app store apps" + } + + function installDevApps() { + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + notice "Checking for dev apps to install" + + checkTaps + + LISTINSTALLED="brew cask list" + INSTALLCOMMAND="brew cask install --appdir=/Applications" + RECIPES=( + charles + codekit + github + imagealpha + imageoptim + java + kaleidoscope + licecap # Movie screen captures + mamp # mac-based LAMP development stack + paw # REST IDE + tower # Mac GUI for git + ) + + # for item in "${RECIPES[@]}"; do + # info "$item" + # done + doInstall + + success "Done installing dev apps" + } + + function installHomebrewPackages() { + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + notice "Checking for Homebrew packages to install..." + + checkTaps + + LISTINSTALLED="brew list" + INSTALLCOMMAND="brew install" + + RECIPES=( + autoconf + automake + bash + bash-completion + colordiff + coreutils + ffmpeg + gifsicle + git + git-extras + git-flow + hub + hr + id3tool + imagemagick + jpegoptim + jq + lesspipe + libksba + libtool + libyaml + mackup + man2html + multimarkdown + node + openssl + optipng + pkg-config + pngcrush + p7zip + readline + rename + shellcheck # Bash linter + sl + source-highlight + ssh-copy-id + sqlite + tag + terminal-notifier + tldr # Better man pages + tree + unison # Rsynch like tool + ) + + doInstall + + success "Done installing Homebrew packages" + } + + function installRuby() { + + notice "Checking for RVM (Ruby Version Manager)..." + + local RUBYVERSION="2.1.2" # Version of Ruby to install via RVM + + # Check for RVM + if [ ! "$(type -P rvm)" ]; then + seek_confirmation "Couldn't find RVM. Install it?" + if is_confirmed; then + curl -L https://get.rvm.io | bash -s stable + source "${HOME}/.rvm/scripts/rvm" + source "${HOME}/.bash_profile" + #rvm get stable --autolibs=enable + rvm install ${RUBYVERSION} + rvm use ${RUBYVERSION} --default + fi + fi + + success "RVM and Ruby are installed" + } + + function installRubyGems() { + unset LISTINSTALLED INSTALLCOMMAND RECIPES + + notice "Checking for Ruby gems..." + + LISTINSTALLED="gem list | awk '{print $1}'" + INSTALLCOMMAND="gem install" + + RECIPES=( + bundler + classifier + compass + digest + fileutils + jekyll + kramdown + kss + less + logger + mini_magick + rake + reduce + s3_website + sass + smusher + ) + + doInstall + + success "Done installing Ruby Gems" + } + + function configureSSH() { + notice "Configuring SSH" + + info "Checking for SSH key in ~/.ssh/id_rsa.pub, generating one if it doesn't exist" + [[ -f "${HOME}/.ssh/id_rsa.pub" ]] || ssh-keygen -t rsa + + info "Copying public key to clipboard" + [[ -f "${HOME}/.ssh/id_rsa.pub" ]] && cat "${HOME}/.ssh/id_rsa.pub" | pbcopy + + # Add SSH keys to Github + seek_confirmation "Add SSH key to Github?" + if is_confirmed; then + info "Paste the key into Github" + + open https://github.com/account/ssh + + seek_confirmation "Test Github Authentication via ssh?" + if is_confirmed; then + info "Note that even when successful, this will fail the script." + ssh -T git@github.com + fi + fi + + success "SSH Configured" + } + + function configureMackup() { + notice "Running mackup config..." + + local DIRCFG="${HOME}/Dropbox/sharedConfiguration/Mackup" + + installDropbox + + dropboxFilesTest=( + "Dropbox/sharedConfiguration/Mackup/Library/Application Support/PaxGalaxia/net.txt" + "Dropbox/sharedConfiguration/Mackup/Pictures/DeviantartBackup/clouds2.jpg" + "Dropbox/sharedConfiguration/Mackup/Library/init/bash/aliases.bash" + "Dropbox/sharedConfiguration/Mackup/Downloads" + "Dropbox/sharedConfiguration/Mackup/.mackup/my-files.cfg" + "Dropbox/sharedConfiguration/App Configuration Files/Alfred2/Alfred.alfredpreferences" + "Dropbox/sharedConfiguration/Mackup/Library/Preferences/com.dustinrue.ControlPlane.plist" + ) + + + info "Confirming that Dropbox has synced by looking for files..." + info "(This might fail if the list of files is out of date)" + + for dropboxFile in "${dropboxFilesTest[@]}"; do + verbose "Checking: $dropboxFile" + while [ ! -e "${HOME}/${dropboxFile}" ]; do + info " Waiting for Dropbox to Sync files..." + sleep 10 + done + done + + Add some additional time just to be sure.... + for ((i=1; i<=6; i++)); do + info " Waiting for Dropbox to Sync files..." + sleep 10 + done + + # Sync Complete + success "Dropbox has synced" + + # Confirm Mackup exists + if [ ! "$(type -P mackup)" ]; then + installHomebrew + brew install mackup + fi + + notice "Checking for Mackup config files..." + if [ ! -L "${HOME}/.mackup" ]; then + info "Symlinking ~/.mackup" + ln -s "${MACKUPDIR}/.mackup" "${HOME}/.mackup" + else + verbose "${HOME}/.mackup is symlinked" + fi + if [ ! -L "${HOME}/.mackup.cfg" ]; then + info "Symlinking ~/.mackup.cfg" + ln -s "${MACKUPDIR}"/.mackup.cfg "${HOME}"/.mackup.cfg + else + verbose "~${HOME}.mackup.cfg is symlinked" + fi + success "Mackup config files are symlinked" + + seek_confirmation "Run Mackup Restore?" + if is_confirmed; then + mackup restore + fi + } + + + # ################### + # Run the script + # ################### + + # Ask for the administrator password upfront + sudo -v + + # installCommandLineTools + # installHomebrew + # checkTaps + # brewCleanup + # installXcode + # installDropbox + # installCaskApps + installAppStoreApps + # installDevApps + # installHomebrewPackages + # installRuby + # installRubyGems + # configureSSH + # configureMackup +} + +## SET SCRIPTNAME VARIABLE ## +scriptName=$(basename "$0") + +function trapCleanup() { + # trapCleanup Function + # ----------------------------------- + # Any actions that should be taken if the script is prematurely + # exited. Always call this function at the top of your script. + # ----------------------------------- + echo "" + # Delete temp files, if any + if [ -d "${tmpDir}" ] ; then + rm -r "${tmpDir}" + fi + die "Exit trapped." +} + +function safeExit() { + # safeExit + # ----------------------------------- + # Non destructive exit for when script exits naturally. + # Usage: Add this function at the end of every script. + # ----------------------------------- + # Delete temp files, if any + if [ -d "${tmpDir}" ] ; then + rm -r "${tmpDir}" + fi + trap - INT TERM EXIT + exit +} + +function seek_confirmation() { + # Asks questions of a user and then does something with the answer. + # y/n are the only possible answers. + # + # USAGE: + # seek_confirmation "Ask a question" + # if is_confirmed; then + # some action + # else + # some other action + # fi + # + # Credt: https://github.com/kevva/dotfiles + # ------------------------------------------------------ + # echo "" + input "$@" + read -p " (y/n) " -n 1 + echo "" +} + +function is_confirmed() { + if [[ "${REPLY}" =~ ^[Yy]$ ]]; then + return 0 + fi + return 1 +} + +function is_not_confirmed() { + if [[ "${REPLY}" =~ ^[Nn]$ ]]; then + return 0 + fi + return 1 +} + +# Set Flags # ----------------------------------- -# 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. +# Flags which can be overridden by user input. +# Default values are below # ----------------------------------- +quiet=false +printLog=false +verbose=false +force=false +strict=false +debug=false +args=() -utilsLocation="${scriptPath}/../lib/utils.sh" # Update this path to find the utilities. +# Set Temp Directory +# ----------------------------------- +# Create temp directory with three random numbers and the process ID +# in the name. This directory is removed automatically at exit. +# ----------------------------------- +tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" +(umask 077 && mkdir "${tmpDir}") || { + die "Could not create temporary directory! Exiting." +} -if [ -f "${utilsLocation}" ]; then - source "${utilsLocation}" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi +# Logging +# ----------------------------------- +# Log is only used when the '-l' flag is set. +# +# To never save a logfile change variable to '/dev/null' +# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log +# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log +# ----------------------------------- +logFile="${HOME}/Library/Logs/${scriptBasename}.log" -seek_confirmation "Do you want to run the Dropbox script to install it first?" -if is_confirmed; then - if is_file "./dropbox.sh"; then - ./dropbox.sh - else - error "Can't find dropbox.sh" - seek_confirmation "Continue running other scripts?" - if is_not_confirmed; then - warning "Exiting." - exit 0 - fi - fi -fi +# Options and Usage +# ----------------------------------- +# Print usage +usage() { + echo -n "${scriptName} [OPTION]... [FILE]... -#List of Scripts to be run -FILES=" - ./install_command_line_tools.sh - ./homebrew.sh - ./macApps.sh - ./devApps.sh - ./ruby.sh - ./mackup.sh - ./osx.sh - ./ssh.sh - ./install_latest_adobe_flash_player.sh +This is a script template. Edit this description to print help to users. + + ${bold}Options:${reset} + -u, --username Username for script + -p, --password User password + --force Skip all user interaction. Implied 'Yes' to all actions. + -q, --quiet Quiet (no output) + -l, --log Print log to file + -s, --strict Exit script with null variables. i.e 'set -o nounset' + -v, --verbose Output more information. (Items echoed to 'verbose') + -d, --debug Runs script in BASH debug mode (set -x) + -h, --help Display this help and exit + --version Output version information and exit " +} -seek_confirmation "Do you want to run all the scripts at once?" -if is_confirmed; then - for file in "${FILES}" - do - if is_file "${file}"; then - ${file} - else - die "${file} does not exist. Exiting" - fi - done -else -for file in "${FILES}" - do - seek_confirmation "Do you want to run ${file}?" - if is_confirmed; then - if is_file "${file}"; then - ${file} - else - die "${file} does not exist." - fi - fi - done -fi +# Iterate over options breaking -ab into -a -b when needed and --foo=bar into +# --foo bar +optstring=h +unset options +while (($#)); do + case $1 in + # If option is of type -ab + -[!-]?*) + # Loop over each character starting with the second + for ((i=1; i < ${#1}; i++)); do + c=${1:i:1} + + # Add current char to options + options+=("-$c") + + # If option takes a required argument, and it's not the last char make + # the rest of the string its argument + if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then + options+=("${1:i+1}") + break + fi + done + ;; + + # If option is of type --foo=bar + --?*=*) options+=("${1%%=*}" "${1#*=}") ;; + # add --endopts for -- + --) options+=(--endopts) ;; + # Otherwise, nothing special + *) options+=("$1") ;; + esac + shift +done +set -- "${options[@]}" +unset options + +# Print help if no arguments were passed. +# Uncomment to force arguments when invoking the script +# ------------------------------------- +# [[ $# -eq 0 ]] && set -- "--help" + +# Read the options and set stuff +while [[ $1 = -?* ]]; do + case $1 in + -h|--help) usage >&2; safeExit ;; + --version) echo "$(basename $0) ${version}"; safeExit ;; + -u|--username) shift; username=${1} ;; + -p|--password) shift; echo "Enter Pass: "; stty -echo; read PASS; stty echo; + echo ;; + -v|--verbose) verbose=true ;; + -l|--log) printLog=true ;; + -q|--quiet) quiet=true ;; + -s|--strict) strict=true;; + -d|--debug) debug=true;; + --force) force=true ;; + --endopts) shift; break ;; + *) die "invalid option: '$1'." ;; + esac + shift +done + +# Store the remaining part as arguments. +args+=("$@") + + +# Logging and Colors +# ----------------------------------------------------- +# Here we set the colors for our script feedback. +# Example usage: success "sometext" +#------------------------------------------------------ + +# Set Colors +bold=$(tput bold) +reset=$(tput sgr0) +purple=$(tput setaf 171) +red=$(tput setaf 1) +green=$(tput setaf 76) +tan=$(tput setaf 3) +blue=$(tput setaf 38) +underline=$(tput sgr 0 1) + +function _alert() { + if [ "${1}" = "emergency" ]; then local color="${bold}${red}"; fi + if [ "${1}" = "error" ]; then local color="${bold}${red}"; fi + if [ "${1}" = "warning" ]; then local color="${red}"; fi + if [ "${1}" = "success" ]; then local color="${green}"; fi + if [ "${1}" = "debug" ]; then local color="${purple}"; fi + if [ "${1}" = "header" ]; then local color="${bold}""${tan}"; fi + if [ "${1}" = "input" ]; then local color="${bold}"; printLog="false"; fi + if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then local color=""; fi + # Don't use colors on pipes or non-recognized terminals + if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then color=""; reset=""; fi + + # Print to $logFile + if ${printLog}; then + echo -e "$(date +"%m-%d-%Y %r") $(printf "[%9s]" "${1}") ${_message}" >> "${logFile}"; + fi + + # Print to console when script is not 'quiet' + if ${quiet}; then + return + else + echo -e "$(date +"%r") ${color}$(printf "[%9s]" "${1}") ${_message}${reset}"; + fi +} + +function die () { local _message="${*} Exiting."; echo "$(_alert emergency)"; safeExit;} +function error () { local _message="${*}"; echo "$(_alert error)"; } +function warning () { local _message="${*}"; echo "$(_alert warning)"; } +function notice () { local _message="${*}"; echo "$(_alert notice)"; } +function info () { local _message="${*}"; echo "$(_alert info)"; } +function debug () { local _message="${*}"; echo "$(_alert debug)"; } +function success () { local _message="${*}"; echo "$(_alert success)"; } +function input() { local _message="${*}"; echo -n "$(_alert input)"; } +function header() { local _message="${*}"; echo "$(_alert header)"; } + +# Log messages when verbose is set to "true" +verbose() { if ${verbose}; then debug "$@"; fi } + +# Trap bad exits with your cleanup function +trap trapCleanup EXIT INT TERM + +# 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 + +# Run in debug mode, if set +if ${debug}; then set -x ; fi + +# Exit on empty variable +if ${strict}; then set -o nounset ; fi + +# 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`, for example. +set -o pipefail + +# Run your script +mainScript + +# Exit cleanly +safeExit \ No newline at end of file diff --git a/setupScripts/ruby.sh b/setupScripts/ruby.sh deleted file mode 100755 index ee794bc..0000000 --- a/setupScripts/ruby.sh +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.1.0" # Version of scriptTemplate.sh that this script is based on -# v.1.1.0 - Added 'debug' option -# -# This script will install Ruby and RVM via Homebrew -# -# 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: -# -# * DATE - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 -debug=0 - - -# 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 -# in the name. This directory is removed automatically at exit. - tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" - (umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." - } - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="${HOME}/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### -header "Beginning ${scriptBasename}" - - -# Set Variables -LISTINSTALLED="gem list | awk '{print ${1}}'" -INSTALLCOMMAND="gem install" -RUBYVERSION="2.1.2" - - -# Check for RVM -if type_not_exists "rvm"; then - seek_confirmation "Install RVM?" - if is_confirmed; then - warning "Installing RVM (Ruby Version Manager) and Ruby which becomes the default ..." - curl -L https://get.rvm.io | bash -s stable - source "~/.rvm/scripts/rvm" - fi -fi - -#Install Ruby -if type_exists "rvm"; then - seek_confirmation "You have RVM already. Check for a newer version?" - if is_confirmed; then - source ${HOME}/.bash_profile - #rvm get stable --autolibs=enable - rvm install ${RUBYVERSION} - rvm use ${RUBYVERSION} --default - fi -fi - -RECIPES=( - bundler - classifier - compass - digest - fileutils - jekyll - kramdown - kss - less - logger - mini_magick - rake - reduce - s3_website - sass - smusher -) - -# Run Functions - -hasHomebrew -doInstall - -#update gems -notice "Updating installed Gems" -gem update --system -gem update - - -header "Ending ${scriptBasename}" -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script installs Ruby and RVM via Homebrew as well as a number of Gems. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -d, --debug Runs script in BASH debug mode (set -x) - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -d|--debug) debug=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Run in debug mode, if set -if [ "${debug}" == "1" ]; then - set -x -fi - -# Exit on empty variable -if [ "${strict}" == "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file diff --git a/setupScripts/ssh.sh b/setupScripts/ssh.sh deleted file mode 100755 index 54839de..0000000 --- a/setupScripts/ssh.sh +++ /dev/null @@ -1,252 +0,0 @@ -#!/usr/bin/env bash - -# ################################################## -# My Generic BASH script template -# -version="1.0.0" # Sets version variable for this script -# -scriptTemplateVersion="1.1.0" # Version of scriptTemplate.sh that this script is based on -# v.1.1.0 - Added 'debug' option -# -# This script creates an SSH key on a mac and then sends it to GitHub. -# -# 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: -# -# * DATE - v1.0.0 - First Creation -# -# ################################################## - -# Source Scripting Utilities -# ----------------------------------- -# If these can't be found, update the path to the file -# ----------------------------------- -SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f "${SCRIPTDIR}/../lib/utils.sh" ]; then - source "${SCRIPTDIR}/../lib/utils.sh" -else - echo "Please find the file util.sh and add a reference to it in this script. Exiting." - exit 1 -fi - -# trapCleanup Function -# ----------------------------------- -# Any actions that should be taken if the script is prematurely -# exited. Always call this function at the top of your script. -# ----------------------------------- -function trapCleanup() { - echo "" - if is_dir "${tmpDir}"; then - rm -r "${tmpDir}" - fi - die "Exit trapped." # Edit this if you like. -} - -# Set Flags -# ----------------------------------- -# Flags which can be overridden by user input. -# Default values are below -# ----------------------------------- -quiet=0 -printLog=0 -verbose=0 -force=0 -strict=0 -debug=0 - - -# 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 -# in the name. This directory is removed automatically at exit. - tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$" - (umask 077 && mkdir "${tmpDir}") || { - die "Could not create temporary directory! Exiting." - } - -# Logging -# ----------------------------------- -# Log is only used when the '-l' flag is set. -# -# To never save a logfile change variable to '/dev/null' -# Save to Desktop use: $HOME/Desktop/${scriptBasename}.log -# Save to standard user log location use: $HOME/Library/Logs/${scriptBasename}.log -# ----------------------------------- -logFile="$HOME/Library/Logs/${scriptBasename}.log" - - -function mainScript() { -############## Begin Script Here ################### - -header "Beginning ${scriptBasename}" - -notice "Checking for SSH key in ~/.ssh/id_rsa.pub, generating one if it doesn't exist." -[[ -f ~/.ssh/id_rsa.pub ]] || ssh-keygen -t rsa - -notice "Copying public key to clipboard." -[[ -f ~/.ssh/id_rsa.pub ]] && cat ~/.ssh/id_rsa.pub | pbcopy - -# Add SSH keys to Github -info "Running Github integration" -seek_confirmation "Open https://github.com/account/ssh in your browser?" -if is_confirmed; then - notice "Copying public key to clipboard." - - [[ -f ~/.ssh/id_rsa.pub ]] && cat ~/.ssh/id_rsa.pub | pbcopy - - open https://github.com/account/ssh - - seek_confirmation "Test Github Authentication via ssh?" - if is_confirmed; then - notice "Testing..." - ssh -T git@github.com - fi -fi - -header "Completed ${scriptBasename}" - -############## End Script Here ################### -} - -############## Begin Options and Usage ################### - - -# Print usage -usage() { - echo -n "${scriptName} [OPTION]... [FILE]... - -This script creates an SSH key on a mac and then sends it to GitHub. - - Options: - -f, --force Skip all user interaction. Implied 'Yes' to all actions - -q, --quiet Quiet (no output) - -l, --log Print log to file - -s, --strict Exit script with null variables. i.e 'set -o nounset' - -v, --verbose Output more information. (Items echoed to 'verbose') - -d, --debug Runs script in BASH debug mode (set -x) - -h, --help Display this help and exit - --version Output version information and exit -" -} - -# Iterate over options breaking -ab into -a -b when needed and --foo=bar into -# --foo bar -optstring=h -unset options -while (($#)); do - case $1 in - # If option is of type -ab - -[!-]?*) - # Loop over each character starting with the second - for ((i=1; i < ${#1}; i++)); do - c=${1:i:1} - - # Add current char to options - options+=("-$c") - - # If option takes a required argument, and it's not the last char make - # the rest of the string its argument - if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then - options+=("${1:i+1}") - break - fi - done - ;; - - # If option is of type --foo=bar - --?*=*) options+=("${1%%=*}" "${1#*=}") ;; - # add --endopts for -- - --) options+=(--endopts) ;; - # Otherwise, nothing special - *) options+=("$1") ;; - esac - shift -done -set -- "${options[@]}" -unset options - -# Print help if no arguments were passed. -# Uncomment to force arguments when invoking the script -# [[ $# -eq 0 ]] && set -- "--help" - -# Read the options and set stuff -while [[ $1 = -?* ]]; do - case $1 in - -h|--help) usage >&2; safeExit ;; - --version) echo "$(basename $0) $version"; safeExit ;; - -u|--username) shift; username=$1 ;; - -p|--password) shift; password=$1 ;; - -v|--verbose) verbose=1 ;; - -l|--log) printLog=1 ;; - -q|--quiet) quiet=1 ;; - -s|--strict) strict=1;; - -d|--debug) debug=1;; - -f|--force) force=1 ;; - --endopts) shift; break ;; - *) die "invalid option: '$1'." ;; - esac - shift -done - - -############## End Options and Usage ################### - - - - -# ############# ############# ############# -# ## TIME TO RUN THE SCRIPT ## -# ## ## -# ## You shouldn't need to edit anything ## -# ## beneath this line ## -# ## ## -# ############# ############# ############# - -# Trap bad exits with your cleanup function -trap trapCleanup EXIT INT TERM - -# Exit on error. Append ||true if you expect an error. -set -o errexit - -# Run in debug mode, if set -if [ "${debug}" == "1" ]; then - set -x -fi - -# Exit on empty variable -if [ "${strict}" == "1" ]; then - set -o nounset -fi - -# 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` -set -o pipefail - - -mainScript # Run your script - -safeExit # Exit cleanly \ No newline at end of file