forked from denysdovhan/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·236 lines (192 loc) · 5.06 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
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
232
233
234
235
236
#!/usr/bin/env bash
# Dotfiles and bootstrap installer
# Installs git, clones repository and symlinks dotfiles to your home directory
set -e
trap on_error SIGTERM
e='\033'
RESET="${e}[0m"
BOLD="${e}[1m"
CYAN="${e}[0;96m"
RED="${e}[0;91m"
YELLOW="${e}[0;93m"
GREEN="${e}[0;92m"
_exists() {
command -v "$1" > /dev/null 2>&1
}
# Success reporter
info() {
echo -e "${CYAN}${*}${RESET}"
}
# Error reporter
error() {
echo -e "${RED}${*}${RESET}"
}
# Success reporter
success() {
echo -e "${GREEN}${*}${RESET}"
}
# End section
finish() {
success "Done!"
echo
sleep 1
}
# Set directory
export DOTFILES=${1:-"$HOME/.dotfiles"}
GITHUB_REPO_URL_BASE="https://github.com/denysdovhan/dotfiles"
HOMEBREW_INSTALLER_URL="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
on_start() {
info " __ __ ____ _ __ "
info " ____/ /____ / /_ / __/(_)/ /___ _____"
info " / __ // __ \ / __// /_ / // // _ \ / ___/"
info " _ / /_/ // /_/ // /_ / __// // // __/(__ ) "
info " (_)\__,_/ \____/ \__//_/ /_//_/ \___//____/ "
info " "
info " by @denysdovhan "
info " "
info "This script will guide you through installing git, zsh and dofiles itself."
echo "It will not install anything without your direct agreement!"
echo
read -p "Do you want to proceed with installation? [y/N] " -n 1 answer
echo
if [ "${answer}" != "y" ]; then
exit
fi
}
install_homebrew() {
info "Trying to detect installed Homebrew..."
if ! _exists brew; then
echo "Seems like you don't have Homebrew installed!"
read -p "Do you agree to proceed with Homebrew installation? [y/N] " -n 1 answer
echo
if [ "${answer}" != "y" ]; then
return
fi
info "Installing Homebrew..."
bash -c "$(curl -fsSL ${HOMEBREW_INSTALLER_URL})"
eval "$(/opt/homebrew/bin/brew shellenv)"
else
success "You already have Homebrew installed. Skipping..."
fi
finish
}
install_git() {
info "Trying to detect installed Git..."
if ! _exists git; then
echo "Seems like you don't have Git installed!"
read -p "Do you agree to proceed with Git installation? [y/N] " -n 1 answer
echo
if [ "${answer}" != "y" ]; then
return
fi
info "Installing Git..."
if [ "$(uname)" = "Darwin" ]; then
brew install git
elif [ "$(uname)" = "Linux" ]; then
sudo apt install git
else
error "Error: Failed to install Git!"
return
fi
else
success "You already have Git installed. Skipping..."
fi
finish
}
install_zsh() {
info "Trying to detect installed Zsh..."
if ! _exists zsh; then
echo "Seems like you don't have Zsh installed!"
read -p "Do you agree to proceed with Zsh installation? [y/N] " -n 1 answer
echo
if [ "${answer}" != "y" ]; then
return
fi
info "Installing Zsh..."
if [ "$(uname)" = "Darwin" ]; then
brew install zsh zsh-completions
elif [ "$(uname)" = "Linux" ]; then
sudo apt install zsh
else
error "Error: Failed to install Zsh!"
return
fi
else
success "You already have Zsh installed. Skipping..."
fi
if _exists zsh && [[ -z "$ZSH_VERSION" ]]; then
info "Setting up Zsh as default shell..."
echo "The script will ask you the password for sudo:"
echo
echo "1) When changing your default shell via chsh -s"
echo
chsh -s "$(command -v zsh)" || error "Error: Cannot set Zsh as default shell!"
fi
finish
}
install_software() {
if [ "$(uname)" != "Darwin" ]; then
return
fi
info "Installing software..."
cd "$DOTFILES"
# Homebrew Bundle
if _exists brew; then
brew bundle
else
error "Error: Brew is not available"
fi
cd -
finish
}
install_npm() {
# Do not instal npm on non-macOS machines
if [ "$(uname)" != "Darwin" ]; then
return
fi
info "Installing global npm packages..."
packages=(
commitizen
npkill
fkill-cli
cz-conventional-changelog
)
echo "Installing: ${packages[*]}"
npm install -g "${packages[@]}"
finish
}
on_finish() {
echo
success "Setup was successfully done!"
success "Happy Coding!"
echo
echo -ne "$RED"'-_-_-_-_-_-_-_-_-_-_-_-_-_-_'
echo -e "$RESET""$BOLD"',------,'"$RESET"
echo -ne "$YELLOW"'-_-_-_-_-_-_-_-_-_-_-_-_-_-_'
echo -e "$RESET""$BOLD"'| /\_/\\'"$RESET"
echo -ne "$GREEN"'-_-_-_-_-_-_-_-_-_-_-_-_-_-'
echo -e "$RESET""$BOLD"'~|__( ^ .^)'"$RESET"
echo -ne "$CYAN"'-_-_-_-_-_-_-_-_-_-_-_-_-_-_'
echo -e "$RESET""$BOLD"'"" ""'"$RESET"
echo
info "P.S: Don't forget to restart a terminal :)"
echo
}
on_error() {
echo
error "Wow... Something serious happened!"
error "Though, I don't know what really happened :("
error "In case, you want to help me fix this problem, raise an issue -> ${CYAN}${GITHUB_REPO_URL_BASE}issues/new${RESET}"
echo
exit 1
}
main() {
on_start "$*"
install_homebrew "$*"
install_git "$*"
install_zsh "$*"
install_software "$*"
install_npm "$*"
on_finish "$*"
}
main "$*"