Created
August 3, 2018 01:13
-
-
Save Schoonology/7c96b734417119a0a44df95ce29ad535 to your computer and use it in GitHub Desktop.
Setup scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -evuo pipefail | |
IFS=$'\n\t' | |
DIR=$(dirname "${BASH_SOURCE[0]}") | |
run_if_closed() { | |
if ! [ -n "$(pgrep "${2:-$1}")" ] | |
then | |
echo "Opening $1..." | |
open -a "$1" | |
read -r -p "Press any key to continue." | |
fi | |
} | |
# When initializing a new computer: | |
# - Update OSX defaults | |
# - Install desired applications | |
# - Restore files from backup | |
# - Install crontab for sync scripts | |
# - Unlock and export secrets (e.g. SSH keys) | |
# - Open apps that need additional setup | |
# | |
# This script assumes: | |
# - You have access to the script | |
# - You have signed into your Apple ID | |
"$DIR/admin/write-defaults.sh" | |
"$DIR/admin/update-apps.sh" | |
"$DIR/admin/restore-from-nas.sh" | |
"$DIR/admin/update-crontab.sh" | |
run_if_closed "1Password 7" | |
"$DIR/admin/unlock-secrets.sh" | |
run_if_closed "Alfred 3" | |
run_if_closed "Docker" | |
run_if_closed "Firefox" firefox | |
run_if_closed "Slack" | |
run_if_closed "Spotify" | |
run_if_closed "Unsplash Wallpapers" | |
run_if_closed "XCode" | |
run_if_closed "Viscosity" | |
run_if_closed "Zoom.us" | |
git lfs install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
function extname() { | |
FILENAME=$(basename "$1") | |
echo ".${FILENAME##*.}" | |
} | |
# Unlock and restore secrets (e.g. SSH keys) | |
# | |
# To do this, we'll log into 1Password using their `op` application, | |
# then export specifically-named "Documents": | |
# | |
# - If a document's name starts with `id_`, we export it to `~/.ssh`. | |
echo "1Password login" | |
echo "===============" | |
echo -n "Domain: " | |
read -r DOMAIN | |
echo -n "Email: " | |
read -r EMAIL | |
echo -n "Secret key: " | |
read -r -s KEY | |
echo | |
eval "$(op signin "$DOMAIN" "$EMAIL" "$KEY")" | |
SSH_KEY_DOCS_DATA=$(op list documents | jq -r -c "map(select(.overview.title | startswith(\"id_\"))) | .[]") | |
mkdir -p ~/.ssh | |
chmod 700 ~/.ssh | |
for item_data in $SSH_KEY_DOCS_DATA; do | |
FILENAME=$(echo $item_data | jq -r ".overview.title") | |
UUID=$(echo $item_data | jq -r ".uuid") | |
op get document "$UUID" > "$HOME/.ssh/$FILENAME" | |
if [ "$(extname "$FILENAME")" == ".pub" ]; then | |
chmod 644 "$HOME/.ssh/$FILENAME" | |
else | |
chmod 600 "$HOME/.ssh/$FILENAME" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -evuo pipefail | |
IFS=$'\n\t' | |
DIR=$(dirname "${BASH_SOURCE[0]}") | |
# Homebrew | |
if ! [ -x "$(command -v brew)" ]; then | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
fi | |
brew update | |
brew tap homebrew/bundle | |
brew bundle install --file="$DIR/Brewfile" | |
brew upgrade | |
mas upgrade | |
# Oh my ZSH | |
if ! [ -d "$HOME/.oh-my-zsh" ]; then | |
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
fi | |
if ! [ -d "$HOME/.oh-my-zsh/plugins/userenv" ]; then | |
git clone https://github.com/schoonology/userenv-zsh.git ~/.oh-my-zsh/plugins/userenv | |
fi | |
# Node | |
nodenv install -s 8.11.3 | |
nodenv global 8.11.3 | |
npm_install_if_missing() { | |
if ! [ -x "$(command -v $1)" ]; then | |
npm install -g ${2:-$1} | |
fi | |
} | |
npm_install_if_missing mgit | |
npm_install_if_missing particle particle-cli | |
npm_install_if_missing quantum quantum-client | |
# Browter | |
if ! [ -x "$(command -v browter)" ]; then | |
mkdir -p ~/Code/public | |
git clone https://github.com/Schoonology/Browter.git ~/Code/public/browter | |
( | |
cd ~/Code/public/browter | |
make | |
make install | |
) | |
fi | |
# Xcodebuild | |
if ! xcodebuild -showsdks &> /dev/null; then | |
echo "Fixing xcodebuild..." | |
sudo xcode-select --switch /Applications/Xcode.app | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -evuo pipefail | |
IFS=$'\n\t' | |
############### | |
# OSX Settings | |
# Expand save dialogs by default | |
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true | |
# Show battery percentage | |
defaults write com.apple.menuextra.battery ShowTime -bool false | |
defaults write com.apple.menuextra.battery ShowPercent -bool true | |
# Show all filename extensions | |
defaults write NSGlobalDomain AppleShowAllExtensions -bool true | |
# Display full POSIX path as Finder window title | |
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true | |
# Show the ~/Library folder | |
chflags nohidden ~/Library | |
# Use scroll gesture with the Ctrl (^) key to zoom | |
defaults write com.apple.universalaccess HIDScrollZoomModifierMask -int 262144 | |
# Expand print panel by default | |
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true | |
# Disable smart quotes as they’re annoying when typing code | |
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false | |
# Disable smart dashes as they’re annoying when typing code | |
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false | |
# Automatically hide and show the Dock | |
defaults write com.apple.dock autohide -bool true | |
# Make Dock icons of hidden applications translucent | |
defaults write com.apple.dock showhidden -bool true | |
# Disable rearranging Spaces with use | |
defaults write com.apple.dock mru-spaces -bool false | |
# Disable typing suggestions | |
defaults write NSGlobalDomain NSAutomaticTextCompletionEnabled -bool false | |
# Disable double-space period | |
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false | |
# Disable auto-capitalization | |
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false | |
# Disable shaking to magnify the mouse cursor | |
defaults write NSGlobalDomain CGDisableCursorLocationMagnification -bool false | |
# Set key repeat to "Fast" | |
defaults write NSGlobalDomain KeyRepeat -int 2 | |
# Set key repeat delay to "Short" | |
defaults write NSGlobalDomain InitialKeyRepeat -int 15 | |
######################### | |
# Safari/WebKit settings | |
# Enable Safari Developer Menu | |
defaults write com.apple.safari IncludeDevelopMenu -bool true | |
# Enable Safari Inspector | |
defaults write com.apple.safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true | |
# Enable Safari Inspector (again? cargo-culting here) | |
defaults write com.apple.safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true | |
# Add context menu for Safari Web Inspector | |
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true | |
# Set Safari’s home page to `about:blank` for faster loading | |
defaults write com.apple.Safari HomePage -string "about:blank" | |
# Prevent Safari from opening ‘safe’ files automatically after downloading | |
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false | |
########### | |
# Messages | |
# Disable sound effects | |
defaults write com.apple.messageshelper.AlertsController PlaySoundsKey -bool false | |
################### | |
# Activity Monitor | |
# Show the main window when launching Activity Monitor | |
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true | |
# Visualize CPU history in the Activity Monitor Dock icon | |
defaults write com.apple.ActivityMonitor IconType -int 6 | |
# Show all processes in Activity Monitor | |
defaults write com.apple.ActivityMonitor ShowCategory -int 0 | |
# Sort Activity Monitor results by CPU usage | |
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage" | |
defaults write com.apple.ActivityMonitor SortDirection -int 0 | |
####################### | |
# Application Settings | |
# Set Alfred sync folder | |
defaults write com.runningwithcrayons.Alfred-Preferences syncfolder -string ~/Documents/Settings | |
# Set iterm2 sync folder | |
defaults write com.googlecode.iterm2 PrefsCustomFolder -string ~/Documents/Settings | |
defaults write com.googlecode.iterm2 LoadPrefsFromCustomFolder -int 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment