-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·203 lines (176 loc) · 6.07 KB
/
setup.sh
File metadata and controls
executable file
·203 lines (176 loc) · 6.07 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env zsh
main() {
ask_for_sudo
install_xcode_command_line_tools # next step requires "git" installed with xcode
install_homebrew
install_packages_with_brewfile
remove_packages_not_in_brewfile
install_nvm # nvm doesn't support homebrew
setup_fzf
setup_symlinks
setup_macos_system_and_application_preferences
remind_manual
}
DOTFILES_REPO=~/dotfiles
# Credit: https://github.com/sam-hosseini/dotfiles/blob/92cdd34570629fdb6d3e94865ba6b8bedd99dbe8/bootstrap.sh#L23
function ask_for_sudo {
notify "INFO" 0 "\nPrompting for sudo password"
if sudo --validate; then
# Keep-alive
while true; do sudo --non-interactive true; \
sleep 10; kill -0 "$$" || exit; done 2>/dev/null &
notify "SUCCESS" 1 "Sudo password updated"
else
echo "FAIL" 1 "Sudo password update failed"
exit 1
fi
}
# Credit: https://github.com/sam-hosseini/dotfiles/blob/92cdd34570629fdb6d3e94865ba6b8bedd99dbe8/bootstrap.sh#L35
function install_xcode_command_line_tools {
notify "INFO" 0 "\nInstalling Xcode command line tools"
if softwareupdate --history | grep --silent "Command Line Tools"; then
notify "INFO" 1 "Xcode command line tools already exists"
else
xcode-select --install
read -n 1 -s -r -p "Press any key once installation is complete"
if softwareupdate --history | grep --silent "Command Line Tools"; then
notify "SUCCESS" 1 "Xcode command line tools installation succeeded"
else
notify "FAIL" 1 "Xcode command line tools installation failed"
exit 1
fi
fi
}
# Credit: https://github.com/sam-hosseini/dotfiles/blob/92cdd34570629fdb6d3e94865ba6b8bedd99dbe8/bootstrap.sh#L52
function install_homebrew {
notify "INFO" 0 "\nInstalling Homebrew"
if hash brew 2>/dev/null; then
notify "INFO" 1 "Homebrew already exists; updating"
if brew update &> /dev/null; then
notify "SUCCESS" 2 "Homebrew updated successfully"
else
notify "FAIL" 2 "Homebrew failed to update"
fi
else
url=https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
if yes | /bin/bash -c "$(curl -fsSL ${url})"; then
notify "SUCCESS" 1 "Homebrew installation succeeded"
else
notify "FAIL" 1 "Homebrew installation failed"
exit 1
fi
fi
}
function install_packages_with_brewfile {
notify "INFO" 0 "\nInstalling Brewfile packages"
BREWFILE=${DOTFILES_REPO}/Brewfile
if brew bundle check --file="$BREWFILE" &> /dev/null; then
notify "INFO" 1 "Brewfile packages already installed"
else
if brew bundle --file="$BREWFILE"; then
notify "SUCCESS" 1 "Brewfile packages installation succeeded"
else
notify "FAIL" 1 "Brewfile packages installation failed"
exit 1
fi
fi
}
function remove_packages_not_in_brewfile() {
notify "INFO" 0 "\nRemoving Brew packages not listed in Brewfile"
if [ "$(brew bundle cleanup)" != "" ]; then
if brew bundle cleanup --force; then
notify "SUCCESS" 1 "Packages removed successfully"
else
notify "FAIL" 1 "Failed to remove some packages"
fi
else
notify "INFO" 1 "No packages to remove"
fi
}
function install_nvm {
notify "INFO" 0 "\nInstalling nvm"
if [ -d "$HOME/.nvm" ]; then
notify "INFO" 1 "Nvm already installed"
else
if git clone https://github.com/nvm-sh/nvm.git $HOME/.nvm &> /dev/null; then
notify "SUCCESS" 1 "Nvm successfully cloned"
if [ $? -eq 0 ]; then
git -C $HOME/.nvm checkout v0.35.1 &> /dev/null
if [ $? -eq 0 ]; then
notify "SUCCESS" 2 "Latest version of nvm checkout out"
else
notify "FAIL" 2 "Failed to checkout latest version of nvm"
exit 1
fi
else
notify "FAIL" 2 "Failed to clone nvm repo"
exit 1
fi
notify "SUCCESS" 1 "Successfully installed nvm"
else
notify "FAIL" 1 "Nvm failed to clone"
fi
fi
}
function setup_fzf {
notify "INFO" 0 "\nSetting up fzf"
$(brew --prefix)/opt/fzf/install --no-fish --no-bash --no-update-rc --key-bindings --completion
notify "SUCCESS" 1 "fzf key bindings and fuzzy completion done"
}
function setup_symlinks {
notify "INFO" 0 "\nSetting up symlinks"
# vscode settings
mkdir -p $HOME/Library/Application\ Support/Code/User/snippets
symlink "vscode:settings.json" ${DOTFILES_REPO}/vscode/settings.json $HOME/Library/Application\ Support/Code/User/settings.json
symlink "vscode:keybindings.json" ${DOTFILES_REPO}/vscode/keybindings.json $HOME/Library/Application\ Support/Code/User/keybindings.json
symlink "vscode:snippets" ${DOTFILES_REPO}/vscode/snippets/ $HOME/Library/Application\ Support/Code/User/snippets
# amethyst settings
symlink "amethyst:plist" ${DOTFILES_REPO}/amethyst/plist $HOME/Library/Preferences/com.amethyst.Amethyst.plist
notify "INFO" 1 "Symlinks setup complete"
}
function symlink() {
application=$1
the_dir=$2
the_link=$3
if rm -rf "$the_link" && ln -s "$the_dir" "$the_link"; then
notify "SUCCESS" 1 "Symlinking for \"${application}\" done"
else
notify "FAIL" 1 "Symlinking for \"${application}\" failed"
exit 1
fi
}
function setup_macos_system_and_application_preferences {
notify "INFO" 0 "\nSetting MacOS system and application preferences"
if source $HOME/.macos; then
notify "SUCCESS" 1 "Preferences successfully applied"
else
notify "FAIL" 1 "Preferences failed to apply"
fi
}
function remind_manual() {
notify "INFO" 0 "\nManual install the following:\nAlacritty\nSnagIt\nAmethyst\nChrome\nLast Pass\nSlack\nObsidian\nVLC\nPacker (after NeoVim build & install)\nWallpapers: https://wall.alphacoders.com/by_sub_category.php?id=173052&name=Girl+Wallpapers\nSpace Launcher: https://spacelauncherapp.com/\n"
}
function notify() {
local TYPE=$1 # ""/"INFO", "SUCCESS", "FAIL"
local INDENT=$2 # 0..infinity
local MSG=$3
local OUT=""
while [ $INDENT -gt 0 ]; do
OUT="$OUT--"
if [ $INDENT -eq 1 ]; then
OUT="$OUT> "
fi
INDENT=$((INDENT-1))
done
case $TYPE in
"SUCCESS")
OUT="$OUT\e[38;5;47m" # Green
;;
"FAIL")
OUT="$OUT\e[38;5;160m" # Red
;;
esac
OUT="$OUT$MSG\e[0m"
echo -e "$OUT"
}
main "$@"