-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependency_installer.sh
executable file
Β·235 lines (218 loc) Β· 5.73 KB
/
dependency_installer.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
#!/bin/bash
# Get the top-level directory of the git repository
top_dir=$(git rev-parse --show-toplevel)
term_color_path="$top_dir/scripts/utils/term_color.sh"
os_detect_path="$top_dir/scripts/utils/os_detect.sh"
# Source the utility scripts
source "$term_color_path"
source "$os_detect_path"
# Language list
languages=(
"C"
"C++"
"C#"
"Dart"
"Go"
"Haskell"
"Java"
"Javascript"
"Kotlin"
"Ruby"
"Rust"
"PHP"
"Python2"
"PyPy2"
"Python3"
"PyPy3"
"Scala"
"Elixir"
"Assembly (NASM)"
"Perl"
"COBOL"
"Pascal (FPC)"
"Crystal"
"Fortran"
"Erlang"
"Lua"
"Brainf*ck"
"OCaml"
)
# Initialize language flags
HAS_C=0
HAS_CPP=0
HAS_CSHARP=0
HAS_DART=0
HAS_GO=0
HAS_HASKELL=0
HAS_JAVA=0
HAS_JAVASCRIPT=0
HAS_KOTLIN=0
HAS_RUBY=0
HAS_RUST=0
HAS_PHP=0
HAS_PYTHON2=0
HAS_PYPY2=0
HAS_PYTHON3=0
HAS_PYPY3=0
HAS_SCALA=0
HAS_ELIXIR=0
HAS_NASM=0
HAS_PERL=0
HAS_COBOL=0
HAS_PASCAL=0
HAS_CRYSTAL=0
HAS_FORTRAN=0
HAS_ERLANG=0
HAS_LUA=0
HAS_BF=0
HAS_OCAML=0
# Language selection helper function
lang_select_help() {
echo "Select the languages you want to install:"
echo "Enter the number of the language you want to install, or 'q' to exit or 'h' for help."
echo "Languages:"
for idx in ${!languages[@]}; do
echo "${bld}$((idx + 1)): ${rst}${languages[$idx]}"
done
}
# Check if the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "${txtred}Please run as root or use sudo.${rst}"
exit 1
fi
echo "${txtred}ubilo-judger ${rst}dependency installer"
echo "Select a preset to install dependencies:"
options=("Minimal" "Standard" "Full" "Custom" "Exit")
option_explanations=(
"C, C++, Python3"
"C, C++, C#, Python2/3 (+PyPy2/3), Java, Javascript"
"C, C++, C#, Dart, Go, Haskell, Java, Javascript, Kotlin, Ruby, Rust, PHP, Python2/3 (+PyPy2/3),
Scala, Elixir, Assembly (NASM), Perl, COBOL, Pascal (FPC), Crystal, Fortran,
Erlang, Lua, OCaml, Brainf*ck"
"Select the languages you want to install."
"Exit the installer."
)
# Display preset options
for idx in ${!options[@]}; do
echo "${bld}[$idx] ${options[$idx]}:${rst} ${option_explanations[$idx]}"
done
# Read user input for preset selection
read -rp "Enter the number of the preset you want to install: " preset
# Function to set language flags based on selections
set_language_flags() {
for lang in "${selections[@]}"; do
case "$lang" in
"C") HAS_C=1 ;;
"C++") HAS_CPP=1 ;;
"C#") HAS_CSHARP=1 ;;
"Dart") HAS_DART=1 ;;
"Go") HAS_GO=1 ;;
"Haskell") HAS_HASKELL=1 ;;
"Java") HAS_JAVA=1 ;;
"Javascript") HAS_JAVASCRIPT=1 ;;
"Kotlin") HAS_KOTLIN=1 ;;
"Ruby") HAS_RUBY=1 ;;
"Rust") HAS_RUST=1 ;;
"PHP") HAS_PHP=1 ;;
"Python2") HAS_PYTHON2=1 ;;
"PyPy2") HAS_PYPY2=1 ;;
"Python3") HAS_PYTHON3=1 ;;
"PyPy3") HAS_PYPY3=1 ;;
"Scala") HAS_SCALA=1 ;;
"Elixir") HAS_ELIXIR=1 ;;
"Assembly (NASM)") HAS_NASM=1 ;;
"Perl") HAS_PERL=1 ;;
"COBOL") HAS_COBOL=1 ;;
"Pascal (FPC)") HAS_PASCAL=1 ;;
"Crystal") HAS_CRYSTAL=1 ;;
"Fortran") HAS_FORTRAN=1 ;;
"Erlang") HAS_ERLANG=1 ;;
"Lua") HAS_LUA=1 ;;
"OCaml") HAS_OCAML=1 ;;
"Brainf*ck") HAS_BF=1 ;;
esac
done
}
# Handle preset selection
case $preset in
0)
selections=("C" "C++" "Python3")
;;
1)
selections=("C" "C++" "C#" "Python2" "PyPy2" "Python3" "PyPy3" "Java" "Javascript")
;;
2)
selections=("C" "C++" "C#" "Dart" "Go" "Haskell" "Java" "Javascript" "Kotlin" "Ruby" "Rust" "PHP" "Python2" "PyPy2" "Python3"
"PyPy3" "Scala" "Elixir" "Assembly (NASM)" "Perl" "COBOL" "Pascal (FPC)" "Crystal" "Fortran" "Erlang" "Lua" "OCaml"
"Brainf*ck")
;;
3)
selections=()
lang_select_help
while true; do
read -rp "Enter the number of the language you want to install (1-29), 'q' to quit, 'h' for help or 'c' to confirm, to deselect rewrite the number: " selection
case "$selection" in
[1-9] | 1[0-9] | 2[0-9])
lang_idx=$((selection - 1))
lang=${languages[lang_idx]}
if [[ " ${selections[@]} " =~ " $lang " ]]; then
selections=("${selections[@]/$lang/}")
echo "${txtred}Deselected ${languages[lang_idx]}.${rst}"
else
selections+=("$lang")
echo "${txtgrn}Selected ${languages[lang_idx]}.${rst}"
fi
;;
q)
echo "${txtred}Exiting...${rst}"
exit 0
;;
c)
echo "${txtgrn}Selected languages: ${selections[@]}.${rst}"
echo "Are you sure you want to install these languages?"
read -rp "Enter 'y' to confirm or 'n' to select again: " confirm
if [ "$confirm" = "y" ]; then
break
fi
;;
h)
lang_select_help
;;
*)
echo "Invalid option."
;;
esac
done
;;
4)
echo "${txtgrn}Exiting...${rst}"
exit 0
;;
*)
echo "${txtred}Invalid option.${rst}"
exit 1
;;
esac
set_language_flags
cli_arg="HAS_C=$HAS_C HAS_CPP=$HAS_CPP HAS_CSHARP=$HAS_CSHARP HAS_DART=$HAS_DART HAS_GO=$HAS_GO HAS_HASKELL=$HAS_HASKELL
HAS_JAVA=$HAS_JAVA HAS_JAVASCRIPT=$HAS_JAVASCRIPT HAS_KOTLIN=$HAS_KOTLIN HAS_RUBY=$HAS_RUBY
HAS_RUST=$HAS_RUST HAS_PHP=$HAS_PHP HAS_PYTHON2=$HAS_PYTHON2 HAS_PYPY2=$HAS_PYPY2 HAS_PYTHON3=$HAS_PYTHON3
HAS_PYPY3=$HAS_PYPY3 HAS_SCALA=$HAS_SCALA HAS_ELIXIR=$HAS_ELIXIR HAS_NASM=$HAS_NASM HAS_PERL=$HAS_PERL
HAS_COBOL=$HAS_COBOL HAS_PASCAL=$HAS_PASCAL HAS_CRYSTAL=$HAS_CRYSTAL HAS_FORTRAN=$HAS_FORTRAN
HAS_ERLANG=$HAS_ERLANG HAS_LUA=$HAS_LUA HAS_OCAML=$HAS_OCAML HAS_BF=$HAS_BF"
detect_operating_system
case "$os_like" in
ubuntu | debian | arch | fedora | centos)
if [ "$os_like" = "debian" ]; then
if [ "$os_name" = "ubuntu" ]; then
os_like="ubuntu"
fi
fi
echo "${txtgrn}Installing dependencies for $os_like...${rst}"
"$top_dir/scripts/dependency_install/install_dep_${os_like}.sh" $cli_arg
;;
*)
echo "${txtred}Unsupported operating system.${rst}"
exit 1
;;
esac