-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·409 lines (363 loc) · 12 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·409 lines (363 loc) · 12 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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/bin/sh
set -eu
# Make sure important variables exist if not already defined
#
# $USER is defined by login(1) which is not always executed (e.g. containers)
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
USER=${USER:-$(id -u -n)}
# $HOME is defined at the time of login, but it could be unset. If it is unset,
# a tilde by itself (~) will not be expanded to the current user's home directory.
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
# macOS does not have getent, but this works even if $HOME is unset
HOME="${HOME:-$(eval echo ~$USER)}"
bold='\033[1m'
normal='\033[0m'
red='\033[0;31m'
blue='\033[0;34m'
bblue='\033[1;34m'
white='\033[0;37m'
green='\033[0;32m'
cyan='\033[0;36m'
elixir_version=1.19.5-otp-28
erlang_version=28.3.3
phoenix_version=1.8.4
case "${SHELL:-}" in
*bash)
current_shell="bash"
config_file="$HOME/.bashrc"
;;
*fish)
current_shell="fish"
config_file="$HOME/.config/fish/config.fish"
mkdir -p "$(dirname "$config_file")"
;;
*zsh)
current_shell="zsh"
config_file="$HOME/.zshrc"
;;
*)
printf "Unsupported shell: %s\n" "$SHELL"
exit 1
;;
esac
# Add OS detection
OS="$(uname -s)"
get_package_manager() {
if command -v apt-get >/dev/null; then
echo "apt"
elif command -v dnf >/dev/null; then
echo "dnf"
elif command -v pacman >/dev/null; then
echo "pacman"
elif command -v apk >/dev/null; then
echo "apk"
else
printf "Unsupported package manager. This script requires apt, dnf, pacman, or apk.\n"
exit 1
fi
}
case "${OS}" in
Linux*)
os_type=Linux
package_manager=$(get_package_manager)
;;
Darwin*)
os_type=macOS
;;
*)
printf "Unsupported OS: %s\n" "${OS}"
exit 1
;;
esac
already_installed() {
case "$1" in
"Elixir")
mise which elixir >/dev/null 2>&1
;;
"Erlang")
mise which erl >/dev/null 2>&1
;;
"git")
which git >/dev/null 2>&1
;;
"Homebrew")
which brew >/dev/null 2>&1
;;
"mise")
which mise >/dev/null 2>&1
;;
"Phoenix")
mix phx.new --version >/dev/null 2>&1
;;
"Xcode Command Line Tools")
which xcode-select >/dev/null 2>&1
;;
*)
printf "Invalid name argument on checking: %s\n" "$1"
exit 1
;;
esac
}
install() {
case "$1" in
"Elixir")
if [ "$os_type" = "Linux" ]; then
case "$package_manager" in
"apt")
sudo apt-get update
sudo apt-get install -y unzip
;;
"dnf")
sudo dnf install -y unzip
;;
"pacman")
sudo pacman -Sy --noconfirm unzip
;;
"apk")
sudo apk add --no-cache unzip
;;
esac
fi
mise use -g -y elixir@$elixir_version
;;
"Erlang")
if [ "$os_type" = "macOS" ]; then
brew install autoconf openssl wxwidgets libxslt fop
if [ ! -f ~/.kerlrc ]; then
printf "KERL_CONFIGURE_OPTIONS=\"--with-ssl=$(brew --prefix openssl) --without-javac\"\n" >~/.kerlrc
fi
ulimit -n 1024
else
case "$package_manager" in
"apt")
sudo apt-get update
sudo apt-get install -y build-essential automake autoconf libssl-dev libncurses5-dev
;;
"dnf")
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y openssl-devel ncurses-devel
;;
"pacman")
sudo pacman -Sy --noconfirm base-devel openssl ncurses
;;
"apk")
sudo apk add --no-cache build-base autoconf openssl-dev ncurses-dev
;;
esac
if [ ! -f ~/.kerlrc ]; then
printf "KERL_CONFIGURE_OPTIONS=\"--without-javac\"\n" >~/.kerlrc
fi
fi
mise use -g -y erlang@$erlang_version
;;
"git")
if [ "$os_type" = "Linux" ]; then
case "$package_manager" in
"apt")
sudo apt-get update
sudo apt-get install -y git
;;
"dnf")
sudo dnf install -y git
;;
"pacman")
sudo pacman -Sy --noconfirm git
;;
"apk")
sudo apk add --no-cache git
;;
esac
fi
;;
"Homebrew")
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
UNAME_MACHINE="$(/usr/bin/uname -m)"
if [[ "${UNAME_MACHINE}" == "arm64" ]]; then
if [ "$current_shell" = "fish" ]; then
fish_add_path /opt/homebrew/bin
else
(
echo
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"'
) >>$config_file
fi
eval "$(/opt/homebrew/bin/brew shellenv)"
else
if [ "$current_shell" = "fish" ]; then
fish_add_path /usr/local/bin
else
(
echo
echo 'eval "$(/usr/local/bin/brew shellenv)"'
) >>$config_file
fi
eval "$(/usr/local/bin/brew shellenv)"
fi
;;
"mise")
curl https://mise.run | sh
case $current_shell in
"bash")
echo 'eval "$(~/.local/bin/mise activate bash)"' >>$config_file
;;
"fish")
echo '~/.local/bin/mise activate fish | source' >>$config_file
;;
"zsh")
echo 'eval "$(~/.local/bin/mise activate zsh)"' >>$config_file
;;
esac
export PATH="$HOME/.local/bin:$PATH"
;;
"Phoenix")
mise exec -- mix local.hex --force
mise exec -- mix local.rebar --force
mise exec -- mix archive.install --force hex phx_new $phoenix_version
;;
"Xcode Command Line Tools")
xcode-select --install
;;
*)
printf "Invalid name argument on install: %s\n" "$1"
exit 1
;;
esac
}
maybe_install() {
if already_installed "$1"; then
printf "%s is already installed. Skipping...\n" "$1"
else
printf "Installing %s...\n" "$1"
if [ "$1" = "Homebrew" ] || [ "$1" = "Erlang" ]; then
printf "This might take a while.\n"
fi
printf "\n"
install "$1"
fi
}
add_env() {
printf "\n"
# Ask for sudo password upfront
sudo -v
# Keep sudo alive
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
if [ "$os_type" = "macOS" ]; then
printf "${white}\n"
sleep 1.5
maybe_install "Xcode Command Line Tools"
printf "${white}\n"
sleep 1.5
maybe_install "Homebrew"
else
printf "${white}\n"
sleep 1.5
maybe_install "git"
fi
printf "${white}\n"
sleep 1.5
maybe_install "mise"
printf "${white}\n"
sleep 1.5
maybe_install "Erlang"
printf "${white}\n"
sleep 1.5
maybe_install "Elixir"
printf "${white}\n"
sleep 1.5
maybe_install "Phoenix"
printf "${white}\n"
printf "${cyan}${bold}phx.tools setup is complete!\n"
printf "${cyan}${bold}Please restart the terminal and type in the following command:\n"
printf "${cyan}${bold}mix phx.new\n"
printf "${white}\n"
}
phx_tools="
██████╗░██╗░░██╗██╗░░██╗ ████████╗░█████╗░░█████╗░██╗░░░░░░██████╗
██╔══██╗██║░░██║╚██╗██╔╝ ╚══██╔══╝██╔══██╗██╔══██╗██║░░░░░██╔════╝
██████╔╝███████║░╚███╔╝░ ░░░██║░░░██║░░██║██║░░██║██║░░░░░╚█████╗░
██╔═══╝░██╔══██║░██╔██╗░ ░░░██║░░░██║░░██║██║░░██║██║░░░░░░╚═══██╗
██║░░░░░██║░░██║██╔╝╚██╗ ░░░██║░░░╚█████╔╝╚█████╔╝███████╗██████╔╝
╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝ ░░░╚═╝░░░░╚════╝░░╚════╝░╚══════╝╚═════╝░
"
by="
██████╗░██╗░░░██╗
██╔══██╗╚██╗░██╔╝
██████╦╝░╚████╔╝░
██╔══██╗░░╚██╔╝░░
██████╦╝░░░██║░░░
╚═════╝░░░░╚═╝░░░
"
optimum="
░█████╗░██████╗░████████╗██╗███╗░░░███╗██╗░░░██╗███╗░░░███╗██████╗░██╗░░██╗
██╔══██╗██╔══██╗╚══██╔══╝██║████╗░████║██║░░░██║████╗░████║██╔══██╗██║░░██║
██║░░██║██████╔╝░░░██║░░░██║██╔████╔██║██║░░░██║██╔████╔██║██████╦╝███████║
██║░░██║██╔═══╝░░░░██║░░░██║██║╚██╔╝██║██║░░░██║██║╚██╔╝██║██╔══██╗██╔══██║
╚█████╔╝██║░░░░░░░░██║░░░██║██║░╚═╝░██║╚██████╔╝██║░╚═╝░██║██████╦╝██║░░██║
░╚════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝╚═╝░░░░░╚═╝░╚═════╝░╚═╝░░░░░╚═╝╚═════╝░╚═╝░░╚═╝
"
printf "%s\n" "$phx_tools"
printf "%s\n" "$by"
printf "%s\n" "$optimum"
sleep 3
printf "\n"
printf "${bblue}${bold}Welcome to the phx.tools shell script for ${os_type}.\n"
sleep 3
printf "\n"
printf "${bblue}${bold}The following will be installed if not available already:\n"
printf "${cyan}${bold}\n"
if [ "$os_type" = "macOS" ]; then
printf "1) Build dependencies\n"
printf "2) Homebrew\n"
printf "3) mise\n"
printf "4) Erlang\n"
printf "5) Elixir\n"
printf "6) Phoenix\n"
else
printf "1) Build dependencies\n"
printf "2) mise\n"
printf "3) Erlang\n"
printf "4) Elixir\n"
printf "5) Phoenix\n"
fi
printf "\n"
printf "${white}${bold}\n"
sleep 1
is_yn() {
case "$1" in
[yY] | [yY][eE][sS])
true
;;
[nN] | [nN][oO])
true
;;
*)
false
;;
esac
}
answer=''
while ! is_yn "$answer"; do
printf "Do you want to continue? (y/n) "
read -r answer
printf "\n"
case "$answer" in
[yY] | [yY][eE][sS])
printf "\n"
sleep 3
add_env
;;
[nN] | [nN][oO])
printf "Thank you for your time\n"
printf "\n"
;;
*)
printf "Please enter y or n\n"
printf "\n"
;;
esac
done