-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer
executable file
·232 lines (195 loc) · 6.78 KB
/
installer
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
#!/bin/bash
usage() {
echo -e "\n Usage: installer [-i/u] [VERSION] [TARGET-DIR] [SOURCE-DIR] [STATIC-DIR-NAME] [SLOT1_DIRNAME] [SLOT2_DIRNAME] [SLOT3_DIRNAME] [LOG-FILE]"
}
install_flag=0
uninstall_flag=0
help_flag=0
while getopts "iu" opt; do
case $opt in
i )
install_flag=1
;;
u )
uninstall_flag=1
;;
h )
help_flag=1
;;
\? )
echo "Invalid option: -$OPTARG. Run with -h for help." >&2
exit 1
;;
: )
echo "Option -$OPTARG requires an argument. Run with -h for help." >&2
exit 1
;;
esac
tot_opts=$OPTIND
done
if [[ $install_flag -eq 0 && $uninstall_flag -eq 0 ]] ; then {
usage
echo -e "\n Missing operation, -i or -u."
exit 1
}
fi
#
if [[ $# -ne 9 ]] ; then {
usage
exit 1
}
fi
INSTALLER_VERSION="0.1.2"
VERSION="$2"
TARGET_INSTALL_DIR="$3"
SOURCE_INSTALL_DIR="$4"
STATIC_DIR_NAME="$5"
SLOT1_DIRNAME="$6"
SLOT2_DIRNAME="$7"
SLOT3_DIRNAME="$8"
LOG_FILE="$9"
truncate_log() {
echo "" > $LOG_FILE
}
log_msg() {
echo -e "$1" >> $LOG_FILE
}
echo -e "\n helapordo installer version [$INSTALLER_VERSION]"
echo -e " args: ["$@"]"
echo -e " will install helapordo version [$VERSION] to [$TARGET_INSTALL_DIR]"
# Function for each installation step
verscheck() {
[[ -f $SOURCE_INSTALL_DIR/helapordo ]] || {
log_msg "\n Can't find helapordo in source dir : [$SOURCE_INSTALL_DIR]"
exit 1
}
readVersion=$($SOURCE_INSTALL_DIR/helapordo -v)
[[ $readVersion != $VERSION ]] && {
log_msg "\n Unexpected helapordo version [$readVersion], expected [$VERSION]"
exit 1
}
log_msg "\n helapordo version $readVersion detected in source dir : [$SOURCE_INSTALL_DIR]."
}
depcheck() {
deps=("$SOURCE_INSTALL_DIR/$STATIC_DIR_NAME") #Legacy code for installing animations and lores # "$SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/animations" "$SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/lore")
totalDeps=${#deps[@]} # Total number of deps tasks
currentDepTask=0 # Current dep task being executed
for depstep in "${deps[@]}"; do
[[ -d $depstep ]] || {
log_msg "\n Can't find: ($depstep)"
exit 1
}
if [[ $depstep != "$SOURCE_INSTALL_DIR/static" ]] ; then { #We don't show contents of ./static as they are not all installed
log_msg "\n Will install files inside dir [$depstep] to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$(basename $depstep )].\n"
for FILE_NAME in $(ls $depstep); do {
log_msg " [$FILE_NAME]"
}
done
}
fi
((currentDepTask++)) # Increment current task count
done
log_msg "\n Done checking local files."
}
mkdirs() {
dirs=("$TARGET_INSTALL_DIR" "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME" "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT1_DIRNAME" "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT2_DIRNAME" "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT3_DIRNAME")
#Legacy code for installing animations and lores >>> # "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/animations" "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/lore")
totalDirs=${#dirs[@]} # Total number of dirs to make
currentDirTask=0 # Current dir task being executed
log_msg "\n Creating directories."
for dirstep in "${dirs[@]}"; do
if [[ ! -d $dirstep ]] ; then {
log_msg " Can't find: ($dirstep)"
log_msg " Creating [$dirstep] dir at: [$dirstep]."
mkdir "$dirstep"
if [[ ! $? -eq 0 ]] ; then {
log_msg "\n Failed creating dir [$dirstep]."
exit 1;
}
fi
}
fi
((currentDirTask++)) # Increment current task count
done
touch "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT1_DIRNAME/save.txt"
touch "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT2_DIRNAME/save.txt"
touch "$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/$SLOT3_DIRNAME/save.txt"
log_msg "\n Done Creating directories."
}
installgame() {
install $SOURCE_INSTALL_DIR/helapordo $TARGET_INSTALL_DIR/helapordo
log_msg "\n Installing game to [$TARGET_INSTALL_DIR/helapordo]."
}
installstatics() {
log_msg "\n Installing game statics to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME]."
#
# Legacy code for installing animations to static dir.
#for A in $(ls $SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/animations) ; do {
# log_msg " Installing animation file [$A] to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/animations]."
#
# install $SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/animations/$A $TARGET_INSTALL_DIR/$STATIC_DIR_NAME/animations
# if [[ ! $? -eq 0 ]] ; then {
# log_msg " \nFailed installing animation file [$A] to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/animations]."
# exit 1;
# }
# fi
# }
#done
#
#
# Legacy code for installing lores to static dir.
#for L in $(ls $SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/lore) ; do {
#log_msg " Installing lore file [$L] to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/lore]."
#install $SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/lore/$L $TARGET_INSTALL_DIR/$STATIC_DIR_NAME/lore
#if [[ ! $? -eq 0 ]] ; then {
#log_msg "\n Failed installing lore file [$L] to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME/lore]."
#exit 1;
#}
#fi
#}
#done
#
#
# Legacy code for installing palette.gpl to static dir.
# install $SOURCE_INSTALL_DIR/$STATIC_DIR_NAME/palette.gpl $TARGET_INSTALL_DIR/$STATIC_DIR_NAME/
#if [[ ! $? -eq 0 ]] ; then {
#log_msg "\n Failed installing palette file to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME]."
#exit 1;
#}
#fi
#log_msg "\n Installed palette file to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME]."
#
log_msg "\n Installed game static deps from [$STATIC_DIR_NAME] dir to [$TARGET_INSTALL_DIR/$STATIC_DIR_NAME]."
}
# Array of installation steps
installSteps=("verscheck" "depcheck" "mkdirs" "installstatics" "installgame")
totalTasks=${#installSteps[@]} # Total number of installation tasks
currentTask=0 # Current task being executed
PROGRESS_BAR_WIDTH=40 # Width of the progress bar
# Function to perform the installation tasks
installGame() {
for step in "${installSteps[@]}"; do
"$step" # Execute each installation step
((currentTask++)) # Increment current task count
# Update progress bar
progress=$((currentTask * 100 / totalTasks))
filledWidth=$((progress * PROGRESS_BAR_WIDTH / 100))
emptyWidth=$((PROGRESS_BAR_WIDTH - filledWidth))
printf "\033[1;35m Installing... ["
# Draw filled portion of the progress bar
for ((i = 0; i < filledWidth; ++i)); do
printf "#"
done
# Draw empty portion of the progress bar
for ((i = 0; i < emptyWidth; ++i)); do
printf " "
done
printf "] %d%%\r\e[0m" $progress
sleep 0.2 # Delay to visualize the progress
done
}
truncate_log
printf " Starting installation.\n"
# Install the game
installGame
printf "\n\n Installation complete.\n"