-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·177 lines (147 loc) · 7.65 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
#==================
set -o errexit # Exit if any individual command fails and isn't handled
set -o nounset # Exit if unset variables are used
if [ -n "${BASH_VERSION:-}" ]; then
# If any command in a pipeline fails, the whole pipeline should fail.
# This option isn't define by POSIX `sh` but is available if we're running
# as `bash`.
# Disable warning for using non-portable option (SC2039 for shellcheck <=
# 0.7.1, SC3040 for >= 0.7.2).
# shellcheck disable=SC2039,SC3040
set -o pipefail
fi
kill_sudo_on_exit() {
trap - EXIT
# Invalidate the cached credentials, if we're the ones that cached it
if [[ "$SUDO_CREDENTIALS_CACHED_IN_SCRIPT" -ne "0" ]]; then
sudo -k
fi
# Kill all subprocesses
kill -9 $(jobs -rp) 2> /dev/null
wait $(jobs -rp) 2>/dev/null
}
trap kill_sudo_on_exit EXIT
ask_for_sudo_while_script_runs() {
# Check to see the credentials were already cached before we got here.
# When we exit, we want to make sure we only invalidate the credentials
# if we were the ones that caused it to be cached.
sudo -nv 2> /dev/null || rv=$?
SUDO_CREDENTIALS_CACHED_IN_SCRIPT="$rv"
sudo -v -p "Enter your password to install: "
# This will create a background subprocess that will extends
# sudo timeout every 5 seconds.
(
while sudo -nv 2> /dev/null; do
sleep 5
done
)&
}
set_defaults_if_missing() {
local domain=$1
local key=$2
local current_value=$(defaults read "$domain" "$key" 2> /dev/null || echo "")
if [[ -z "$current_value" ]]; then
shift 2
defaults write "$domain" "$key" "$@"
fi
}
make_and_install_roots() {
TARGET_ROOT_DIR="$HOME"
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/roots"
COPY_DIR="$SOURCE_DIR/copy/User"
SYMLINK_DIR="$SOURCE_DIR/symlinks/User"
find "$SYMLINK_DIR/" -type f \( ! -name ".DS_Store" \) | while read -d $'\n' symlink; do
symlink=${symlink#*//}
if [[ "$symlink" == *".symlink" ]]; then
# A symlink file contains a single line representing the target to symlink to
src=$(cat "$SYMLINK_DIR/$symlink")
src="${src/#\~\/.dotfiles/$HOME}"
dest="$TARGET_ROOT_DIR/${symlink%.symlink}"
else
src="$SYMLINK_DIR/$symlink"
dest="$TARGET_ROOT_DIR/$symlink"
fi
# Only create the symlink if the source file or directory exists
if [[ -f "$src" || -d "$src" ]] && [[ ! -f "$dest" ]]; then
mkdir -p "$(dirname "$dest")"
ln -sf "$src" "$dest"
fi
done
rsync -razI --ignore-existing --progress "$COPY_DIR/" "$HOME"
[[ -f ~/.zshenv ]] && source ~/.zshenv
[[ -f ~/.zprofile ]] && source ~/.zprofile
[[ -f ~/.zshrc ]] && source ~/.zshrc
}
# -- Bootstrapping -------------------------------------------------------------
install_homebrew() {
if command -v brew >/dev/null; then
# Homebrew already installed.
echo "Skipping homebrew, already installed."
return
fi
echo "Installing homebrew and packages..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew analytics off || true
brew update
brew bundle install
}
configure_defaults() {
# The following has been largely inspired by: https://github.com/mathiasbynens/dotfiles/blob/main/.macos
# Close any open System Preferences panes, to prevent them from overriding settings being changed
osascript -e 'tell application "System Preferences" to quit'
# Enable dark mode, the following is set during Mac Buddy, we need to overwrite the value instead
defaults write NSGlobalDomain AppleInterfaceStyle Dark
# Show file extensions by default
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Expand save panel by default
set_defaults_if_missing NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
set_defaults_if_missing NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Save to disk (not to iCloud) by default
set_defaults_if_missing NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Expand print panel by default
set_defaults_if_missing NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
set_defaults_if_missing NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Automatically quit printer app once the print jobs complete
set_defaults_if_missing com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the “Are you sure you want to open this application?” dialog
set_defaults_if_missing com.apple.LaunchServices LSQuarantine -bool false
# Trackpad, mouse, keyboard, Bluetooth accessories, and input
# The following settings are seeded by the operating system, so we need to overwrite the values instead
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad DragLock 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Dragging 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadFiveFingerPinchGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadFourFingerHorizSwipeGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadFourFingerPinchGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadFourFingerVertSwipeGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadHandResting 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadHorizScroll 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadMomentumScroll 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadPinch 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRotate 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadScroll 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDrag 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerHorizSwipeGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerTapGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerVertSwipeGesture 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadTwoFingerDoubleTapGesture 1
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadTwoFingerFromRightEdgeSwipeGesture 3
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad USBMouseStopsTrackpad 0
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad UserPreferences 1
# Use list view in all Finder windows by default
set_defaults_if_missing com.apple.finder FXPreferredViewStyle -string "Nlsv"
set_defaults_if_missing com.apple.finder FXDefaultSearchScope -string "SCcf"
# Enable AirDrop over Ethernet and on unsupported Macs running Lion
set_defaults_if_missing com.apple.NetworkBrowser BrowseAllInterfaces -bool true
# Show the ~/Library folder
chflags nohidden ~/Library && xattr -d com.apple.FinderInfo ~/Library
# Show the /Volumes folder
sudo chflags nohidden /Volumes
}
ask_for_sudo_while_script_runs
make_and_install_roots
install_homebrew
configure_defaults