-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_macOS
executable file
·231 lines (181 loc) · 6.85 KB
/
setup_macOS
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env bash
declare -i exitcode
exitcode=0
# dotfiles directory
DOTFILES_DIRECTORY="${HOME}/dotfiles"
# get base directory
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Ask for the administrator password upfront
sudo -v
# ----------------------------------------------------
source "${BASEDIR}/shell_utils" || { echo "Failed to source shell_utils" >&2;exit 1; }
source "${BASEDIR}/homebrew/brew_install_packages" || { echo "Failed to source brew_install_packages" >&2;exit 1; }
# change to the dotfiles directory
# For some unknown reason it doesn't exist, exit!
# p_header "Changing to the ${DOTFILES_DIRECTORY} directory"
# cd "${DOTFILES_DIRECTORY}" || { echo "Failed to change directory to ${DOTFILES_DIRECTORY}" >&2;exit 1; }
# p_success "Done"
# ----------------------------------------------------
# Before relying on Homebrew, check that packages can be compiled by making sure
p_header "Checking for xcode command line tools..."
if ! xcode-select -p > /dev/null; then
printf "Installing xcode command line tools...\n"
xcode-select --install > /dev/null
# wait until the tools are installed...
until xcode-select -p > /dev/null; do
sleep 5;
done
# making sure we installed it
if xcode-select -p > /dev/null; then
p_success "Successfully installed xcode command line tools."
else
p_error "Failed to install xcode command line tools."
exit 1
fi
else
p_success "xcode command line tools already installed."
fi
# extend sudo timeout for another 5 mins
sudo -v
# ----------------------------------------------------
# Check for Homebrew
# Install homebrew and all the requested packages
p_header "Checking for homebrew..."
if ! type_exists 'brew'; then
p_header "Installing Homebrew..."
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if type_exists 'brew'; then
p_success "Successfully installed homebrew"
brew_install_basic
else
p_error "Failed to install homebrew."
exit 1
fi
else
p_success "Homebrew already installed."
brew_install_basic
fi
# extend sudo timeout for another 5 mins
sudo -v
# ----------------------------------------------------
# Check for git
# Git will be installed with xcode command line tools. If not
# then install with homebrew
p_header "Checking for git..."
if ! type_exists 'git'; then
p_header "Updating Homebrew..."
brew update > /dev/null
p_success "Homebrew updated"
p_header "Installing Git..."
brew install git
if type_exists 'git'; then
p_success "Successfully installed git."
else
p_error "Failed to install git."
exit 1
fi
else
p_success "Git already installed."
fi
# ----------------------------------------------------
# Oh My ZSH
p_header "Install Oh My ZSH"
TMP_INSTALL_PATH="${HOME}/.oh-my-zsh"
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Oh My ZSH already installed."
fi
# ----------------------------------------------------
# Zsh Syntax Highlighting
p_header "Install Zsh Syntax Highlighting"
TMP_INSTALL_PATH="${HOME}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${TMP_INSTALL_PATH}" || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Zsh Syntax Highlighting already installed."
fi
# ----------------------------------------------------
# Zsh Autosuggestions
p_header "Install Zsh Autosuggestions"
TMP_INSTALL_PATH="${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions "${TMP_INSTALL_PATH}" || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Zsh Autosuggestions already installed."
fi
# ----------------------------------------------------
# Zsh Completions
p_header "Install Zsh Completions"
TMP_INSTALL_PATH="${HOME}/.oh-my-zsh/custom/plugins/zsh-completions"
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
git clone https://github.com/zsh-users/zsh-completions "${TMP_INSTALL_PATH}" || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Zsh Completions already installed."
fi
# ----------------------------------------------------
# Powerlevel 10k
p_header "Install Powerlevel 10k"
TMP_INSTALL_PATH="${HOME}/.oh-my-zsh/custom/themes/powerlevel10k"
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "${TMP_INSTALL_PATH}" || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Powerlevel 10k already installed."
fi
# ----------------------------------------------------
# Linking dotfiles
link_dotfile "zsh/zshrc" ".zshrc" || exitcode=1
link_dotfile "p10k/p10k.zsh" ".p10k.zsh" || exitcode=1
link_dotfile "tmux/tmux.conf" ".tmux.conf" || exitcode=1
link_dotfile "tmux/tmux.conf.local" ".tmux.conf.local" || exitcode=1
link_dotfile "vim/vimrc" ".vimrc" || exitcode=1
link_dotfile "git/gitconfig" ".gitconfig" || exitcode=1
mkdir -p "${HOME}/.config/git/"
link_dotfile "git/gitignore" ".config/git/ignore" || exitcode=1
# ----------------------------------------------------
# Vim plugins
p_header "Install Vundle"
TMP_INSTALL_PATH="${HOME}/.vim/bundle/Vundle.vim"
# Check VundleVim URL
if curl --output /dev/null --silent --head --fail "https://github.com/VundleVim/Vundle.vim"; then
# Add your commands for section A here
if [[ ! -d "${TMP_INSTALL_PATH}" ]]; then
git clone https://github.com/VundleVim/Vundle.vim.git "${TMP_INSTALL_PATH}" || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
p_success "Vundle already installed."
fi
p_header "Install Vim plugins via Vundle"
vim +PluginInstall +qall > /dev/null || { echo "Failed" >&2;exit 1; }
p_success "Done"
else
echo "The VundleVim URL is not valid. Skipping VundleVim."
fi
# ----------------------------------------------------
# Personal scripts
p_header "Copy personal scripts to user home bin"
if [[ ! -d "${HOME}/bin" ]]; then
mkdir -v "${HOME}/bin" || { echo "Failed" >&2;exit 1; }
fi
# -n for do not overwriting
# -v for verbose
cp -vn bin/* "${HOME}/bin"
p_success "Done"
# ----------------------------------------------------
# macOS System Preferences
p_header "Setting Custom System Preferences"
bash "${BASEDIR}/macos/macOS_custom_setup.sh" || exitcode=1
p_success "Done"
# ----------------------------------------------------
# Exit
if [ ! ${exitcode} -eq 0 ]; then
echo "Some parts failed"
else
p_success "------ All Completed ------"
fi
exit ${exitcode}