-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
run.sh
111 lines (93 loc) · 2.08 KB
/
run.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
#!/usr/bin/env bash
# Import all the util files
source src/util/args.sh
source src/util/helpers.sh
source src/util/menu.sh
source src/util/print_utils.sh
# Import commands
source src/commands/download.sh
source src/commands/compile.sh
source src/commands/extract.sh
# Run the command specified by the choice made on the menu
run_command() {
case $1 in
[0])
download spigot_versions
;;
[1])
extract spigot_versions extracted_files
;;
[2])
compile extracted_files;;
esac
if [ $? -ne 0 ]; then
echo 🔴 Something went wrong while performing the selected action!
fi
# Delete all output and re-render the menu
if [ $2 == 1 ] && [ $is_interactive == 1 ]; then
choice=89
moveCursorUp
delete_lines 21
moveCursorDown
execute
fi
}
execute() {
if [ $display_title = 1 ]; then
print_title
fi
check_os
echo
flag=false
# If no flag added to the command, create an interactive menu
if [[ "$choice" == 89 ]]; then
echo "What do would you like to do today? (Use arrow keys to move, and Enter to select)"
echo
# Set mode as interactive
is_interactive=1
# Options to display on menu
local options=(
"Download"
"Extract"
"Compile"
"All the above"
"Exit"
)
select_option "${options[@]}"
choice=$?
delete_lines 9
else
flag=true
fi
if [ $choice = 3 ]; then
echo Performing all actions...
# Run through all commands if the choice is "All the above"
for i in {0..2}; do
run_command $i 0
if [ $? -ne 0 ]; then
break
fi
done
elif [ $choice = 4 ]; then
# Exit the program
delete_lines 20
unset ASNMSCMD
echo Bye Bye...
exit 0
elif [ $choice = 77 ]; then
# Run tests
source src/test.sh
else
# Run the correct command according to the choice
run_command $choice 1
fi
unset ASNMSCMD
RETURN_CODE=$?
if [ $RETURN_CODE -ne 0 ]; then
echo "🔴 Something went wrong while executing: '${options[$choice]}'"
exit $RETURN_CODE
fi
}
mkdir -p spigot_versions
mkdir -p extracted_files
execute