forked from RetroPie/RetroPie-Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackages.sh
More file actions
290 lines (261 loc) · 9.19 KB
/
packages.sh
File metadata and controls
290 lines (261 loc) · 9.19 KB
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
#!/usr/bin/env bash
# This file is part of The RetroPie Project
#
# The RetroPie Project is the legal property of its developers, whose names are
# too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
#
# See the LICENSE.md file at the top-level directory of this distribution and
# at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
#
__mod_idx=()
__mod_id=()
__mod_type=()
__mod_desc=()
__mod_menus=()
__mod_flags=()
# params: $1=index, $2=id, $3=type, $4=description, $5=menus, $6=flags
function rp_registerFunction() {
__mod_idx+=($1)
__mod_id[$1]=$2
__mod_type[$1]=$3
__mod_desc[$1]=$4
__mod_menus[$1]=$5
__mod_flags[$1]=$6
}
function rp_listFunctions() {
local idx
local mod_id
local desc
local mode
local func
echo -e "Index/ID: Description: List of available actions"
echo "-----------------------------------------------------------------------------------------------------------------------------------"
for idx in ${__mod_idx[@]}; do
mod_id=${__mod_id[$idx]};
printf "%d/%-20s: %-42s :" "$idx" "$mod_id" "${__mod_desc[$idx]}"
while read mode; do
mode=${mode//_$mod_id/}
echo -n " $mode"
# if not experimental and has no nobin flag, we have an install_bin call also
if [[ "$mode" == "install" ]] && ! hasFlag "${__mod_flags[$idx]}" "nobin" && ! [[ "${__mod_menus[$idx]}" =~ "4+" ]]; then
echo -n " install_bin"
fi
done < <(compgen -A function -X \!*_$mod_id)
echo ""
done
echo "==================================================================================================================================="
}
function rp_printUsageinfo() {
echo -e "Usage:\n$0 <Index # or ID>\nThis will run the actions depends, sources, build, install, configure and clean automatically.\n"
echo -e "Alternatively, $0 can be called as\n$0 <Index # or ID [depends|sources|build|install|configure|clean|remove]\n"
echo "Definitions:"
echo "depends: install the dependencies for the module"
echo "sources: install the sources for the module"
echo "build: build/compile the module"
echo "install: install the compiled module"
echo "configure: configure the installed module (es_systems.cfg / launch parameters etc)"
echo "clean: remove the sources/build folder for the module"
echo -e "\nThis is a list of valid modules/packages and supported commands:\n"
rp_listFunctions
}
function rp_callModule() {
local req_id="$1"
local mode="$2"
# shift the function parameters left so $@ will contain any additional parameters which we can use in modules
shift 2
if [[ -z "$mode" ]]; then
for mode in depends sources build install configure clean; do
rp_callModule $req_id $mode || return 1
done
return 0
fi
# if index get mod_id from array else try and find it (we should probably use bash associative arrays for efficiency)
local mod_id
local idx
if [[ "$req_id" =~ ^[0-9]+$ ]]; then
mod_id=${__mod_id[$req_id]}
idx=$req_id
else
for idx in "${!__mod_id[@]}"; do
if [[ "$req_id" == "${__mod_id[$idx]}" ]]; then
mod_id="$req_id"
break
fi
done
fi
if [[ -z "$mod_id" ]]; then
fatalError "No module '$req_id' found for platform $__platform"
fi
# create variables that can be used in modules
local md_id="$mod_id"
local md_desc="${__mod_desc[$idx]}"
local md_type="${__mod_type[$idx]}"
local md_flags="${__mod_flags[$idx]}"
local md_build="$__builddir/$mod_id"
local md_inst="$rootdir/$md_type/$mod_id"
# remove source/build files
if [[ "${mode}" == "clean" ]]; then
rmDirExists "$md_build"
return 0
fi
# create function name
function="${mode}_${mod_id}"
if [[ "${mode}" == "install_bin" ]] && [[ ! "$md_flags" =~ nobin ]]; then
rp_installBin
return
fi
if [[ "${mode}" == "create_bin" ]] && [[ ! "$md_flags" =~ nobin ]]; then
rp_createBin
return
fi
# return if function doesn't exist
fnExists $function || return 0
# these can be returned by a module
local md_ret_require=""
local md_ret_files=""
local action
case "$mode" in
depends)
action="Installing dependencies for"
;;
sources)
action="Getting sources for"
rmDirExists "$md_build"
mkdir -p "$md_build"
pushd "$md_build"
;;
build)
action="Building"
pushd "$md_build" 2>/dev/null
;;
install|install_bin)
action="Installing"
mkdir -p "$md_inst"
pushd "$md_build" 2>/dev/null
;;
configure)
action="Configuring"
pushd "$md_inst" 2>/dev/null
;;
remove)
action="Removing"
;;
*)
action="Running action '$mode' for"
;;
esac
local pushed=$?
local md_ret_errors=()
# print an action and a description
[[ -n "$action" ]] && printHeading "$action '$md_id' : $md_desc"
# call the function with parameters
$function "$@"
local file
# some errors were returned. append to global errors and return
if [[ "${#md_ret_errors}" -eq 0 ]]; then
# check if any required files are found
if [[ -n "$md_ret_require" ]]; then
for file in "${md_ret_require[@]}"; do
if [[ ! -e "$file" ]]; then
md_ret_errors+=("Could not successfully $mode $md_desc ($file not found).")
break
fi
done
else
# check for existance and copy any files/directories returned
if [[ -n "$md_ret_files" ]]; then
for file in "${md_ret_files[@]}"; do
if [[ ! -e "$md_build/$file" ]]; then
md_ret_errors+=("Could not successfully install $md_desc ($md_build/$file not found).")
break
fi
cp -Rv "$md_build/$file" "$md_inst"
done
fi
fi
fi
# remove build/install folder if empty
[[ -d "$md_build" ]] && find "$md_build" -maxdepth 0 -empty -exec rmdir {} \;
[[ -d "$md_inst" ]] && find "$md_inst" -maxdepth 0 -empty -exec rmdir {} \;
case "$mode" in
sources|build|install|configure)
[[ $pushed -ne 1 ]] && popd
;;
esac
if [[ "${#md_ret_errors[@]}" -gt 0 ]]; then
printMsgs "console" "${md_ret_errors[@]}" >&2
__ERRMSGS+=("${md_ret_errors[@]}")
return 1
fi
return 0
}
function rp_installBin() {
printHeading "Installing binary archive for $md_desc"
[[ "$__has_binaries" -eq 0 ]] && fatalError "There are no binary archives for platform $__platform"
local archive="$md_type/$md_id.tar.gz";
local dest="$rootdir/$md_type"
mkdir -p "$dest"
wget -O- -q "$__binary_url/$archive" | tar -xvz -C "$dest"
if fnExists $function; then
$function
fi
}
function rp_createBin() {
printHeading "Creating binary archive for $md_desc"
if [[ -d "$rootdir/$md_type/$md_id" ]]; then
local archive="$md_id.tar.gz"
local dest="$__tmpdir/archives/$__raspbian_name/$__platform/$md_type"
rm -f "$dest/$archive"
mkdir -p "$dest"
tar cvzf "$dest/$archive" -C "$rootdir/$md_type" "$md_id"
chown $user:$user "$dest/$archive"
else
printMsgs "console" "No install directory $rootdir/$md_type/$md_id - no archive created"
fi
}
function rp_registerModule() {
local module_idx="$1"
local module_path="$2"
local module_type="$3"
local rp_module_id=""
local rp_module_desc=""
local rp_module_menus=""
local rp_module_flags=""
local var
local error=0
source $module_path
for var in rp_module_id rp_module_desc; do
if [[ -z "${!var}" ]]; then
echo "Module $module_path is missing valid $var"
error=1
fi
done
[[ $error -eq 1 ]] && exit 1
local flag
local valid=1
rp_module_flags=($rp_module_flags)
for flag in "${rp_module_flags[@]}"; do
if [[ "$flag" =~ ^\!(.+) ]] && isPlatform "${BASH_REMATCH[1]}"; then
valid=0
break
fi
done
if [[ "$valid" -eq 1 ]]; then
rp_registerFunction "$module_idx" "$rp_module_id" "$module_type" "$rp_module_desc" "$rp_module_menus" "${rp_module_flags[*]}"
fi
}
function rp_registerModuleDir() {
local module_idx="$1"
local module_dir="$2"
for module in $(find "$scriptdir/scriptmodules/$2" -maxdepth 1 -name "*.sh" | sort); do
rp_registerModule $module_idx "$module" "$module_dir"
((module_idx++))
done
}
function rp_registerAllModules() {
rp_registerModuleDir 100 "emulators"
rp_registerModuleDir 200 "libretrocores"
rp_registerModuleDir 250 "ports"
rp_registerModuleDir 300 "supplementary"
rp_registerModuleDir 900 "admin"
}