-
Notifications
You must be signed in to change notification settings - Fork 14
/
my_tools_installer.bash
executable file
·135 lines (112 loc) · 3.1 KB
/
my_tools_installer.bash
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
#!/bin/bash
#Author Omar BOUYKOURNE
#42login : obouykou
#print a banner, and update all files
./scripts/banner.bash
git pull &>/dev/null
OLD_PATH=$PATH
# check storage first
if ! ./scripts/check_storage.bash; then
exit 1
fi
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
ctrl_c() {
echo -en "\b\b\b"
pkill -f spin &>/dev/null
stty echo
exit 1
}
# declaring programs arrays, and another for their confirmations
progs=(valgrind node docker docker-machine minikube)
declare -a alreadyInstalledProgs
export PATH=$HOME/goinfre/.brew/bin:$PATH
# remove the already installed programs from the progs array
# and add them to the alreadyInstalledProgs array
for i in "${!progs[@]}"; do
if [[ -f "$HOME"/goinfre/.brew/bin/${progs[$i]} ]] || which "${progs[$i]}" &>/dev/null; then
alreadyInstalledProgs+=("${progs[$i]}")
unset "progs[$i]"
fi
done
# print all the already installed progs elements with a loop
if [[ ${#alreadyInstalledProgs[@]} != "0" ]]; then
printf "\nThe following programs are already installed:\n\n"
fi
for prog in "${alreadyInstalledProgs[@]}"; do
sleep 0.3
printf "\033[33m--- %s \033[0m ===> $(which "$prog")\n" "$prog"
done
echo
# if there is no progs to install, exit
if [[ "${#progs[@]}" == "0" ]]; then
echo -e "\n\033[32m------- All programs are already installed -------\033[0m\n"
sleep 1
exit 0
fi
# confirm brew installation
sleep 0.3
echo -e "\n\033[33mDo you want to install: \033[0m"
# is something is selected
shouldInstall=0
declare -a progsToInstall
# get programs installation confirmations
for prog in "${progs[@]}"; do
./scripts/is_confirmed.bash "$prog"
# if at least one is selected, set shouldInstall to 1
if [[ "$?" == "1" ]]; then
shouldInstall=1
progsToInstall+=("$prog")
fi
done
# check if the confirmation array is empty
if [[ "$shouldInstall" == "0" ]]; then
echo -e "\n\033[31m------- No program selected -------\033[0m\n"
exit 0
fi
# show cursor and enable keyboard
cleanup() {
tput cnorm
stty echo
pkill -f spin &>/dev/null
/bin/rm -rf ~/.curlrc &>/dev/null
/bin/rm -rf error.log &>/dev/null
export PATH=$OLD_PATH
SHELL_LANG=$(echo -n "$SHELL" | awk -F / '{print $3}')
shell_f="${HOME}/.${SHELL_LANG}rc"
brew &>/dev/null
if [[ "$?" == "127" ]]; then
echo -e "\n\033[32m ⛔️ Please, run this command: [ source $shell_f ]\033[0m\n"
exit 1
fi
exit 0
}
# get back the cursor after exiting
trap cleanup EXIT
# hide cursor
tput civis
# disable keyboard
stty -echo
# start installing
echo -e "\n\033[33mInstalling programs...\033[0m"
# install brew if confirmed and update PATH
if [[ ! -f "$HOME"/goinfre/.brew/bin/brew ]]; then
if ! ./scripts/brew_installer.bash; then
exit 1
fi
./scripts/update_PATH.bash
fi
# install all confirmed installations
for prog in "${progsToInstall[@]}"; do
./scripts/installer.bash "$prog"
done
if [[ " ${progsToInstall[*]} " =~ " docker " ]]; then
./scripts/make_data_dir.bash docker
fi
if [[ " ${progsToInstall[*]} " =~ " minikube " ]]; then
./scripts/make_data_dir.bash minikube
fi
if [[ " ${progsToInstall[*]} " =~ " docker " ]] || [[ " ${progsToInstall[*]} " =~ " docker-machine " ]]; then
./scripts/dmcm_installer.bash
fi
exit 0