-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup-godot-engine-scriptmodule.sh
executable file
·294 lines (247 loc) · 8.38 KB
/
setup-godot-engine-scriptmodule.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
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
#!/usr/bin/env bash
# setup-godot-engine-scriptmodule.sh
#
# RetroPie Godot Engine "Emulator"
# A scriptmodule to install a Godot "emulator" for RetroPie.
#
# Author: hiulit
# Repository: https://github.com/hiulit/RetroPie-Godot-Engine-Emulator
# License: MIT https://github.com/hiulit/RetroPie-Godot-Engine-Emulator/blob/master/LICENSE
#
# Requirements:
# - RetroPie 4.x.x
# Globals ####################################################################
user="$SUDO_USER"
[[ -z "$user" ]] && user="$(id -un)"
home="$(eval echo ~$user)"
readonly RP_DIR="$home/RetroPie"
readonly RP_ROMS_DIR="$RP_DIR/roms"
readonly RP_EMULATORS_DIR="/opt/retropie/emulators"
readonly SCRIPT_VERSION="1.12.3"
readonly VERSION_MAJOR="$(echo "$SCRIPT_VERSION" | cut -d "." -f 1)"
readonly VERSION_MINOR="$(echo "$SCRIPT_VERSION" | cut -d "." -f 2)"
readonly VERSION_PATCH="$(echo "$SCRIPT_VERSION" | cut -d "." -f 3)"
readonly SCRIPT_DIR="$(cd "$(dirname $0)" && pwd)"
readonly SCRIPT_NAME="$(basename "$0")"
readonly SCRIPT_FULL="$SCRIPT_DIR/$SCRIPT_NAME"
readonly SCRIPT_TITLE="RetroPie Godot Engine \"Emulator\""
readonly SCRIPT_DESCRIPTION="A scriptmodule to install a Godot \"emulator\" for RetroPie."
readonly SCRIPTMODULE_NAME="godot-engine"
readonly SCRIPTMODULE_FILE="scriptmodules/emulators/$SCRIPTMODULE_NAME.sh"
readonly SCRIPTMODULE_SETTINGS_DIR="$RP_ROMS_DIR/$SCRIPTMODULE_NAME/settings"
readonly PACKAGE_TYPE="optional"
readonly SETTINGS_FILES=(
"override.cfg"
"godot-engine-settings.cfg"
)
readonly TMP_SETTINGS_DIR="$home/.tmp/$SCRIPTMODULE_NAME"
# Variables ##################################################################
RPS_DIR="$home/RetroPie-Setup"
# Functions ##################################################################
function is_retropie() {
[[ -d "$RP_DIR" && -d "$home/.emulationstation" && -d "/opt/retropie" ]]
}
function usage() {
echo
echo "USAGE: $0 [OPTIONS]"
echo
echo "Use '$0 --help' to see all the options."
echo
}
function check_path() {
if [[ -n "$1" ]]; then
if [[ -d "$1" ]]; then
RPS_DIR="$1"
else
echo >&2
echo "ERROR: '$1' doesn't exist!" >&2
echo >&2
exit 1
fi
fi
}
function install_update_settings_files() {
# Create a temporary directory to store the "settings" files.
mkdir -p "$TMP_SETTINGS_DIR"
# Copy the "settings" files to the temporaty directory.
# These files will be used by the scriptmodule.
for file in "${SETTINGS_FILES[@]}"; do
cat "$SCRIPT_DIR/$file" > "$TMP_SETTINGS_DIR/$file"
done
}
function install() {
echo
echo "> Installing '$SCRIPTMODULE_NAME' scriptmodule (v$SCRIPT_VERSION)..."
# Install the "godot-engine" scriptmodule.
cat "$SCRIPT_DIR/$SCRIPTMODULE_FILE" > "$RPS_DIR/$SCRIPTMODULE_FILE"
if [[ "$?" -eq 0 ]]; then
install_update_settings_files
echo
echo "'$SCRIPTMODULE_NAME' scriptmodule installed successfully!"
echo
echo "To install the '$SCRIPTMODULE_NAME' emulator, run:"
echo
echo "'sudo $RPS_DIR/retropie_setup.sh'"
echo
echo "Go to:"
echo
echo "|- Manage packages"
echo " |- Manage $PACKAGE_TYPE packages"
echo " |- $SCRIPTMODULE_NAME"
echo " |- Install from source"
echo
echo "Copy your games to '$RP_ROMS_DIR/$SCRIPTMODULE_NAME'."
echo "Game extensions: .pck .zip."
echo
else
echo >&2
echo "ERROR: Couldn't install the '$SCRIPTMODULE_NAME' scriptmodule." >&2
echo >&2
fi
}
function uninstall() {
echo
echo "> Uninstalling '$SCRIPTMODULE_NAME' scriptmodule..."
if [[ ! -f "$RPS_DIR/$SCRIPTMODULE_FILE" ]]; then
echo >&2
echo "ERROR: Can't uninstall the '$SCRIPTMODULE_NAME' scriptmodule because it is not installed!" >&2
echo >&2
exit 1
fi
if [[ -d "$RP_EMULATORS_DIR/$SCRIPTMODULE_NAME" ]]; then
echo >&2
echo "ERROR: '$SCRIPTMODULE_NAME' emulator is still installed." >&2
echo >&2
echo "To uninstall the '$SCRIPTMODULE_NAME' emulator, run:" >&2
echo >&2
echo "'sudo $RPS_DIR/retropie_setup.sh'" >&2
echo >&2
echo "Go to:" >&2
echo >&2
echo "|- Manage packages" >&2
echo " |- Manage $PACKAGE_TYPE packages" >&2
echo " |- $SCRIPTMODULE_NAME" >&2
echo " |- Remove" >&2
echo >&2
exit 1
fi
# Remove the scriptmodule file.
rm "$RPS_DIR/$SCRIPTMODULE_FILE"
# Remove the temporary "settings" files.
[[ -d "$TMP_SETTINGS_DIR" ]] && rm -rf "$TMP_SETTINGS_DIR"
if [[ "$?" -eq 0 ]]; then
echo
echo "'$SCRIPTMODULE_NAME' scriptmodule uninstalled successfully!"
echo
else
echo >&2
echo "ERROR: Couldn't uninstall the '$SCRIPTMODULE_NAME' scriptmodule." >&2
echo >&2
fi
}
function update() {
echo
echo "> Updating '$SCRIPTMODULE_NAME' scriptmodule..."
if [[ ! -f "$RPS_DIR/$SCRIPTMODULE_FILE" ]]; then
echo >&2
echo "ERROR: Can't update the '$SCRIPTMODULE_NAME' scriptmodule because it is not installed!" >&2
echo >&2
echo "Run '$0 --install' to install the '$SCRIPTMODULE_NAME' scriptmodule." >&2
echo >&2
exit 1
fi
# Update the "godot-engine" scriptmodule.
cat "$SCRIPT_DIR/$SCRIPTMODULE_FILE" > "$RPS_DIR/$SCRIPTMODULE_FILE"
if [[ "$?" -eq 0 ]]; then
install_update_settings_files
echo
echo "'$SCRIPTMODULE_NAME' updated to v$SCRIPT_VERSION successfully!"
echo
echo "To update the '$SCRIPTMODULE_NAME' emulator, run:"
echo
echo "'sudo $RPS_DIR/retropie_setup.sh'"
echo
echo "Go to:"
echo
echo "|- Manage packages"
echo " |- Manage $PACKAGE_TYPE packages"
echo " |- $SCRIPTMODULE_NAME"
echo " |- Update (from source)"
echo
else
echo >&2
echo "ERROR: Couldn't update the '$SCRIPTMODULE_NAME' scriptmodule." >&2
echo >&2
fi
}
function get_options() {
if [[ -z "$1" ]]; then
usage
exit 0
else
case "$1" in
#H -h, --help Prints the help message.
-h|--help)
echo
echo "$SCRIPT_TITLE"
for ((i=1; i<="${#SCRIPT_TITLE}"; i+=1)); do [[ -n "$dashes" ]] && dashes+="-" || dashes="-"; done && echo "$dashes"
echo "$SCRIPT_DESCRIPTION"
echo
echo "USAGE: $0 [OPTIONS]"
echo
echo "OPTIONS:"
echo
sed '/^#H /!d; s/^#H //' "$0"
echo
exit 0
;;
#H -v, --version Prints the script version.
-v|--version)
echo "$SCRIPT_VERSION"
;;
#H -i, --install [path] Installs the "godot-engine" scriptmodule.
#H Path: The location of the "RetroPie-Setup" folder.
#H Default: "~/RetroPie-Setup".
-i|--install)
check_path "$2"
install
;;
#H -u, --uninstall [path] Uninstalls the "godot-engine" scriptmodule.
#H Path: The location of the "RetroPie-Setup" folder.
#H Default: "~/RetroPie-Setup".
-u|--uninstall)
check_path "$2"
uninstall
;;
#H -U, --update [path] Updates the "godot-engine" scriptmodule.
#H Path: The location of the "RetroPie-Setup" folder.
#H Default: "~/RetroPie-Setup".
-U|--update)
check_path "$2"
update
;;
*)
echo >&2
echo "ERROR: Invalid option '$1'." >&2
exit 2
;;
esac
fi
}
function main() {
if ! is_retropie; then
echo >&2
echo "ERROR: RetroPie is not installed. Aborting..." >&2
exit 1
fi
if [[ ! -d "$RPS_DIR" ]]; then
echo >&2
echo "ERROR: '$RPS_DIR' doesn't exist." >&2
echo >&2
echo "Please, input the location of the 'RetroPie-Setup' folder." >&2
echo "Example: $0 [OPTION] \"$home/RetroPie-Setup\"" >&2
exit 1
fi
get_options "$@"
}
main "$@"