forked from ladislas/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
Β·296 lines (238 loc) Β· 6.52 KB
/
bootstrap.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/env zsh
#
# Source helper functions
#
trap "exit 1" INT
typeset -x DOTFILES_DIR=$(pwd)
typeset -Ux FAILED_COMMANDS=()
typeset -Ux CAN_FAIL_COMMANDS=()
typeset -x ARG_ARRAY=()
# create tmp file & schedule delete if error
typeset -x TEMP_FILE=$(mktemp)
trap "rm -f $TEMP_FILE" 0 2 3 15
source $DOTFILES_DIR/scripts/helpers/include.sh
function try {
. $DOTFILES_DIR'/scripts/helpers/try.sh' $@
}
alias try_can_fail="try -x"
#
# Set output level (verbose / super verbose)
#
if [[ "$@" =~ "-vv" ]]; then
alias try="try -vv"
elif [[ "$@" =~ "-v" || "$@" =~ "--verbose" ]]; then
alias try="try -v"
fi
#
# Set arguments
#
qualifier_commands=( "-v" "-vv" "--verbose" "--force" )
main_commands=( "--all" "--ci" "--dry-run" )
ci_commands=( "--hello" "--zsh" "--git" "--nvim" "--data" "--macos" "--brew" "--apps-install" "--apps-config" )
script_commands=( "--hello" "--zsh" "--git" "--nvim" "--data" "--macos" "--brew" "--apps-install" "--apps-config" "--dev" "--rsync" )
ARG_ARRAY=($@)
available_args=( ${qualifier_commands[*]} ${main_commands[*]} ${script_commands[*]} )
#
# Check that arguments have been passed, if not exit
#
if array_is_empty $ARG_ARRAY ; then
echo "π₯ No arguments have been passed."
echo "Please try again with one of those: $available_args"
exit 1
fi
#
# Check that passed arguments are available, if not exit
#
for arg in $ARG_ARRAY; do
if [[ ! " ${available_args[@]} " =~ " ${arg} " ]]; then
echo "π₯ Unrecognized argument: $arg"
echo "Please try again with one of those: $available_args"
exit 1
fi
done
#
# Arg: --dry-run
#
if is_dry_run ; then
echo ""
echo "π Running bootstrap as dry run. Nothing will be installed or modified... π‘οΈ"
typeset -x DRY_RUN=true
fi
#
# Check for brew & coreutils, if not install
#
if ! is_dry_run ; then
print_section "Checking for brew & coreutils"
if [[ $(command -v brew) == "" ]]; then
print_action "Install brew"
fake_try "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\""
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
if [[ $(command -v gls) == "" ]]; then
print_action "Install coreutils"
fake_try "brew install coreutils"
brew install coreutils
fi
if [ ! $? -eq 0 ]; then
echo "π₯ Could not install brew & coreutils, exiting with status code $?"
exit 1
fi
fi
if test -d "/opt/homebrew/bin"; then
export BREW_PREFIX="/opt/homebrew"
elif test -d "/usr/local/bin"; then
export BREW_PREFIX="/usr/local"
fi
print_action "Add gnubin to path"
fake_try "export PATH=\"$BREW_PREFIX/opt/coreutils/libexec/gnubin:\$PATH\""
export PATH="$BREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
#
# Arg: --all
#
if args_contain "--all" ; then
if ! args_contain "--force" ; then
echo ""
echo "π₯ π₯ π₯"
echo "You are about to run all the scripts. This it NOT recommended"
echo "unless you know what you are doing! Unexepected behaviors can occur!"
echo "π₯ π₯ π₯"
echo ""
echo "Please confirm that you have read the source files and are okay with that."
printf "π Are you sure you want to continue? (y/n) "
read
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
echo ""
echo "Goodbye, come again!..."
exit 0
fi
fi
echo ""
echo "β οΈ Running bootstrap with all args! β οΈ"
echo "\t$script_commands"
ARG_ARRAY=($script_commands)
fi
#
# Arg: --ci
#
if args_contain "--ci" ; then
echo ""
echo "π¬ Running bootstrap for testing with the following args: π§ͺ"
echo "\t$ci_commands"
ARG_ARRAY=($ci_commands)
fi
#
# Sudo power
#
if args_contain "--macos" || args_contain "--brew" ; then
if ! sudo -n true 2>/dev/null; then
echo ""
echo "π Args --macos & --brew require sudo to run. π"
ask_for_sudo
fi
fi
#
# Arg: --hello
#
if args_contain "--hello" ; then
print_section "Starting Hello, World! script"
print_action "Make sure we're good to go"
try echo "Hello, World!"
# try sleep 3
try echo "Let's get moving!"
try_can_fail false
fi
#
# Arg: --brew
#
if args_contain "--brew" ; then
print_section "Starting brew configuration script"
source $DOTFILES_DIR/scripts/brew.sh
fi
#
# Arg: --apps-install
#
if args_contain "--apps-install" ; then
print_section "Starting applications installation script"
source $DOTFILES_DIR/scripts/apps.sh
fi
#
# Arg: --apps-config
#
if args_contain "--apps-config" ; then
print_section "Starting applications configuration script"
source $DOTFILES_DIR/scripts/apps_config.sh
fi
#
# Arg: --zsh
#
if args_contain "--zsh" ; then
print_section "Starting zsh configuration script"
# Switch to using brew-installed zsh as default shell
if ! fgrep -q "${BREW_PREFIX}/bin/zsh" /etc/shells ; then
print_action "Setting brew zsh as default shell"
try echo "${BREW_PREFIX}/bin/zsh" | sudo tee -a /etc/shells;
try chsh -s "${BREW_PREFIX}/bin/zsh";
fi;
print_action "Clean up zcompdump"
try rm -f ~/.zcompdump
try rm -f $DOTFILES_DIR/zsh/.zcompdump
try rm -f $DOTFILES_DIR/zsh/.zcompdump.zwc
print_action "chmod $BREW_PREFIX/share for completion"
try chmod -R go-w "$BREW_PREFIX/share"
print_action "Symlink config files"
try mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}
try ln -sr $DOTFILES_DIR/symlink/.zshenv $HOME/.zshenv
try ln -sr $DOTFILES_DIR/zsh ${XDG_CONFIG_HOME:-$HOME/.config}/
fi
#
# Arg: --git
#
if args_contain "--git" ; then
print_section "Starting git configuration script"
print_action "Symlink config files"
try mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}
try ln -sr $DOTFILES_DIR/git ${XDG_CONFIG_HOME:-$HOME/.config}/
fi
#
# Arg: --neovim
#
if args_contain "--nvim" ; then
print_section "Starting neovim configuration script"
print_action "Git clone neovim config"
try git clone --recursive https://github.com/ladislas/nvim ~/.config/nvim
fi
#
# Arg: --data
#
if args_contain "--data" ; then
print_section "Starting XDG Data configuration script"
print_action "Symlink config files"
try mkdir -p ${XDG_DATA_HOME:-$HOME/.local/share}
try ln -sr $DOTFILES_DIR/data/* ${XDG_DATA_HOME:-$HOME/.local/share}
fi
#
# Arg: --dev
#
if args_contain "--dev" ; then
print_section "Starting personnal dev configuration script"
source $DOTFILES_DIR/scripts/dev.sh
fi
#
# Arg: --macos
#
if args_contain "--macos" ; then
print_section "Starting macOS configuration script"
source $DOTFILES_DIR/scripts/macos.sh
fi
#
# Arg: --rsync
#
if args_contain "--rsync" ; then
print_section "Starting rsync configuration script"
source $DOTFILES_DIR/scripts/rsync_config.sh
fi
#
# List failed commands & delete TEMP_FILE
#
list_failed_commands
rm -rf $TEMP_FILE