-
Notifications
You must be signed in to change notification settings - Fork 23
/
bootstrap
executable file
·182 lines (169 loc) · 4.34 KB
/
bootstrap
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
178
179
180
181
182
#!/bin/sh
#
# Interactive Q&A shell script to setup a new system.
set -e
red="\e[0;31m"
green="\e[0;32m"
yellow="\e[0;33m"
blue="\e[0;34m"
magenta="\e[0;35m"
cyan="\e[0;36m"
reset="\e[0;0m"
colorize() {
printf "$cyan>>>$reset %s" "$*" 1>&2
}
# Make experience more pleasant.
log() {
colorize "$*"
printf "\n"
}
# Make experience more pleasant.
ask() {
colorize "$*"
printf "$green (y)es $reset" 1>&2
printf "/"
printf "$yellow (n)o $reset" 1>&2
printf "/"
printf "$red (q)uit $reset" 1>&2
IFS= read -s -n 1 action
case "$action" in
y)
printf "\n"
return 0
;;
n)
printf "\n"
return 1
;;
*)
exit 1
;;
esac
}
# Keeps sudo priviledge alive throughout the execution of this script.
enter_sudo_mode() {
if ! sudo -n true 2> /dev/null; then
log "please enter your password to maintain a sudo session"
sudo -v
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
fi
}
# MacOS-specific system changes.
setup_darwin() {
# Close any open System Preferences panes, to prevent them from
# overriding settings we're about to change.
log "closing System Preferences"
osascript -e 'tell application "System Preferences" to quit'
enter_sudo_mode
log "tuning macOS settings"
. bootstrap.macos
log "installing all available software updates"
sudo softwareupdate -i -a
log "installing XCode comand line developer tools"
xcode-select --install || true
}
setup_keyboard_layout() {
enter_sudo_mode
log "copying custom layout to /Library/Keyboard Layouts"
sudo cp mavam.keylayout /Library/Keyboard\ Layouts/
log "enable the new keyboard:"
log " (1) System Preferences → Keyboard → Input Sources"
log " (2) Search and select 'mavam'"
log "remap Caps Lock with Karabiner Elements:"
log " (1) Escape: when tapped"
log " (2) Left Alt: when held"
}
setup_homebrew() {
# Make sure we look at least in the default install location.
if which brew > /dev/null 2>&1; then
log "upgrading existing Homebrew packages"
brew upgrade
else
log "installing Homebrew"
homebrew="Homebrew/install/HEAD/install.sh"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/$homebrew)"
fi
}
setup_tmux() {
if [ ! -d ~/.tmux/plugins/tpm ]; then
log "installing Tmux plugins"
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
~/.tmux/plugins/tpm/bin/install_plugins
else
log "updating Tmux plugins"
~/.tmux/plugins/tpm/bin/update_plugins all
fi
}
setup_neovim() {
log "updating NeoVim plugins via Packer"
nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"
}
setup_fish() {
fish=$(which fish 2> /dev/null)
if [ -z "$fish" ]; then
log "fish not found :-("
else
if grep -Fq "$fish" /etc/shells; then
log "skipping /etc/shells, $fish already there"
else
log "adding $fish to /etc/shells"
echo "$fish" | sudo tee -a /etc/shells > /dev/null
fi
log "setting fish as login shell"
login_shell="$(dscl . -read ~ UserShell | cut -f 2 -d " ")"
if [ "$login_shell" = "$fish" ]; then
log "$fish is already your login shell"
else
sudo chsh -s "$fish" "$USER"
fi
if which fisher 2> /dev/null; then
log "updating fish plugins via fisher"
fisher update
fi
fi
}
main() {
export PATH="/opt/homebrew/bin:$PATH"
printf "$blue"
echo ' __ '
echo ' _ _____ / /________ ____ ___ ___ '
echo '| | /| / / _ \/ / ___/ __ \/ __ `__ \/ _ \'
echo '| |/ |/ / __/ / /__/ /_/ / / / / / / __/'
echo '|__/|__/\___/_/\___/\____/_/ /_/ /_/\___/ '
echo
printf "$reset"
if ask "setup dotfiles?"; then
sh "$(dirname "$0")/dots" install -a
fi
case "$(uname -s)" in
Darwin)
if ask "setup homebrew?"; then
setup_homebrew
fi
if ask "install Hombrew bundle?"; then
log "installing bundled Homebrew packages"
brew bundle "--file=$(dirname "$0")/homebrew/.Brewfile" || true
fi
if ask "tune macOS system settings?"; then
setup_darwin
fi
if ask "install keyboard layout?"; then
setup_keyboard_layout
fi
;;
esac
if ask "setup fish?"; then
setup_fish
fi
if ask "setup NeoVim?"; then
setup_neovim
fi
if ask "setup Tmux?"; then
setup_tmux
fi
}
main "$@"