mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-09 13:43:46 -05:00
First commit
This commit is contained in:
4
etc/.gitignore
vendored
Normal file
4
etc/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*
|
||||||
|
|
||||||
|
!.gitignore
|
||||||
|
!.README.md
|
||||||
206
lib/setupScriptFunctions.sh
Executable file
206
lib/setupScriptFunctions.sh
Executable file
@@ -0,0 +1,206 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# Shared bash functions used by my mac setup scripts.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - Initial creation
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
|
||||||
|
# hasHomebrew
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# This function checks for Homebrew being installed.
|
||||||
|
# If it is not found, we install it and its prerequisites
|
||||||
|
# ------------------------------------------------------
|
||||||
|
hasHomebrew () {
|
||||||
|
# Check for Homebrew
|
||||||
|
if type_not_exists 'brew'; then
|
||||||
|
e_error "No Homebrew. Gots to install it."
|
||||||
|
seek_confirmation "Install Homebrew?"
|
||||||
|
if is_confirmed; then
|
||||||
|
# Ensure that we can actually, like, compile anything.
|
||||||
|
if [[ ! "$(type -P gcc)" && "$OSTYPE" =~ ^darwin ]]; then
|
||||||
|
e_error "XCode or the Command Line Tools for XCode must be installed first."
|
||||||
|
seek_confirmation "Install Command Line Tools from here?"
|
||||||
|
if is_confirmed; then
|
||||||
|
xcode-select --install
|
||||||
|
else
|
||||||
|
e_error "Please come back after Command Line Tools are installed. Exiting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# Check for Git
|
||||||
|
if type_not_exists 'git'; then
|
||||||
|
e_error "Git should be installed. It isn't. Aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Install Homebrew
|
||||||
|
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||||
|
brew tap homebrew/dupes
|
||||||
|
brew tap homebrew/versions
|
||||||
|
brew tap phinze/homebrew-cask
|
||||||
|
else
|
||||||
|
e_error "Without Homebrew installed we won't get very far."
|
||||||
|
e_error "Exiting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# brewMaintenance
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Will run the recommended Homebrew maintenance scripts
|
||||||
|
# ------------------------------------------------------
|
||||||
|
brewMaintenance () {
|
||||||
|
seek_confirmation "Run Homebrew maintenance?"
|
||||||
|
if is_confirmed; then
|
||||||
|
brew doctor
|
||||||
|
brew update
|
||||||
|
brew upgrade
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# hasCasks
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# This function checks for Homebrew Casks and Fonts being installed.
|
||||||
|
# If it is not found, we install it and its prerequisites
|
||||||
|
# ------------------------------------------------------
|
||||||
|
hasCasks () {
|
||||||
|
if ! $(brew cask > /dev/null); then
|
||||||
|
brew install caskroom/cask/brew-cask
|
||||||
|
brew tap caskroom/fonts
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# ------------------------------------------------------
|
||||||
|
|
||||||
|
# Given a list of desired items and installed items, return a list
|
||||||
|
# of uninstalled items.
|
||||||
|
# Credit: https://github.com/cowboy/dotfiles
|
||||||
|
function to_install() {
|
||||||
|
local debug desired installed i desired_s installed_s remain
|
||||||
|
if [[ "$1" == 1 ]]; then debug=1; shift; fi
|
||||||
|
# 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[@]}")
|
||||||
|
)
|
||||||
|
[[ "$debug" ]] && for v in desired desired_s installed installed_s remain; do
|
||||||
|
echo "$v ($(eval echo "\${#$v[*]}")) $(eval echo "\${$v[*]}")"
|
||||||
|
done
|
||||||
|
echo "${remain[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install the desired items that are not already installed.
|
||||||
|
function doInstall () {
|
||||||
|
list="$(to_install "${RECIPES[*]}" "$($LISTINSTALLED)")"
|
||||||
|
if [[ "$list" ]]; then
|
||||||
|
seek_confirmation "Confirm each install before running?"
|
||||||
|
if is_confirmed; then
|
||||||
|
for item in ${list[@]}
|
||||||
|
do
|
||||||
|
seek_confirmation "Install $item?"
|
||||||
|
if is_confirmed; then
|
||||||
|
$INSTALLCOMMAND $item
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
for item in ${list[@]}
|
||||||
|
do
|
||||||
|
$INSTALLCOMMAND $item
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
e_success "Nothing to install. You've already got them all."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# brewCleanup
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# This function cleans up an initial Homebrew installation
|
||||||
|
# ------------------------------------------------------
|
||||||
|
brewCleanup () {
|
||||||
|
# This is where brew stores its binary symlinks
|
||||||
|
binroot="$(brew --config | awk '/HOMEBREW_PREFIX/ {print $2}')"/bin
|
||||||
|
|
||||||
|
# htop
|
||||||
|
if [[ "$(type -P $binroot/htop)" && "$(stat -L -f "%Su:%Sg" "$binroot/htop")" != "root:wheel" || ! "$(($(stat -L -f "%DMp" "$binroot/htop") & 4))" ]]; then
|
||||||
|
e_header "Updating htop permissions"
|
||||||
|
sudo chown root:wheel "$binroot/htop"
|
||||||
|
sudo chmod u+s "$binroot/htop"
|
||||||
|
fi
|
||||||
|
if [[ "$(type -P $binroot/bash)" && "$(cat /etc/shells | grep -q "$binroot/bash")" ]]; then
|
||||||
|
e_header "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
|
||||||
|
e_header "Making $binroot/bash your default shell"
|
||||||
|
sudo chsh -s "$binroot/bash" "$USER" >/dev/null 2>&1
|
||||||
|
e_success "Please exit and restart all your shells."
|
||||||
|
fi
|
||||||
|
brew cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
# hasDropbox
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# This function checks for Dropbox being installed.
|
||||||
|
# If it is not found, we install it and its prerequisites
|
||||||
|
# ------------------------------------------------------
|
||||||
|
hasDropbox () {
|
||||||
|
# Confirm we have Dropbox installed
|
||||||
|
e_arrow "Confirming that Dropbox is installed..."
|
||||||
|
if [ ! -e /Applications/Dropbox.app ]; then
|
||||||
|
e_error "We don't have Dropbox. Let's get it installed."
|
||||||
|
seek_confirmation "Install Dropbox and all necessary prerequisites?"
|
||||||
|
if is_confirmed; then
|
||||||
|
# Run functions
|
||||||
|
hasHomebrew
|
||||||
|
brewMaintenance
|
||||||
|
hasCasks
|
||||||
|
|
||||||
|
# Set Variables
|
||||||
|
local LISTINSTALLED="brew cask list"
|
||||||
|
local INSTALLCOMMAND="brew cask install --appdir=/Applications"
|
||||||
|
|
||||||
|
local RECIPES=(dropbox)
|
||||||
|
Install
|
||||||
|
open -a dropbox
|
||||||
|
else
|
||||||
|
e_error "Can't run this script. Install Dropbox manually. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
e_success "Dropbox is installed."
|
||||||
|
fi
|
||||||
|
}
|
||||||
288
lib/sharedFunctions.sh
Executable file
288
lib/sharedFunctions.sh
Executable file
@@ -0,0 +1,288 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# Shared bash functions used by my bash scripts.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - Initial creation
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
# readFile
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Function to read a line from a file.
|
||||||
|
#
|
||||||
|
# Most often used to read the config files saved in my etc directory.
|
||||||
|
# Outputs each line in a variable named $result
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function readFile() {
|
||||||
|
unset $result
|
||||||
|
while read result
|
||||||
|
do
|
||||||
|
echo $result
|
||||||
|
done < "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# needSudo
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# If a script needs sudo access, call this function which
|
||||||
|
# requests sudo access and then keeps it alive.
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function needSudo() {
|
||||||
|
# Update existing sudo time stamp if set, otherwise do nothing.
|
||||||
|
sudo -v
|
||||||
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
||||||
|
}
|
||||||
|
|
||||||
|
# die
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# "die function" - used to denote a failed action in a script.
|
||||||
|
# usage: cd some/path || die "cd failed"
|
||||||
|
# ------------------------------------------------------
|
||||||
|
die() {
|
||||||
|
e_error "FATAL ERROR: $* (status $?)" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# convertsecs
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Convert Seconds to human readable time
|
||||||
|
#
|
||||||
|
# To use this, pass a number (seconds) into the function as this:
|
||||||
|
# print "$(convertsecs $TOTALTIME)"
|
||||||
|
#
|
||||||
|
# To compute the time it takes a script to run use tag the start and end times with
|
||||||
|
# STARTTIME=$(date +"%s")
|
||||||
|
# ENDTIME=$(date +"%s")
|
||||||
|
# TOTALTIME=$(($ENDTIME-$STARTTIME))
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function convertsecs() {
|
||||||
|
((h=${1}/3600))
|
||||||
|
((m=(${1}%3600)/60))
|
||||||
|
((s=${1}%60))
|
||||||
|
printf "%02d:%02d:%02d\n" $h $m $s
|
||||||
|
}
|
||||||
|
|
||||||
|
# pushover
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Sends notifications view Pushover
|
||||||
|
# Requires a file named 'pushover.cfg' be placed in '../etc/'
|
||||||
|
#
|
||||||
|
# Usage: pushover "Title Goes Here" "Message Goes Here"
|
||||||
|
#
|
||||||
|
# Credit: http://ryonsherman.blogspot.com/2012/10/shell-script-to-send-pushover.html
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function pushover() {
|
||||||
|
# Check for config file
|
||||||
|
if [ ! -f "../etc/pushover.cfg" ]; then
|
||||||
|
e_error "Please locate the pushover.cfg to send notifications to Pushover"
|
||||||
|
else
|
||||||
|
# Grab variables from the config file
|
||||||
|
source "../etc/pushover.cfg"
|
||||||
|
|
||||||
|
# Send to Pushover
|
||||||
|
PUSHOVERURL="https://api.pushover.net/1/messages.json"
|
||||||
|
API_KEY="$PUSHOVER_API_KEY"
|
||||||
|
USER_KEY="$PUSHOVER_USER_KEY"
|
||||||
|
DEVICE=""
|
||||||
|
TITLE="${1}"
|
||||||
|
MESSAGE="${2}"
|
||||||
|
curl \
|
||||||
|
-F "token=${API_KEY}" \
|
||||||
|
-F "user=${USER_KEY}" \
|
||||||
|
-F "device=${DEVICE}" \
|
||||||
|
-F "title=${TITLE}" \
|
||||||
|
-F "message=${MESSAGE}" \
|
||||||
|
"${PUSHOVERURL}" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# File Checks
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# A series of functions which make checks against the filesystem. For
|
||||||
|
# use in if/then statements.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# if is_file; then
|
||||||
|
# ...
|
||||||
|
# fi
|
||||||
|
# ------------------------------------------------------
|
||||||
|
|
||||||
|
function is_exists() {
|
||||||
|
if [[ -e "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_not_exists() {
|
||||||
|
if [[ ! -e "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_file() {
|
||||||
|
if [[ -f "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_not_file() {
|
||||||
|
if [[ ! -f "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_dir() {
|
||||||
|
if [[ -d "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_not_dir() {
|
||||||
|
if [[ ! -d "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_symlink() {
|
||||||
|
if [[ -L "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_not_symlink() {
|
||||||
|
if [[ ! -L "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_empty() {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_not_empty() {
|
||||||
|
if [[ -n "$1" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test whether a command exists
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Usage:
|
||||||
|
# if type_exists 'git'; then
|
||||||
|
# some action
|
||||||
|
# else
|
||||||
|
# some other action
|
||||||
|
# fi
|
||||||
|
# ------------------------------------------------------
|
||||||
|
|
||||||
|
function type_exists() {
|
||||||
|
if [ $(type -P $1) ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function type_not_exists() {
|
||||||
|
if [ ! $(type -P $1) ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test which OS the user runs
|
||||||
|
# $1 = OS to test
|
||||||
|
# Usage: if is_os 'darwin'; then
|
||||||
|
|
||||||
|
function is_os() {
|
||||||
|
if [[ "${OSTYPE}" == $1* ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# SEEKING 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
|
||||||
|
# ------------------------------------------------------
|
||||||
|
|
||||||
|
# Ask the question
|
||||||
|
function seek_confirmation() {
|
||||||
|
printf "\n${bold}$@${reset}"
|
||||||
|
read -p " (y/n) " -n 1
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# same as above but underlined
|
||||||
|
function seek_confirmation_head() {
|
||||||
|
printf "\n${underline}${bold}$@${reset}"
|
||||||
|
read -p "${underline}${bold} (y/n)${reset} " -n 1
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test whether the result of an 'ask' is a confirmation
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
# Skip something
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Offer the user a chance to skip something.
|
||||||
|
# Credit: https://github.com/cowboy/dotfiles
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function skip() {
|
||||||
|
REPLY=noskip
|
||||||
|
read -t 5 -n 1 -s -p "${bold}To skip, press ${underline}X${reset}${bold} within 5 seconds.${reset}"
|
||||||
|
if [[ "$REPLY" =~ ^[Xx]$ ]]; then
|
||||||
|
echo " Skipping!"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo " Continuing..."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# unmountDrive
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# If an AFP drive is mounted as part of a script, this
|
||||||
|
# will unmount the volume.
|
||||||
|
# ------------------------------------------------------
|
||||||
|
function unmountDrive() {
|
||||||
|
if [ -d "$1" ]; then
|
||||||
|
diskutil unmount "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
29
lib/sharedVariables.sh
Executable file
29
lib/sharedVariables.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# Shared bash functions used by my bash scripts.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - Initial creation
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
# SCRIPTNAME
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Will return the name of the script being run
|
||||||
|
# ------------------------------------------------------
|
||||||
|
SCRIPTNAME=`basename $0` #Set Script Name variable
|
||||||
|
|
||||||
|
# NOW
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Will print the current date and time in the format:
|
||||||
|
# 01-02-2015 01:09:54 PM
|
||||||
|
# ------------------------------------------------------
|
||||||
|
NOW=$(date +"%m-%d-%Y %r") #Set Timestamp in variable
|
||||||
|
|
||||||
|
# THISHOST
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Will print the current hostname of the computer the script
|
||||||
|
# is being run on.
|
||||||
|
# ------------------------------------------------------
|
||||||
|
THISHOST=$(hostname)
|
||||||
74
lib/utils.sh
Executable file
74
lib/utils.sh
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
# Source additional files
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# The list of additional utility files to be sourced
|
||||||
|
# ------------------------------------------------------
|
||||||
|
|
||||||
|
# First we locate this script and populate the $SCRIPTPATH variable
|
||||||
|
# Doing so allows us to source additional files from this utils file.
|
||||||
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
SOURCE="$(readlink "$SOURCE")"
|
||||||
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||||
|
done
|
||||||
|
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
|
# Write the list of utility files to be sourced
|
||||||
|
FILES="
|
||||||
|
sharedVariables.sh
|
||||||
|
sharedFunctions.sh
|
||||||
|
setupScriptFunctions.sh
|
||||||
|
"
|
||||||
|
|
||||||
|
# Source the Utility Files
|
||||||
|
for file in $FILES
|
||||||
|
do
|
||||||
|
if [ -f "$SCRIPTPATH/$file" ]; then
|
||||||
|
source "$SCRIPTPATH/$file"
|
||||||
|
else
|
||||||
|
e_error "$file does not exist. Exiting"
|
||||||
|
Exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Logging and Colors
|
||||||
|
# ------------------------------------------------------
|
||||||
|
# Here we set the colors for our script feedback.
|
||||||
|
# Example usage: e_success "sometext"
|
||||||
|
#------------------------------------------------------
|
||||||
|
|
||||||
|
# Set Colors
|
||||||
|
bold=$(tput bold)
|
||||||
|
underline=$(tput sgr 0 1)
|
||||||
|
reset=$(tput sgr0)
|
||||||
|
purple=$(tput setaf 171)
|
||||||
|
red=$(tput setaf 1)
|
||||||
|
green=$(tput setaf 76)
|
||||||
|
tan=$(tput setaf 3)
|
||||||
|
blue=$(tput setaf 38)
|
||||||
|
|
||||||
|
# Headers and Logging
|
||||||
|
e_header() { echo -e "\n${bold}${purple}========== $@ ==========${reset}\n" ; }
|
||||||
|
e_arrow() { echo -e "➜ $@" ; }
|
||||||
|
e_success() { echo -e "${green}✔ $@${reset}" ; }
|
||||||
|
e_error() { echo -e "${red}✖ $@${reset}" ; }
|
||||||
|
e_warning() { echo -e "${tan}➜ $@${reset}" ; }
|
||||||
|
e_underline() { echo -e "${underline}${bold}$@${reset}" ; }
|
||||||
|
e_bold() { echo -e "${bold}$@${reset}" ; }
|
||||||
|
e_note() { echo -e "${underline}${bold}${blue}Note:${reset} ${blue}$@${reset}" ; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Note to self
|
||||||
|
# This is how you create a variable with multiple lines
|
||||||
|
# read -d '' String <<"EOF"
|
||||||
|
# one
|
||||||
|
# two
|
||||||
|
# three
|
||||||
|
# four
|
||||||
|
# EOF
|
||||||
|
# echo ${String}
|
||||||
31
setupScripts/README.MD
Normal file
31
setupScripts/README.MD
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Setup Scripts Readme File
|
||||||
|
These are the files I have created to mange the configuration of new computers.
|
||||||
|
|
||||||
|
## File Manifest
|
||||||
|
|
||||||
|
### Actively in use
|
||||||
|
These files are actively maintained and in use.
|
||||||
|
|
||||||
|
* **casks.sh** - Installs native Mac applications via [Homebrew Cask](https://github.com/caskroom/homebrew-cask) casks and runs Brew maintenance scripts
|
||||||
|
* **dropbox.sh** - Installs [Dropbox](http://dropbox.com) if not already installed
|
||||||
|
* **fileTest.sh** - Maintenance script to run occasionally. This ensures that the files called from the `mackup.sh` actually exist. If any of these files fail `mackup.sh` will fail as well.
|
||||||
|
* **fileTest.txt** - Text files containing the paths to documents and directories within Dropbox. This list is called from `mackup.sh` as well as `dropboxFileTest.sh` and is used to ensure that files have synced correctly.
|
||||||
|
* **functions.sh** - The backbone of my process. Contains most of the logic for the other scripts that are in use and makes them available as shared functions.
|
||||||
|
* **homebrew.sh** - Installs unix based [Homebrew](http://brew.sh/) packages and runs Brew maintenance scripts
|
||||||
|
* **mackup.sh** - This script configures and installs [mackup](https://github.com/lra/mackup), and then restores my files from Dropbox to their correct locations. **Note:** *This script relies on the existence of certain files in Dropbox to ensure that synching has completed. This list of files needs maintenance from time to time.*
|
||||||
|
* **newMackSetup.sh** - This is script calls all of the other scripts in the correct order to configure a new computer from scratch.
|
||||||
|
* **osx.sh** - This script contains the Mac OSX specific settings.
|
||||||
|
* **ruby.sh** - This script installs [RVM (Ruby Version Manager)](http://rvm.io/) and certain Gems including Jekyll.
|
||||||
|
* **ssd.sh** - Optional script for configuring non-Apple native SSDs
|
||||||
|
* **ssh.sh** - Script to configure SSH and link it to Github
|
||||||
|
* **utils.sh** - This is a utilities script containing common BASH scripting utilities.
|
||||||
|
|
||||||
|
### Scratch files
|
||||||
|
These files are not actively in use. They are either old and for reference purposes or test files.
|
||||||
|
|
||||||
|
* **dropboxsymlinks.sh** - Before discovering [mackup](https://github.com/lra/mackup) I wrote this script to symlink my own files through Dropbox. Saved for posterity to remind myself that I don't know how to code.
|
||||||
|
* **otherPeopleMackupScript.sh** - Hacked together script to attempt to get Mackup running on someone else's computer without any of the other scripts listed above.
|
||||||
|
* **testScript.sh** - A scratch file used to test different BASH functions. Erase at will.
|
||||||
|
|
||||||
|
## USAGE
|
||||||
|
To configure a new computer simply run the script `newMacSetup.sh` in Terminal.app and follow the instructions.
|
||||||
74
setupScripts/casks.sh
Executable file
74
setupScripts/casks.sh
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set Variables
|
||||||
|
LISTINSTALLED="brew cask list"
|
||||||
|
INSTALLCOMMAND="brew cask install --appdir=/Applications"
|
||||||
|
|
||||||
|
RECIPES=(
|
||||||
|
alfred
|
||||||
|
arq
|
||||||
|
authy-bluetooth
|
||||||
|
bartender
|
||||||
|
betterzipql
|
||||||
|
capo
|
||||||
|
carbon-copy-cloner
|
||||||
|
cheatsheet
|
||||||
|
codekit
|
||||||
|
controlplane
|
||||||
|
default-folder-x
|
||||||
|
dropbox
|
||||||
|
evernote
|
||||||
|
fantastical
|
||||||
|
firefox
|
||||||
|
flux
|
||||||
|
fluid
|
||||||
|
github
|
||||||
|
google-chrome
|
||||||
|
hazel
|
||||||
|
istat-menus
|
||||||
|
iterm2
|
||||||
|
imagealpha
|
||||||
|
imageoptim
|
||||||
|
java
|
||||||
|
joinme
|
||||||
|
kaleidoscope
|
||||||
|
launchbar
|
||||||
|
mamp
|
||||||
|
marked
|
||||||
|
mailplane
|
||||||
|
moom
|
||||||
|
nvalt
|
||||||
|
omnifocus
|
||||||
|
onepassword
|
||||||
|
plex-home-theater
|
||||||
|
qlcolorcode
|
||||||
|
qlmarkdown
|
||||||
|
qlprettypatch
|
||||||
|
qlstephen
|
||||||
|
quicklook-csv
|
||||||
|
quicklook-json
|
||||||
|
skitch
|
||||||
|
suspicious-package
|
||||||
|
textexpander
|
||||||
|
tower
|
||||||
|
vlc
|
||||||
|
webp-quicklook
|
||||||
|
xld
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run Functions
|
||||||
|
|
||||||
|
hasHomebrew
|
||||||
|
hasCasks
|
||||||
|
brewMaintenance
|
||||||
|
doInstall
|
||||||
|
|
||||||
|
# Cleanup Homebrew
|
||||||
|
brew cask cleanup
|
||||||
12
setupScripts/dropbox.sh
Executable file
12
setupScripts/dropbox.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Confirm we have Dropbox
|
||||||
|
hasDropbox
|
||||||
|
|
||||||
34
setupScripts/fileTest.sh
Executable file
34
setupScripts/fileTest.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script tests for the existence of certain files in Dropbox.
|
||||||
|
# It is used to keep a current list in the mackup.sh script.
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Variables from config file
|
||||||
|
if is_file "../etc/mackup.cfg"; then
|
||||||
|
source "../etc/mackup.cfg"
|
||||||
|
TESTFILE="$TESTCFG"
|
||||||
|
else
|
||||||
|
die "Can not run without config file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if is_not_file "$TESTFILE"; then
|
||||||
|
die "Could not find $TESTFILE. Exiting."
|
||||||
|
else
|
||||||
|
e_arrow "Confirming that Dropbox has synced..."
|
||||||
|
while IFS= read -r file
|
||||||
|
do
|
||||||
|
while [ ! -e $HOME/"$file" ] ;
|
||||||
|
do
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
e_success "Found $file"
|
||||||
|
done < "$TESTFILE"
|
||||||
|
fi
|
||||||
67
setupScripts/homebrew.sh
Executable file
67
setupScripts/homebrew.sh
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set Variables
|
||||||
|
LISTINSTALLED="brew list"
|
||||||
|
INSTALLCOMMAND="brew install"
|
||||||
|
|
||||||
|
install-ffmpeg () {
|
||||||
|
seek_confirmation "Install ffmpeg?"
|
||||||
|
if is_confirmed; then
|
||||||
|
if type_not_exists 'ffmpeg'; then
|
||||||
|
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libcaca --with-libass --with-frei0r --with-libquvi --with-libvidstab --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-x265
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
RECIPES=(
|
||||||
|
autoconf
|
||||||
|
automake
|
||||||
|
bash
|
||||||
|
bash-completion
|
||||||
|
colordiff
|
||||||
|
coreutils
|
||||||
|
git
|
||||||
|
git-extras
|
||||||
|
git-flow
|
||||||
|
htop-osx
|
||||||
|
hub
|
||||||
|
hr
|
||||||
|
id3tool
|
||||||
|
imagemagick
|
||||||
|
jpegoptim
|
||||||
|
lesspipe
|
||||||
|
libksba
|
||||||
|
libtool
|
||||||
|
libyaml
|
||||||
|
mackup
|
||||||
|
man2html
|
||||||
|
multimarkdown
|
||||||
|
openssl
|
||||||
|
optipng
|
||||||
|
pkg-config
|
||||||
|
pngcrush
|
||||||
|
readline
|
||||||
|
shellcheck
|
||||||
|
sl
|
||||||
|
source-highlight
|
||||||
|
ssh-copy-id
|
||||||
|
sqlite
|
||||||
|
tree
|
||||||
|
unison
|
||||||
|
z
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run Functions
|
||||||
|
|
||||||
|
hasHomebrew
|
||||||
|
brewMaintenance
|
||||||
|
doInstall
|
||||||
|
install-ffmpeg
|
||||||
|
brewCleanup
|
||||||
95
setupScripts/mackup.sh
Executable file
95
setupScripts/mackup.sh
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# This script will in restore a new computer from a mackup backup
|
||||||
|
# using Dropbox. It requires a config file in '../etc' to run.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - Initial creation
|
||||||
|
#
|
||||||
|
# NOTE: This script ensure that a Dropbox sync has been completed
|
||||||
|
# by keeping a list of files up-to-date. These files are listed (one
|
||||||
|
# per line) in a text file. If this file falls out of date, this
|
||||||
|
# script will never run
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
# Source utils
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
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 is_not_file "$TESTFILE"; then
|
||||||
|
die "Could not find $TESTFILE. Exiting."
|
||||||
|
else
|
||||||
|
e_arrow "Confirming that Dropbox has synced..."
|
||||||
|
while IFS= read -r file
|
||||||
|
do
|
||||||
|
while [ ! -e $HOME/"$file" ] ;
|
||||||
|
do
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
done < "$TESTFILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Add some additional time just to be sure....
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
e_warning "Waiting for Dropbox to Sync files."
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
# Sync Complete
|
||||||
|
e_success "Hooray! Dropbox has synced the necessary files."
|
||||||
|
|
||||||
|
if type_not_exists 'mackup'; then
|
||||||
|
e_error "MACKUP NOT FOUND."
|
||||||
|
e_error "Run 'brew install mackup' or run the Homebrew setup script. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# upgrade mackup. Don't display in terminal
|
||||||
|
brew upgrade mackup >/dev/null 2>&1
|
||||||
|
|
||||||
|
e_arrow "Checking for Mackup config files..."
|
||||||
|
if [ ! -L ""$HOME"/.mackup" ]; then
|
||||||
|
ln -s "$MACKUPDIR"/.mackup "$HOME"/.mackup
|
||||||
|
fi
|
||||||
|
if [ ! -L ""$HOME"/.mackup.cfg" ]; then
|
||||||
|
ln -s "$MACKUPDIR"/.mackup.cfg "$HOME"/.mackup.cfg
|
||||||
|
fi
|
||||||
|
e_success "Mackup config files linked."
|
||||||
|
|
||||||
|
seek_confirmation "Run Mackup Restore?"
|
||||||
|
if is_confirmed; then
|
||||||
|
mackup restore
|
||||||
|
e_header "All Done."
|
||||||
|
else
|
||||||
|
e_arrow "Exiting"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
68
setupScripts/newMacSetup.sh
Executable file
68
setupScripts/newMacSetup.sh
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# This script cycles through all my setup scripts. Run
|
||||||
|
# this script when you are starting fresh on a computer and
|
||||||
|
# it will take care of everything.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - Initial creation
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
seek_confirmation "Do you want to run the Dropbox script to install it first?"
|
||||||
|
if is_confirmed; then
|
||||||
|
if [ -e ./dropbox.sh ]; then
|
||||||
|
./dropbox.sh
|
||||||
|
else
|
||||||
|
e_error "Can't find dropbox.sh"
|
||||||
|
seek_confirmation "Continue running other scripts?"
|
||||||
|
if is_not_confirmed; then
|
||||||
|
e_error "Exiting"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
#List of Scripts to be run
|
||||||
|
FILES="
|
||||||
|
./homebrew.sh
|
||||||
|
./casks.sh
|
||||||
|
./ruby.sh
|
||||||
|
./mackup.sh
|
||||||
|
./osx.sh
|
||||||
|
./ssh.sh
|
||||||
|
./ssd.sh
|
||||||
|
"
|
||||||
|
|
||||||
|
seek_confirmation "Do you want to run all the scripts at once?"
|
||||||
|
if is_confirmed; then
|
||||||
|
for file in $FILES
|
||||||
|
do
|
||||||
|
if [ -e "$file" ]; then
|
||||||
|
$file
|
||||||
|
else
|
||||||
|
e_error "$file does not exist. Exiting"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
for file in $FILES
|
||||||
|
do
|
||||||
|
seek_confirmation "Do you want to run $file?"
|
||||||
|
if is_confirmed; then
|
||||||
|
if [ -e "$file" ]; then
|
||||||
|
$file
|
||||||
|
else
|
||||||
|
e_error "$file does not exist."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
701
setupScripts/osx.sh
Executable file
701
setupScripts/osx.sh
Executable file
@@ -0,0 +1,701 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Inspired by ~/.osx — http://mths.be/osx
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Grant sudo privs.
|
||||||
|
needSudo
|
||||||
|
|
||||||
|
e_header "Beginning osx.sh"
|
||||||
|
e_note "This script runs a series of commands to pre-configure OSX."
|
||||||
|
|
||||||
|
seek_confirmation "Would you like to set your computer name (as done via System Preferences >> Sharing)? (y/n)"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_arrow "What would you like the name to be?"
|
||||||
|
read COMPUTER_NAME
|
||||||
|
sudo scutil --set ComputerName "$COMPUTER_NAME"
|
||||||
|
sudo scutil --set HostName "$COMPUTER_NAME"
|
||||||
|
sudo scutil --set LocalHostName "$COMPUTER_NAME"
|
||||||
|
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$COMPUTER_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
# 1. General UI/UX
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Run General UI Tweaks?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
|
||||||
|
e_success "Disabled Sound Effects on Boot"
|
||||||
|
sudo nvram SystemAudioVolume=" "
|
||||||
|
|
||||||
|
e_success "Hide the Time Machine, Volume, User, and Bluetooth icons"
|
||||||
|
# Get the system Hardware UUID and use it for the next menubar stuff
|
||||||
|
for domain in ~/Library/Preferences/ByHost/com.apple.systemuiserver.*; do
|
||||||
|
defaults write "${domain}" dontAutoLoad -array \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/TimeMachine.menu" \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/Volume.menu" \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/User.menu"
|
||||||
|
done
|
||||||
|
|
||||||
|
defaults write com.apple.systemuiserver menuExtras -array \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/Bluetooth.menu" \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/AirPort.menu" \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/Battery.menu" \
|
||||||
|
"/System/Library/CoreServices/Menu Extras/Clock.menu"
|
||||||
|
|
||||||
|
e_success "Set highlight color to yellow"
|
||||||
|
defaults write NSGlobalDomain AppleHighlightColor -string '0.984300 0.929400 0.450900'
|
||||||
|
|
||||||
|
e_success "Set sidebar icon size to small"
|
||||||
|
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1
|
||||||
|
# Possible values for int: 1=small, 2=medium
|
||||||
|
|
||||||
|
e_success "Always show scrollbars"
|
||||||
|
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
|
||||||
|
# Possible values: `WhenScrolling`, `Automatic` and `Always`
|
||||||
|
|
||||||
|
#e_success "Disable transparency in the menu bar and elsewhere on Yosemite"
|
||||||
|
#defaults write com.apple.universalaccess reduceTransparency -bool true
|
||||||
|
|
||||||
|
e_success "Disable opening and closing window animations"
|
||||||
|
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false
|
||||||
|
|
||||||
|
e_success "Expand save panel by default"
|
||||||
|
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
|
||||||
|
|
||||||
|
e_success "Expand print panel by default"
|
||||||
|
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
|
||||||
|
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
|
||||||
|
|
||||||
|
e_success "Save to disk (not to iCloud) by default"
|
||||||
|
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
|
||||||
|
|
||||||
|
e_success "Automatically quit printer app once the print jobs complete"
|
||||||
|
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
|
||||||
|
|
||||||
|
e_success "Disable the Are you sure you want to open this application? dialog"
|
||||||
|
defaults write com.apple.LaunchServices LSQuarantine -bool false
|
||||||
|
|
||||||
|
e_success "General:Display ASCII control characters using caret notation in standard text views"
|
||||||
|
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
|
||||||
|
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
|
||||||
|
|
||||||
|
e_success "Disable automatic termination of inactive apps"
|
||||||
|
defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true
|
||||||
|
|
||||||
|
e_success "Disable Resume system-wide"
|
||||||
|
defaults write com.apple.systempreferences NSQuitAlwaysKeepsWindows -bool false
|
||||||
|
|
||||||
|
e_success "Set Help Viewer windows to non-floating mode"
|
||||||
|
defaults write com.apple.helpviewer DevMode -bool true
|
||||||
|
|
||||||
|
e_success "Reveal info when clicking the clock in the login window"
|
||||||
|
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
|
||||||
|
|
||||||
|
#e_success "Restart automatically if the computer freezes"
|
||||||
|
#systemsetup -setrestartfreeze on
|
||||||
|
|
||||||
|
#e_success "Never go into computer sleep mode"
|
||||||
|
#systemsetup -setcomputersleep Off > /dev/null
|
||||||
|
|
||||||
|
e_success "Check for software updates daily, not just once per week"
|
||||||
|
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
|
||||||
|
|
||||||
|
#e_success "Disable Notification Center and remove the menu bar icon"
|
||||||
|
#launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
|
||||||
|
|
||||||
|
e_success "Disabled smart quotes as they are annoying when typing code"
|
||||||
|
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
|
||||||
|
|
||||||
|
e_success "Disabled smart dashes as they are annoying when typing code"
|
||||||
|
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
|
||||||
|
|
||||||
|
e_success "Removing duplicates in the 'Open With' menu"
|
||||||
|
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
|
||||||
|
|
||||||
|
#e_success "Disable hibernation? (speeds up entering sleep mode)"
|
||||||
|
#sudo pmset -a hibernatemode 0
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 2. Trackpad, mouse, keyboard, Bluetooth accessories, and input
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Run Trackpad, Mouse, Keyboard Tweaks?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
#e_success "Trackpad: enable tap to click for this user and for the login screen"
|
||||||
|
#defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
|
||||||
|
#defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
|
||||||
|
#defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
|
||||||
|
|
||||||
|
# e_success "Trackpad: map bottom right corner to right-click"
|
||||||
|
# defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
|
||||||
|
# defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true
|
||||||
|
# defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 1
|
||||||
|
# defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true
|
||||||
|
|
||||||
|
# e_success "Disable “natural” (Lion-style) scrolling"
|
||||||
|
# defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
|
||||||
|
|
||||||
|
e_success "Setting trackpad & mouse speed to a reasonable number"
|
||||||
|
defaults write -g com.apple.trackpad.scaling 2
|
||||||
|
defaults write -g com.apple.mouse.scaling 2.5
|
||||||
|
|
||||||
|
e_success "Increase sound quality for Bluetooth headphones/headsets"
|
||||||
|
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
|
||||||
|
|
||||||
|
e_success "Enable full keyboard access for all controls"
|
||||||
|
# (e.g. enable Tab in modal dialogs)
|
||||||
|
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
|
||||||
|
|
||||||
|
e_success "Use scroll gesture with the Ctrl (^) modifier key to zoom"
|
||||||
|
defaults write com.apple.universalaccess closeViewScrollWheelToggle -bool true
|
||||||
|
defaults write com.apple.universalaccess HIDScrollZoomModifierMask -int 262144
|
||||||
|
# Follow the keyboard focus while zoomed in
|
||||||
|
defaults write com.apple.universalaccess closeViewZoomFollowsFocus -bool true
|
||||||
|
|
||||||
|
e_success "Disable press-and-hold for keys in favor of key repeat"
|
||||||
|
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
|
||||||
|
|
||||||
|
e_success "Set a blazingly fast keyboard repeat rate"
|
||||||
|
defaults write NSGlobalDomain KeyRepeat -int 0
|
||||||
|
|
||||||
|
e_success "Automatically illuminate built-in MacBook keyboard in low light"
|
||||||
|
defaults write com.apple.BezelServices kDim -bool true
|
||||||
|
|
||||||
|
e_success "Turn off keyboard illumination when computer is not used for 5 minutes"
|
||||||
|
defaults write com.apple.BezelServices kDimTime -int 300
|
||||||
|
|
||||||
|
e_success "Set language and text formats"
|
||||||
|
# Note: if you’re in the US, replace `EUR` with `USD`, `Centimeters` with
|
||||||
|
# `Inches`, `en_GB` with `en_US`, and `true` with `false`.
|
||||||
|
defaults write NSGlobalDomain AppleLanguages -array "en" "nl"
|
||||||
|
defaults write NSGlobalDomain AppleLocale -string "en_US@currency=USD"
|
||||||
|
defaults write NSGlobalDomain AppleMeasurementUnits -string "Inches"
|
||||||
|
defaults write NSGlobalDomain AppleMetricUnits -bool false
|
||||||
|
|
||||||
|
e_success "Set the timezone"
|
||||||
|
systemsetup -settimezone "America/New_York" > /dev/null
|
||||||
|
#see `systemsetup -listtimezones` for other values
|
||||||
|
|
||||||
|
#e_success "Disable spelling auto-correct"
|
||||||
|
#defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
|
||||||
|
|
||||||
|
# Stop iTunes from responding to the keyboard media keys
|
||||||
|
#launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 3. Screen
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Run Screen Configurations?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Require password immediately after sleep or screen saver begins"
|
||||||
|
defaults write com.apple.screensaver askForPassword -int 1
|
||||||
|
defaults write com.apple.screensaver askForPasswordDelay -int 0
|
||||||
|
|
||||||
|
e_success "Save screenshots to the desktop"
|
||||||
|
defaults write com.apple.screencapture location -string "${HOME}/Desktop"
|
||||||
|
|
||||||
|
e_success "Save screenshots in PNG format"
|
||||||
|
defaults write com.apple.screencapture type -string "png"
|
||||||
|
# other options: BMP, GIF, JPG, PDF, TIFF, PNG
|
||||||
|
|
||||||
|
#e_success "Disable shadow in screenshots"
|
||||||
|
#defaults write com.apple.screencapture disable-shadow -bool true
|
||||||
|
|
||||||
|
e_success "Enable subpixel font rendering on non-Apple LCDs"
|
||||||
|
defaults write NSGlobalDomain AppleFontSmoothing -int 2
|
||||||
|
|
||||||
|
#e_success "Enabling HiDPI display modes (requires restart)"
|
||||||
|
#sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 4. Finder
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Run Finder Tweaks?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Finder: allow quitting via ⌘ + Q"
|
||||||
|
defaults write com.apple.finder QuitMenuItem -bool true
|
||||||
|
|
||||||
|
e_success "Finder: disable window animations and Get Info animations"
|
||||||
|
defaults write com.apple.finder DisableAllAnimations -bool true
|
||||||
|
|
||||||
|
e_success "Set Home Folder as the default location for new Finder windows"
|
||||||
|
# For other paths, use `PfLo` and `file:///full/path/here/`
|
||||||
|
defaults write com.apple.finder NewWindowTarget -string "PfDe"
|
||||||
|
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"
|
||||||
|
|
||||||
|
e_success "Show icons for hard drives, servers, and removable media on the desktop"
|
||||||
|
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
|
||||||
|
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
|
||||||
|
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
|
||||||
|
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
|
||||||
|
|
||||||
|
#e_success "Finder: show hidden files by default"
|
||||||
|
#defaults write com.apple.finder AppleShowAllFiles -bool true
|
||||||
|
|
||||||
|
e_success "Finder: show all filename extensions"
|
||||||
|
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
|
||||||
|
|
||||||
|
e_success "Finder: show status bar"
|
||||||
|
defaults write com.apple.finder ShowStatusBar -bool true
|
||||||
|
|
||||||
|
e_success "Finder: show path bar"
|
||||||
|
defaults write com.apple.finder ShowPathbar -bool true
|
||||||
|
|
||||||
|
e_success "Finder: allow text selection in Quick Look"
|
||||||
|
defaults write com.apple.finder QLEnableTextSelection -bool true
|
||||||
|
|
||||||
|
#e_success "Display full POSIX path as Finder window title"
|
||||||
|
#defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
|
||||||
|
|
||||||
|
e_success "When performing a search, search the current folder by default"
|
||||||
|
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
|
||||||
|
|
||||||
|
e_success "Disable the warning when changing a file extension"
|
||||||
|
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
|
||||||
|
|
||||||
|
e_success "Enable spring loading for directories"
|
||||||
|
defaults write NSGlobalDomain com.apple.springing.enabled -bool true
|
||||||
|
|
||||||
|
e_success "Remove the spring loading delay for directories"
|
||||||
|
defaults write NSGlobalDomain com.apple.springing.delay -float 0
|
||||||
|
|
||||||
|
e_success "Avoid creating .DS_Store files on network volumes"
|
||||||
|
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
|
||||||
|
|
||||||
|
e_success "Disable disk image verification"
|
||||||
|
defaults write com.apple.frameworks.diskimages skip-verify -bool true
|
||||||
|
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
|
||||||
|
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
|
||||||
|
|
||||||
|
# e_success "Automatically open a new Finder window when a volume is mounted"
|
||||||
|
# defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
|
||||||
|
# defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
|
||||||
|
# defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
|
||||||
|
|
||||||
|
e_success "Show item info near icons on the desktop and in other icon views"
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
|
||||||
|
e_success "Show item info to the right of the icons on the desktop"
|
||||||
|
/usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:labelOnBottom false" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
|
||||||
|
e_success "Enable snap-to-grid for icons on the desktop and in other icon views"
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
|
||||||
|
e_success "Increase grid spacing for icons on the desktop and in other icon views"
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
|
||||||
|
e_success "Increase the size of icons on the desktop and in other icon views"
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
|
||||||
|
|
||||||
|
e_success "Use column view in all Finder windows by default"
|
||||||
|
defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
|
||||||
|
# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`, `Nlsv`
|
||||||
|
|
||||||
|
e_success "Disable the warning before emptying the Trash"
|
||||||
|
defaults write com.apple.finder WarnOnEmptyTrash -bool false
|
||||||
|
|
||||||
|
# e_success "Empty Trash securely by default"
|
||||||
|
# defaults write com.apple.finder EmptyTrashSecurely -bool true
|
||||||
|
|
||||||
|
e_success "Show the ~/Library folder"
|
||||||
|
chflags nohidden ~/Library
|
||||||
|
|
||||||
|
#e_success "Remove Dropbox’s green checkmark icons in Finder"
|
||||||
|
#file=/Applications/Dropbox.app/Contents/Resources/emblem-dropbox-uptodate.icns
|
||||||
|
#[ -e "${file}" ] && mv -f "${file}" "${file}.bak"
|
||||||
|
|
||||||
|
e_success "Expand File Info panes"
|
||||||
|
# “General”, “Open with”, and “Sharing & Permissions”
|
||||||
|
defaults write com.apple.finder FXInfoPanesExpanded -dict \
|
||||||
|
General -bool true \
|
||||||
|
OpenWith -bool true \
|
||||||
|
Privileges -bool true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable AirDrop over Ethernet and on unsupported Macs running Lion
|
||||||
|
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 5. Dock, Dashboard, and hot corners
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Dock, Dashboard, Corners?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
e_success "Enable highlight hover effect for the grid view of a stack"
|
||||||
|
defaults write com.apple.dock mouse-over-hilite-stack -bool true
|
||||||
|
|
||||||
|
e_success "Set the icon size of Dock items to 36 pixels"
|
||||||
|
defaults write com.apple.dock tilesize -int 36
|
||||||
|
|
||||||
|
e_success "Minimize windows into their application’s icon"
|
||||||
|
defaults write com.apple.dock minimize-to-application -bool true
|
||||||
|
|
||||||
|
e_success "Enable spring loading for all Dock items"
|
||||||
|
defaults write com.apple.dock enable-spring-load-actions-on-all-items -bool true
|
||||||
|
|
||||||
|
e_success "Show indicator lights for open applications in the Dock"
|
||||||
|
defaults write com.apple.dock show-process-indicators -bool true
|
||||||
|
|
||||||
|
e_success "Wipe all (default) app icons from the Dock"
|
||||||
|
# This is only really useful when setting up a new Mac, or if you don’t use
|
||||||
|
# the Dock to launch apps.
|
||||||
|
defaults write com.apple.dock persistent-apps -array
|
||||||
|
|
||||||
|
e_success "Don’t animate opening applications from the Dock"
|
||||||
|
defaults write com.apple.dock launchanim -bool false
|
||||||
|
|
||||||
|
e_success "Speed up Mission Control animations"
|
||||||
|
defaults write com.apple.dock expose-animation-duration -float 0.1
|
||||||
|
|
||||||
|
# e_success "Don’t group windows by application in Mission Control"
|
||||||
|
# # (i.e. use the old Exposé behavior instead)
|
||||||
|
# defaults write com.apple.dock expose-group-by-app -bool false
|
||||||
|
|
||||||
|
e_success "Disable Dashboard"
|
||||||
|
defaults write com.apple.dashboard mcx-disabled -bool true
|
||||||
|
|
||||||
|
e_success "Don’t show Dashboard as a Space"
|
||||||
|
defaults write com.apple.dock dashboard-in-overlay -bool true
|
||||||
|
|
||||||
|
# e_success "Don’t automatically rearrange Spaces based on most recent use"
|
||||||
|
# defaults write com.apple.dock mru-spaces -bool false
|
||||||
|
|
||||||
|
e_success "Remove the auto-hiding Dock delay"
|
||||||
|
defaults write com.apple.dock autohide-delay -float 0
|
||||||
|
|
||||||
|
#e_success "Remove the animation when hiding/showing the Dock"
|
||||||
|
#defaults write com.apple.dock autohide-time-modifier -float 0
|
||||||
|
|
||||||
|
e_success "Automatically hide and show the Dock"
|
||||||
|
defaults write com.apple.dock autohide -bool true
|
||||||
|
|
||||||
|
e_success "Make Dock icons of hidden applications translucent"
|
||||||
|
defaults write com.apple.dock showhidden -bool true
|
||||||
|
|
||||||
|
|
||||||
|
# Add a spacer to the left side of the Dock (where the applications are)
|
||||||
|
#defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
|
||||||
|
# Add a spacer to the right side of the Dock (where the Trash is)
|
||||||
|
#defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'
|
||||||
|
|
||||||
|
e_success "Disabled hot corners"
|
||||||
|
# Possible values:
|
||||||
|
# 0: no-op
|
||||||
|
# 2: Mission Control
|
||||||
|
# 3: Show application windows
|
||||||
|
# 4: Desktop
|
||||||
|
# 5: Start screen saver
|
||||||
|
# 6: Disable screen saver
|
||||||
|
# 7: Dashboard
|
||||||
|
# 10: Put display to sleep
|
||||||
|
# 11: Launchpad
|
||||||
|
# 12: Notification Center
|
||||||
|
# Top left screen corner → Mission Control
|
||||||
|
defaults write com.apple.dock wvous-tl-corner -int 0
|
||||||
|
defaults write com.apple.dock wvous-tl-modifier -int 0
|
||||||
|
# Top right screen corner → Desktop
|
||||||
|
defaults write com.apple.dock wvous-tr-corner -int 0
|
||||||
|
defaults write com.apple.dock wvous-tr-modifier -int 0
|
||||||
|
# Bottom left screen corner → Start screen saver
|
||||||
|
defaults write com.apple.dock wvous-bl-corner -int 0
|
||||||
|
defaults write com.apple.dock wvous-bl-modifier -int 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 6. Safari & WebKit
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Safari & Webkit tweaks?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
e_success "Privacy: don’t send search queries to Apple"
|
||||||
|
defaults write com.apple.Safari UniversalSearchEnabled -bool false
|
||||||
|
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
|
||||||
|
|
||||||
|
e_success "Show the full URL in the address bar (note: this still hides the scheme)"
|
||||||
|
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
|
||||||
|
|
||||||
|
e_success "Set Safari’s home page to about:blank for faster loading"
|
||||||
|
defaults write com.apple.Safari HomePage -string "about:blank"
|
||||||
|
|
||||||
|
e_success "Prevent Safari from opening safe files automatically after downloading"
|
||||||
|
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
|
||||||
|
|
||||||
|
# e_success "Allow hitting the Backspace key to go to the previous page in history"
|
||||||
|
# defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool true
|
||||||
|
|
||||||
|
# # Hide Safari’s bookmarks bar by default
|
||||||
|
# defaults write com.apple.Safari ShowFavoritesBar -bool false
|
||||||
|
|
||||||
|
# # Hide Safari’s sidebar in Top Sites
|
||||||
|
# defaults write com.apple.Safari ShowSidebarInTopSites -bool false
|
||||||
|
|
||||||
|
# # Disable Safari’s thumbnail cache for History and Top Sites
|
||||||
|
# defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2
|
||||||
|
|
||||||
|
e_success "Enable Safari’s debug menu"
|
||||||
|
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
|
||||||
|
|
||||||
|
e_success "Make Safari’s search banners default to Contains instead of Starts With"
|
||||||
|
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
|
||||||
|
|
||||||
|
Remove useless icons from Safari’s bookmarks bar
|
||||||
|
defaults write com.apple.Safari ProxiesInBookmarksBar "()"
|
||||||
|
|
||||||
|
e_success "Enable the Develop menu and the Web Inspector in Safari"
|
||||||
|
defaults write com.apple.Safari IncludeDevelopMenu -bool true
|
||||||
|
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
|
||||||
|
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true
|
||||||
|
|
||||||
|
e_success "Add a context menu item for showing the Web Inspector in web views"
|
||||||
|
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 7. Mail
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Mail.app?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
e_success "Disable send and reply animations in Mail.app"
|
||||||
|
defaults write com.apple.mail DisableReplyAnimations -bool true
|
||||||
|
defaults write com.apple.mail DisableSendAnimations -bool true
|
||||||
|
|
||||||
|
e_success "Copy sane email addresses to clipboard"
|
||||||
|
# Copy email addresses as `foo@example.com` instead of `Foo Bar <foo@example.com>` in Mail.app
|
||||||
|
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
|
||||||
|
|
||||||
|
#e_success "Add the keyboard shortcut ⌘ + Enter to send an email in Mail.app"
|
||||||
|
#defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Send" -string "@\\U21a9"
|
||||||
|
|
||||||
|
e_success "Display emails in threaded mode, sorted by date (newest at the top)"
|
||||||
|
defaults write com.apple.mail DraftsViewerAttributes -dict-add "DisplayInThreadedMode" -string "yes"
|
||||||
|
defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortedDescending" -string "no"
|
||||||
|
defaults write com.apple.mail DraftsViewerAttributes -dict-add "SortOrder" -string "received-date"
|
||||||
|
|
||||||
|
#e_success "Disable inline attachments (just show the icons)"
|
||||||
|
#defaults write com.apple.mail DisableInlineAttachmentViewing -bool false
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 8. Spotlight
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Spotlight?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
# Hide Spotlight tray-icon (and subsequent helper)
|
||||||
|
#sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
|
||||||
|
|
||||||
|
e_success "Disabled Spotlight indexing for any new mounted volume"
|
||||||
|
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
|
||||||
|
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"
|
||||||
|
|
||||||
|
e_success "Change indexing order and disable some file types"
|
||||||
|
# Yosemite-specific search results (remove them if your are using OS X 10.9 or older):
|
||||||
|
# MENU_DEFINITION
|
||||||
|
# MENU_CONVERSION
|
||||||
|
# MENU_EXPRESSION
|
||||||
|
# MENU_SPOTLIGHT_SUGGESTIONS (send search queries to Apple)
|
||||||
|
# MENU_WEBSEARCH (send search queries to Apple)
|
||||||
|
# MENU_OTHER
|
||||||
|
defaults write com.apple.spotlight orderedItems -array \
|
||||||
|
'{"enabled" = 1;"name" = "APPLICATIONS";}' \
|
||||||
|
'{"enabled" = 1;"name" = "SYSTEM_PREFS";}' \
|
||||||
|
'{"enabled" = 1;"name" = "DIRECTORIES";}' \
|
||||||
|
'{"enabled" = 1;"name" = "PDF";}' \
|
||||||
|
'{"enabled" = 1;"name" = "FONTS";}' \
|
||||||
|
'{"enabled" = 0;"name" = "DOCUMENTS";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MESSAGES";}' \
|
||||||
|
'{"enabled" = 0;"name" = "CONTACT";}' \
|
||||||
|
'{"enabled" = 0;"name" = "EVENT_TODO";}' \
|
||||||
|
'{"enabled" = 0;"name" = "IMAGES";}' \
|
||||||
|
'{"enabled" = 0;"name" = "BOOKMARKS";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MUSIC";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MOVIES";}' \
|
||||||
|
'{"enabled" = 0;"name" = "PRESENTATIONS";}' \
|
||||||
|
'{"enabled" = 0;"name" = "SPREADSHEETS";}' \
|
||||||
|
'{"enabled" = 0;"name" = "SOURCE";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_DEFINITION";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_OTHER";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_CONVERSION";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_EXPRESSION";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_WEBSEARCH";}' \
|
||||||
|
'{"enabled" = 0;"name" = "MENU_SPOTLIGHT_SUGGESTIONS";}'
|
||||||
|
# Load new settings before rebuilding the index
|
||||||
|
killall mds > /dev/null 2>&1
|
||||||
|
# Make sure indexing is enabled for the main volume
|
||||||
|
sudo mdutil -i on / > /dev/null
|
||||||
|
# Rebuild the index from scratch
|
||||||
|
sudo mdutil -E / > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 9. Terminal & iTerm 2
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Terminal.app?"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
e_success "Only use UTF-8 in Terminal.app"
|
||||||
|
defaults write com.apple.terminal StringEncodings -array 4
|
||||||
|
|
||||||
|
# Use a modified version of the Pro theme by default in Terminal.app
|
||||||
|
open "${HOME}/Dropbox/sharedConfiguration/App Configuration Files/Terminal/solarizedDark.terminal"
|
||||||
|
sleep 2 # Wait a bit to make sure the theme is loaded
|
||||||
|
defaults write com.apple.terminal "Default Window Settings" -string "solarizedDark"
|
||||||
|
defaults write com.apple.terminal "Startup Window Settings" -string "solarizedDark"
|
||||||
|
|
||||||
|
# Enable “focus follows mouse” for Terminal.app and all X11 apps
|
||||||
|
# i.e. hover over a window and start typing in it without clicking first
|
||||||
|
#defaults write com.apple.terminal FocusFollowsMouse -bool true
|
||||||
|
#defaults write org.x.X11 wm_ffm -bool true
|
||||||
|
fi
|
||||||
|
|
||||||
|
seek_confirmation "Configure iTerm2?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Installed pretty iTerm colors"
|
||||||
|
open "${HOME}/Dropbox/sharedConfiguration/App Configuration Files/iTerm/nate.itermcolors"
|
||||||
|
|
||||||
|
e_success "Don't display the annoying prompt when quitting iTerm"
|
||||||
|
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 10. Time Machine
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Disable Time Machine?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Prevent Time Machine from prompting to use new hard drives as backup volume"
|
||||||
|
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
|
||||||
|
|
||||||
|
e_success "Disable local Time Machine backups"
|
||||||
|
hash tmutil &> /dev/null && sudo tmutil disablelocal
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 11. Activity Monitor
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Activity Monitor?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Show the main window when launching Activity Monitor"
|
||||||
|
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
|
||||||
|
|
||||||
|
e_success "Visualize CPU usage in the Activity Monitor Dock icon"
|
||||||
|
defaults write com.apple.ActivityMonitor IconType -int 5
|
||||||
|
|
||||||
|
e_success "Show all processes in Activity Monitor"
|
||||||
|
defaults write com.apple.ActivityMonitor ShowCategory -int 0
|
||||||
|
|
||||||
|
e_success "Sort Activity Monitor results by CPU usage"
|
||||||
|
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
|
||||||
|
defaults write com.apple.ActivityMonitor SortDirection -int 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 12. Address Book, Dashboard, iCal, TextEdit, Chrome, and Disk Utility
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
seek_confirmation "Configure Google Chrome?"
|
||||||
|
if is_confirmed; then
|
||||||
|
# Use the system-native print preview dialog
|
||||||
|
defaults write com.google.Chrome DisablePrintPreview -bool true
|
||||||
|
defaults write com.google.Chrome.canary DisablePrintPreview -bool true
|
||||||
|
fi
|
||||||
|
|
||||||
|
seek_confirmation "Configure Contacts, Calendar, TextEdit, Disk Util?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Enable the debug menu in Address Book"
|
||||||
|
defaults write com.apple.addressbook ABShowDebugMenu -bool true
|
||||||
|
|
||||||
|
# Enable Dashboard dev mode (allows keeping widgets on the desktop)
|
||||||
|
# defaults write com.apple.dashboard devmode -bool true
|
||||||
|
|
||||||
|
# Enable the debug menu in iCal (pre-10.8)
|
||||||
|
# defaults write com.apple.iCal IncludeDebugMenu -bool true
|
||||||
|
|
||||||
|
e_success "Use plain text mode for new TextEdit documents"
|
||||||
|
defaults write com.apple.TextEdit RichText -int 0
|
||||||
|
e_success "Open and save files as UTF-8 in TextEdit"
|
||||||
|
defaults write com.apple.TextEdit PlainTextEncoding -int 4
|
||||||
|
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
|
||||||
|
|
||||||
|
e_success "Enable the debug menu in Disk Utility"
|
||||||
|
defaults write com.apple.DiskUtility DUDebugMenuEnabled -bool true
|
||||||
|
defaults write com.apple.DiskUtility advanced-image-options -bool true
|
||||||
|
fi
|
||||||
|
|
||||||
|
seek_confirmation "Configure Sublime Text 3 in Terminal?"
|
||||||
|
if is_confirmed; then
|
||||||
|
if [ ! -e "/Applications/Sublime Text.app" ]; then
|
||||||
|
e_error "We don't have Sublime Text.app. Get it installed and try again."
|
||||||
|
else
|
||||||
|
if [ ! -e "/usr/local/bin/subl" ]; then
|
||||||
|
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
|
||||||
|
e_success "Symlink created"
|
||||||
|
else
|
||||||
|
e_arrow "Symlink already exists. Nothing done."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# 13. Messages
|
||||||
|
###############################################################################
|
||||||
|
seek_confirmation "Configure Messages.app?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "Disable automatic emoji substitution in Messages.app? (i.e. use plain text smileys) (y/n)"
|
||||||
|
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticEmojiSubstitutionEnablediMessage" -bool false
|
||||||
|
|
||||||
|
e_success "Disable smart quotes in Messages.app? (it's annoying for messages that contain code) (y/n)"
|
||||||
|
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false
|
||||||
|
|
||||||
|
e_success "Disabled continuous spell checking in Messages.app? (y/n)"
|
||||||
|
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "continuousSpellCheckingEnabled" -bool false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
########################## DONE #############################
|
||||||
|
|
||||||
|
seek_confirmation "Kill all effected applications?"
|
||||||
|
if is_confirmed; then
|
||||||
|
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
|
||||||
|
"Dock" "Finder" "Mail" "Messages" "Safari" "SystemUIServer" \
|
||||||
|
"Terminal" "iCal"; do
|
||||||
|
killall "${app}" > /dev/null 2>&1
|
||||||
|
done
|
||||||
|
e_success "Apps killed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
e_note "Some of these changes require a logout/restart to take effect."
|
||||||
61
setupScripts/ruby.sh
Executable file
61
setupScripts/ruby.sh
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set Variables
|
||||||
|
LISTINSTALLED="gem list | awk '{print $1}'"
|
||||||
|
INSTALLCOMMAND="gem install"
|
||||||
|
RUBYVERSION="2.1.2"
|
||||||
|
|
||||||
|
|
||||||
|
# Check for RVM
|
||||||
|
if [[ ! "$(type -P rvm)" ]]; then
|
||||||
|
seek_confirmation_head "Install RVM?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_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 -P rvm)" ]]; then
|
||||||
|
#e_warning "Checking for newer Ruby Version"
|
||||||
|
source $HOME/.bash_profile
|
||||||
|
#rvm get stable --autolibs=enable
|
||||||
|
rvm install $RUBYVERSION
|
||||||
|
rvm use $RUBYVERSION --default
|
||||||
|
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
|
||||||
|
gem update --system
|
||||||
|
gem update
|
||||||
43
setupScripts/ssd.sh
Executable file
43
setupScripts/ssd.sh
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Inspired by ~/.osx — http://mths.be/osx
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update existing sudo time stamp if set, otherwise do nothing.
|
||||||
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# SSD-specific tweaks #
|
||||||
|
###############################################################################
|
||||||
|
e_header "Running SSD Specific OSX Tweaks"
|
||||||
|
|
||||||
|
seek_confirmation "Confirm that you have an SSD Hard Drive"
|
||||||
|
if is_confirmed; then
|
||||||
|
|
||||||
|
e_success "Disable local Time Machine snapshots"
|
||||||
|
sudo tmutil disablelocal
|
||||||
|
|
||||||
|
e_success "Disable hibernation (speeds up entering sleep mode)"
|
||||||
|
sudo pmset -a hibernatemode 0
|
||||||
|
|
||||||
|
e_success "Remove the sleep image file to save disk space"
|
||||||
|
sudo rm /Private/var/vm/sleepimage
|
||||||
|
e_success "Create a zero-byte file instead…"
|
||||||
|
sudo touch /Private/var/vm/sleepimage
|
||||||
|
e_success "…and make sure it can’t be rewritten"
|
||||||
|
sudo chflags uchg /Private/var/vm/sleepimage
|
||||||
|
|
||||||
|
e_success "Disable the sudden motion sensor as it’s not useful for SSDs"
|
||||||
|
sudo pmset -a sms 0
|
||||||
|
|
||||||
|
e_note "DON'T FORGET TO RESTART FOR CHANGES TO TAKE EFFECT"
|
||||||
|
e_header "Completed SSD Specific OSX Tweaks"
|
||||||
|
fi
|
||||||
37
setupScripts/ssh.sh
Executable file
37
setupScripts/ssh.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script creates public SSH Keys and sends them to Github
|
||||||
|
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "You must have utils.sh to run. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
e_header "Running : SSH CONFIG"
|
||||||
|
|
||||||
|
e_success "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
|
||||||
|
|
||||||
|
e_success "Copying public key to clipboard."
|
||||||
|
[[ -f ~/.ssh/id_rsa.pub ]] && cat ~/.ssh/id_rsa.pub | pbcopy
|
||||||
|
|
||||||
|
# Add SSH keys to Github
|
||||||
|
e_header "Github integration"
|
||||||
|
seek_confirmation "Open https://github.com/account/ssh in your browser?"
|
||||||
|
if is_confirmed; then
|
||||||
|
e_success "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
|
||||||
|
printf "\n Testing..."
|
||||||
|
ssh -T git@github.com
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
e_header "Completed : SSH CONFIG"
|
||||||
4
syncScripts/.gitignore
vendored
Normal file
4
syncScripts/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!SyncTemplate.sh
|
||||||
|
!README.md
|
||||||
38
syncScripts/README.md
Normal file
38
syncScripts/README.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# iPhotoUnison.sh
|
||||||
|
|
||||||
|
# iTunesRsync.sh
|
||||||
|
This script was written to push the iTunes library on my MacMini named MiniMusic to my ReadyNAS for backup purposes.
|
||||||
|
|
||||||
|
It is run every day by a plist file that was loaded into Launchd. This file was loaded using a program call **Lingon**. If you don't have access to that program, here's manual instructions for loading/unloading launchd tasks.
|
||||||
|
|
||||||
|
#### Installing launchd tasks
|
||||||
|
**First**, create a plist XML document. You can find information on these
|
||||||
|
|
||||||
|
* [here][1]
|
||||||
|
* [here][2]
|
||||||
|
* and, [here][3]
|
||||||
|
|
||||||
|
this document should be named something like `com.mycompanyname.mydepartment.mytaskname.plist`
|
||||||
|
|
||||||
|
**Second**, copy the plist files into your LaunchDaemons folder (or LaunchAgents, if you want it to only run when you’re logged in):
|
||||||
|
|
||||||
|
`cp com.mycompanyname.mydepartment.mytaskname.plist /Library/LaunchDaemons`
|
||||||
|
|
||||||
|
**Third**, so that launchd will pick it up without needing a reboot, we do the following:
|
||||||
|
|
||||||
|
`launchctl load -w /Library/LaunchDaemons/com.mycompanyname.mydepartment.mytaskname.plist`
|
||||||
|
|
||||||
|
To check it’s all installed, do `launchctl list` and check that your task is in the list.
|
||||||
|
|
||||||
|
#### Disabling launchd tasks
|
||||||
|
When the time comes that you need to disable the task, do the following:
|
||||||
|
|
||||||
|
`launchctl unload -w /Library/LaunchDaemons/com.mycompanyname.mydepartment.mytaskname.plist`
|
||||||
|
`rm /Library/LaunchDaemons/com.mycompanyname.mydepartment.mytaskname.plist`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[1]: http://www.splinter.com.au/using-launchd-to-run-a-script-every-5-mins-on/
|
||||||
|
[2]: http://alvinalexander.com/mac-os-x/launchd-examples-launchd-plist-file-examples-mac
|
||||||
|
[3]: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/ScheduledJobs.html
|
||||||
307
syncScripts/SyncTemplate.sh
Executable file
307
syncScripts/SyncTemplate.sh
Executable file
@@ -0,0 +1,307 @@
|
|||||||
|
# Source my scripting utils
|
||||||
|
# ------------------------
|
||||||
|
|
||||||
|
# ##################################################
|
||||||
|
# My Generic sync script.
|
||||||
|
#
|
||||||
|
# This script will give you the option of using rsync
|
||||||
|
# or Unison. Rsync is for one-way syncing, Unison is for
|
||||||
|
# two-way syncing.
|
||||||
|
#
|
||||||
|
# Depending on what flags are passed to the script and
|
||||||
|
# what information is written in the config file, this script
|
||||||
|
# will perform different behavior.
|
||||||
|
#
|
||||||
|
# USAGE:
|
||||||
|
#
|
||||||
|
# 1) IMPORTANT: Copy this script and rename it for your purpose before running.
|
||||||
|
# 2) Run the script. This will create a blank config file for you and then exit.
|
||||||
|
# 3) Enter your information within the config file
|
||||||
|
# 4) Run the script again.
|
||||||
|
#
|
||||||
|
# DISCLAIMER:
|
||||||
|
# I am a novice programmer and I bear no responsibility whatsoever
|
||||||
|
# if this (or any other) script that I write wipes your computer,
|
||||||
|
# destroys your data, crashes your car, or otherwise causes mayhem
|
||||||
|
# and destruction. USE AT YOUR OWN RISK.
|
||||||
|
#
|
||||||
|
# HISTORY
|
||||||
|
# * 2015-01-02 - First Creation
|
||||||
|
#
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
# Source Scripting Utilities
|
||||||
|
if [ -f "../lib/utils.sh" ]; then
|
||||||
|
source "../lib/utils.sh"
|
||||||
|
else
|
||||||
|
echo "Please find the file util.sh and add a reference to it in this script. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This script calls for a configuration file.
|
||||||
|
# This is its location
|
||||||
|
CONFIG="../etc/$SCRIPTNAME.cfg"
|
||||||
|
|
||||||
|
|
||||||
|
# HELP
|
||||||
|
# When -h is passed to the script, this will display inline help
|
||||||
|
function HELP () {
|
||||||
|
echo -e "\nHelp for $SCRIPTNAME"
|
||||||
|
echo -e "This script will give you the option of using rsync"
|
||||||
|
echo -e "or Unison. Rsync is for one-way syncing, Unison is for"
|
||||||
|
echo -e "two-way syncing.\n"
|
||||||
|
echo -e "Depending on what flags are passed to the script and"
|
||||||
|
echo -e "what information is written in the config file, this script"
|
||||||
|
echo -e "will perform different behavior.\n"
|
||||||
|
echo -e "USAGE:"
|
||||||
|
echo -e " 1) IMPORTANT: Copy this script and rename it for your purpose before running."
|
||||||
|
echo -e " 2) Run the script. This will create a blank config file for you and then exit."
|
||||||
|
echo -e " 3) Enter your information within the config file"
|
||||||
|
echo -e " 4) Run the script again.\n"
|
||||||
|
echo -e "This script requires a config file located at: \"$CONFIG\""
|
||||||
|
echo -e "Ensure that the config file is correct before running."
|
||||||
|
echo -e "If the config file is not found at all, the script will create a new one for you.\n"
|
||||||
|
echo -e "MODIFIERS:"
|
||||||
|
echo -e "-n: Dry Run. This will show what would have been transferred. Works in rsync only."
|
||||||
|
echo -e "-z: Compresses data during the transfer. Good for low bandwidth. Works in rsync only."
|
||||||
|
echo -e "-h: View help"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Here we source the Config file or create a new one if none exists.
|
||||||
|
if is_file "$CONFIG"; then
|
||||||
|
source "$CONFIG"
|
||||||
|
else
|
||||||
|
seek_confirmation "Config file does not exist. Would you like to create one?"
|
||||||
|
if is_not_confirmed; then
|
||||||
|
die "No config file. Exiting"
|
||||||
|
else
|
||||||
|
touch "$CONFIG"
|
||||||
|
cat >"$CONFIG" <<EOL
|
||||||
|
# ##################################################
|
||||||
|
# CONFIG FILE FOR $SCRIPTNAME
|
||||||
|
# CREATED ON $NOW
|
||||||
|
# ##################################################
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# BASE CONFIGURATION
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
|
# Method
|
||||||
|
# ---------------------------
|
||||||
|
# This script will work with both Unison and rsync.
|
||||||
|
# Set the METHOD variable to either 'unison' or 'rsync'
|
||||||
|
METHOD=""
|
||||||
|
|
||||||
|
# Directories To Sync
|
||||||
|
# ---------------------------
|
||||||
|
# These are the COMPLETE paths two directories that will be synced.
|
||||||
|
# Be sure to include trailing slashes on directories.
|
||||||
|
SOURCEDIRECTORY=""
|
||||||
|
TARGETDIRECTORY=""
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# Network Volume Mounting
|
||||||
|
# ---------------------------
|
||||||
|
# If one of the directies you need to sync is on a network drive set
|
||||||
|
# the variable NEEDMOUNT to 'true'
|
||||||
|
NEEDMOUNT="false"
|
||||||
|
|
||||||
|
# MOUNTPOINT is the address of the drive to be mounted.
|
||||||
|
# Use the format afp://username:password@address/mountname
|
||||||
|
MOUNTPOINT=""
|
||||||
|
|
||||||
|
# REMOTEVOLUME is the directory that the drive should be mounted
|
||||||
|
# into on the local computer. Typically this is in the /Volumes/ dir.
|
||||||
|
# and should be named the same as the mount name in the MOUNTPOINT.
|
||||||
|
# Use the complete path, not a relative path
|
||||||
|
REMOTEVOLUME=""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# UNISON PREFERENCES
|
||||||
|
# ---------------------------
|
||||||
|
# If you are using UNISON to sync your directories, fill in this section.
|
||||||
|
|
||||||
|
# Unison keeps its own config profiles which configure
|
||||||
|
# much of the script. These .prf files are located in '~/.unison/'
|
||||||
|
# more info: http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html
|
||||||
|
#
|
||||||
|
# If you wish to use a Unison profile change USERPROFILE to 'true'
|
||||||
|
# and add the profile name to UNISONPROFILE
|
||||||
|
USEPROFILE="false"
|
||||||
|
UNISONPROFILE=""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# RSYNC PREFENCES
|
||||||
|
# ---------------------------
|
||||||
|
# If you are using rsync, complete this section
|
||||||
|
|
||||||
|
# EXCLUDE is a text file that contains all the rsync excludes.
|
||||||
|
# Anything listed within this file will be ignored during sync.
|
||||||
|
EXCLUDE=""
|
||||||
|
|
||||||
|
# ADDITIONAL OPTIONS
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
|
# LOGFILE is a text file to log all script activity to.
|
||||||
|
# Use the format /some/directory/file.txt
|
||||||
|
# If you don't want a log of the activity leave this as /dev/null
|
||||||
|
LOGFILE="/dev/null"
|
||||||
|
|
||||||
|
# PUSHOVER is an online notification tool.
|
||||||
|
# If you want to receive notifications upon completion
|
||||||
|
# set the following value to "true"
|
||||||
|
PUSHOVERNOTIFY="false"
|
||||||
|
|
||||||
|
# CANONICALHOST is used to denote a sync hub which should never initiate a sync.
|
||||||
|
# Leave blank if not needed.
|
||||||
|
CANONICALHOST=""
|
||||||
|
EOL
|
||||||
|
e_success "Config file created. Edit the values before running this script again. Exiting."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# READ OPTIONS
|
||||||
|
# Reads the options passed to the script
|
||||||
|
# from the command line
|
||||||
|
# ------------------------
|
||||||
|
while getopts "hnz" opt; do
|
||||||
|
case $opt in
|
||||||
|
h) # show help
|
||||||
|
HELP
|
||||||
|
;;
|
||||||
|
n) # Show progress in terminal
|
||||||
|
DRYRUN="n"
|
||||||
|
;;
|
||||||
|
z) # Compress Data
|
||||||
|
COMPRESS="z"
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
HELP
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# HostCheck
|
||||||
|
# Confirm we can run this script. If a canonical host is set in
|
||||||
|
# the config file we check it here.
|
||||||
|
if [ "$THISHOST" = "$CANONICALHOST" ]; then
|
||||||
|
echo "$NOW - Script was not run since we were on the wrong host" >> "$LOGFILE"
|
||||||
|
die "We are currently on $THISHOST and can not proceed. Be sure to run this script on the non-canonical host."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MethodCheck
|
||||||
|
# Confirm we have either Unison or Rsync specified
|
||||||
|
# in the config file. Exit if not
|
||||||
|
if [ "$METHOD" != "rsync" ] && [ "$METHOD" != "unison" ]; then
|
||||||
|
echo "$NOW - Script aborted without a method specified in the config file." >> "$LOGFILE"
|
||||||
|
die "We can not continue. Please specify a sync method in the config file."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Time the script by logging the start time
|
||||||
|
STARTTIME=$(date +"%s")
|
||||||
|
|
||||||
|
# Log Script Start to $LOGFILE
|
||||||
|
echo -e "-----------------------------------------------------" >> "$LOGFILE"
|
||||||
|
echo -e "$NOW - $SCRIPTNAME Begun" >> "$LOGFILE"
|
||||||
|
echo -e "-----------------------------------------------------\n" >> "$LOGFILE"
|
||||||
|
|
||||||
|
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then
|
||||||
|
# Mount AFP volume
|
||||||
|
if is_not_dir "$REMOTEVOLUME"; then
|
||||||
|
e_arrow "Mounting drive"
|
||||||
|
mkdir "$REMOTEVOLUME"
|
||||||
|
mount_afp "$MOUNTPOINT" "$REMOTEVOLUME"
|
||||||
|
sleep 10
|
||||||
|
echo "$NOW - $REMOTEVOLUME Mounted" >> "$LOGFILE"
|
||||||
|
e_success "$REMOTEVOLUME Mounted"
|
||||||
|
else
|
||||||
|
e_success "$REMOTEVOLUME already mounted"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test for source directories.
|
||||||
|
# If the don't exist we can't continue
|
||||||
|
if is_dir "$TARGETDIRECTORY"; then
|
||||||
|
e_success "$TARGETDIRECTORY exists"
|
||||||
|
else
|
||||||
|
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then
|
||||||
|
unmountDrive "$REMOTEVOLUME"
|
||||||
|
if is_dir "$REMOTEVOLUME"; then
|
||||||
|
rm -r "$REMOTEVOLUME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo -e "$NOW - Script aborted since $TARGETDIRECTORY was not found. Exited.\n" >> "$LOGFILE"
|
||||||
|
die "$TARGETDIRECTORY does not exist. Exiting."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test for local directory
|
||||||
|
if is_dir "$SOURCEDIRECTORY"; then
|
||||||
|
e_success "$SOURCEDIRECTORY exists"
|
||||||
|
else
|
||||||
|
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then
|
||||||
|
unmountDrive "$REMOTEVOLUME"
|
||||||
|
if is_dir "$REMOTEVOLUME"; then
|
||||||
|
rm -r "$REMOTEVOLUME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo -e "$NOW - Script aborted since $SOURCEDIRECTORY was not found. Exited.\n" >> "$LOGFILE"
|
||||||
|
die "$SOURCEDIRECTORY does not exist. Exiting."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Time to sync
|
||||||
|
if [ "$METHOD" = "rsync" ]; then
|
||||||
|
/usr/bin/rsync -vahh"$DRYRUN""$COMPRESS" --progress --force --delete --exclude-from="$EXCLUDE" "$SOURCEDIRECTORY" "$TARGETDIRECTORY" --log-file="$LOGFILE"
|
||||||
|
fi
|
||||||
|
if [ "$METHOD" = "unison" ]; then
|
||||||
|
|
||||||
|
# Check if Unison is installed. It is not a standard package
|
||||||
|
if type_not_exists 'unison'; then
|
||||||
|
seek_confirmation "Unison not installed, install it?"
|
||||||
|
if is_confirmed; then
|
||||||
|
hasHomebrew
|
||||||
|
brewMaintenance
|
||||||
|
brew install unison
|
||||||
|
else
|
||||||
|
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then
|
||||||
|
unmountDrive "$REMOTEVOLUME"
|
||||||
|
if is_dir "$REMOTEVOLUME"; then
|
||||||
|
rm -r "$REMOTEVOLUME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
die "Can not continue without Unison."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USEPROFILE" != "true"]; then
|
||||||
|
# Run Unison without a profile
|
||||||
|
unison "$SOURCEDIRECTORY" "$TARGETDIRECTORY"
|
||||||
|
else
|
||||||
|
# Run unison with a profile
|
||||||
|
unison "$UNISONPROFILE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Unmount the drive (if mounted)
|
||||||
|
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then
|
||||||
|
unmountDrive "$REMOTEVOLUME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Time the script by logging the end time
|
||||||
|
ENDTIME=$(date +"%s")
|
||||||
|
TOTALTIME=$(($ENDTIME-$STARTTIME-20))
|
||||||
|
|
||||||
|
# notify with pushover if requested
|
||||||
|
if [ "$PUSHOVERNOTIFY" = "true" ]; then
|
||||||
|
pushover "$SCRIPTNAME Completed" "$SCRIPTNAME was run in $(convertsecs $TOTALTIME)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n-----------------------------------------------------" >> "$LOGFILE"
|
||||||
|
echo "$NOW - $SCRIPTNAME completed in $(convertsecs $TOTALTIME)" >> "$LOGFILE"
|
||||||
|
echo -e "-----------------------------------------------------\n" >> "$LOGFILE"
|
||||||
|
|
||||||
|
e_success "$NOW - $SCRIPTNAME completed in $(convertsecs $TOTALTIME)"
|
||||||
Reference in New Issue
Block a user