This repository has been archived by the owner on May 10, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package
executable file
·628 lines (584 loc) · 23.6 KB
/
package
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
#!/bin/bash
#
# build.sh
#
# Copyright (C) 2021 SpacingBat3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# GOTO: Variables:
GIT_REPO="https://github.com/ptitSeb/box86.git"
HERE="$(dirname "`which "$0"`")"
ME="$(basename "$0" .sh)"
OLD_WORKDIR="$PWD"
ID="${UID}:$(id -g ${USER})"
PLATFORM_LIST=('Raspberry Pi (2/3/4)' 'RK3399' 'ODROID' 'Gameshell' 'Pandora' 'Pyra')
BUILD_METHOD_ARR=("chroot enviroment" "toolchain" "new chroot enviroment")
LIB_MODE_ARR=('Copy all files.' 'Copy ".so" libraries.'
'Copy only necessary libraries.')
PACMAN_BOX86_LIBS=('glibc' 'gcc-libs')
SCRIPT_NAME="`basename "$(git -C "${HERE}" remote -v | head -n1 | awk '{print $2}')" .git`-`basename $0 .sh`"
LOGFILE="${HERE}/build.log"
[[ "$(date +%Y)" == "2021" ]] && CP_YEAR="2021" || CP_YEAR="2021-$(date %Y)"
err_count=0
# GOTO: External scripts
hash -p "${HERE}/tools/gen-appimage.sh" gen-appimage
# Functions for easier text formatting:
help_tl(){
echo -e "\n\e[1;4m${@}\e[0m"
}
help_dc(){
printf '%-36.36s\e[2m%-.38s\e[0m\n' "`printf "$1"`" "`printf "${@:2}"`"
}
help_nx(){
printf '\e[2m%-36.36s%s\e[0m\n' ' ' "${@}"
}
help_dc2(){
printf "%-55.55s\e[2m%s\e[0m\n" "$(printf "\033[1;94m->\033[0m \033[1m${1}=\033[0m${2}")" "${3}"
}
# Functions:
get_ver(){
printf "r%s.%s" "$(git -C "${HERE}" rev-list --count HEAD)" "$(git -C "${HERE}" rev-parse --short HEAD)"
}
version(){
echo -e "\n${SCRIPT_NAME}, version $(get_ver)"
echo -e "\nCopyright (C) ${CP_YEAR} SpacingBat3\n"
echo "This program comes with ABSOLUTELY NO WARRANTY."
echo "This is free software, and you are welcome to redistribute it"
echo -e "under certain conditions.\n"
}
chroot(){
sudo -p "[chroot] Enter your password: " "${HERE}/tools/chroot.sh" \
"${CHROOT_DIR}" "${HERE}/tmp/src" "${UID}" "${USER}" "$@"
}
help(){
get_device_info
x="$((${#LIB_MODE_ARR[@]}-1))"
y="$((${#BUILD_METHOD_ARR[@]}-1))"
usage
help_tl "VARIABLES:"
help_dc2 "ARCH" "[aarch64/armv7(l/h)]" "BOX86 target CPU architecture"
help_nx "(default: host arch == `uname -m`)"
help_dc2 "BUILD_METHOD" "[0-${y}]" "A method to use for the box86"
help_nx "compilation on the AArch64 hosts."
help_dc2 "BUILD_PLATFORM" "[PLATFORM]" "Overwrites PLATFORM to optimize the build"
help_nx "for (default: host == \"${platform_full}\")."
help_dc2 "CHROOT_DIR" "[PATH]" "Sets the ARMHF chroot path which will"
help_nx "be used to compile box86 on AARCH64"
help_nx "host."
help_dc2 "CP_LIB" "[0-${x}]" "Sets the mode of filtering libraries."
help_dc2 "OUT" "[DIRECTORY]" "A path to the directory, inside which"
help_nx "the AppImage will be saved."
help_dc2 "RESET" "[STEP]" "Restart the build from this STEP."
help_dc2 "VER" "[TAG/BRANCH]" "Tag or branch of the box86 repo"
help_nx "which will be used to download the other"
help_nx "version of the BOX86 (than master)."
echo -e "\nYou can also prefix the variable name with the \"BOX86_APPIMAGE_\" if you want"
echo "to save it as an enviromental variable and you are aware the regular variable"
echo "names will be in conflict with variables used by the other software."
help_tl "PLATFORMS:"
printf -v PLATFORM_ALL '%s, ' "${PLATFORM_LIST[@]}"
echo -e " \e[1;92m✓\e[0m ${PLATFORM_ALL%, }"
echo
x=0
y=0
help_tl "AARCH64 BUILD METHODS:"
until [[ "$y" -gt "$[${#BUILD_METHOD_ARR[@]}-1]" ]]; do
printf " \e[1m%s\e[0m == %s\n" "$y" "${BUILD_METHOD_ARR[$y]}"
let y++
done
help_tl "LIBRARY FILTERS:"
until [[ "$x" -gt "$[${#LIB_MODE_ARR[@]}-1]" ]]; do
printf " \e[1m%s\e[0m == %s\n" "$x" "${LIB_MODE_ARR[$x]}"
let x++
done
let x-- y--
echo -e "\nThese values also indidicates the disk space usage by the libraries inside"
echo "the AppImage – where 0 indicates the highest disk space usage and ${x} – the"
echo "lowest."
echo -e "\nPlease note that this variable shouldn't be set to the highest value unless"
echo "you want to provide the libraries by yourself outside the AppImage (which"
echo "generally takes more disk space because AppImages are compressed) or you"
echo "would like to use the Appimage as a dependency to package X86 binary on"
echo "AArch64 distributables."
echo
}
usage(){
echo -e "\n\e[1mUSAGE\e[0m: `basename $0` [ARGUMENT] [FOO=BAR]..."
help_tl "ARGUMENTS:"
help_dc " -h --help" "Display entire help message."
help_dc " -u --usage" "Display script usage."
help_dc " -c --clear" "Clear build files to free some disk"
help_nx "space."
}
error(){
error_msg "$@"
if [[ "$1" != 130 ]]; then
read -n1 -srp "$(printf '\e[1mPress any key to continue.\e[0m')"
echo
fi
clear; tput rmcup
trap - EXIT
error_msg "$@"
stty echo >/dev/null 2>&1
exit "$1"
}
error_msg(){
printf "\n\e[1;91mERROR:\e[0m "
case "$1" in
1) echo "Build method: \"${build_method}\" not implemented yet!" ;;
2) echo "GIT was not installed!" ;;
3) echo "Unsupported linux distrinution!" ;;
4) echo "Unsupported Raspberry Pi device!" ;;
5) echo "Missing dependency: ${depends}!" ;;
6) echo "Source file/directory not found!" ;;
7) echo "Couldn't get all sources!" ;;
8) echo "Unsupported architecture ${ARCH}!" ;;
9) echo "An error occured while ${2}!" ;;
10) echo "Unimplemented selection!" ;;
11) echo "Couldn't make the chroot enviroment!" ;;
12) echo "Directory \"${2}\" already exists!" ;;
13) echo "Missing chroot dependency: ${depends}!" ;;
130) echo "Received INT signal!" ;;
*)
echo "Unknown error!"
echo "Exit code ${1}!"
;;
esac
# Some additional info about the issue (in some cases):
case "$1" in
5)
if pacman -F "/usr/bin/${depends}" >/dev/null 2>&1; then
readarray satisfy_list < <(pacman --color always -F "/usr/bin/${depends}")
for each in "${satisfy_list[@]}"; do
printf "\e[1;94mINFO:\e[0m ${each}"
done
unset each
fi
;;
esac
printf "\n"
}
warn(){
printf "\n\e[1;93mWARN:\e[0m "
echo -e "$@" "\n"
}
workdirs(){
case "${argv[@]}" in
-*c*|"--clear")
cleanup_all
;;&
*)
printf "\nPreparing the script's work directory..."
[[ ! -d "${HERE}/tmp/src" ]] && mkdir "${HERE}/tmp/src"
[[ -f "${HERE}/tmp/src/box86/build/CMakeCache.txt" ]] && rm -f "${HERE}/tmp/src/box86/build/CMakeCache.txt"
[[ -d "${HERE}/tmp/final.AppDir" ]] && rm -Rf "${HERE}/tmp/final.AppDir" >/dev/null 2>&1
echo " Done!"
;;
esac
}
cleanup() {
printf "\nRemoving unnecessary \"*.AppDir\" folders..."
[[ -d "${HERE}/tmp/final.AppDir" ]] && rm -Rf "${HERE}/tmp/final.AppDir" >/dev/null 2>&1
[[ -d "${HERE}/tmp/box86.AppDir" ]] && rm -Rf "${HERE}/tmp/box86.AppDir" >/dev/null 2>&1
echo " Done!"
}
cleanup_all(){
printf "\nRemoving build files..."
readarray -t temp_dirs <"${HERE}/.gitignore"
for dir in "${temp_dirs[@]}"; do
[[ -d "$dir" ]] && rm -Rf "${HERE}/${dir}"
done
echo " Done!"
}
is_update(){
GIT_LOCAL="${1:-${HERE}/tmp/src/box86}"
if [[ "`git -C "${GIT_LOCAL}" branch`" =~ 'master' ]]; then
git -C "$GIT_LOCAL" fetch >/dev/null 2>&1
upstream='@{u}'
local="$(git -C "${GIT_LOCAL}" rev-parse @)"
remote="$(git -C "${GIT_LOCAL}" rev-parse "$upstream")"
if [ "$local" = "$remote" ]; then
return 1
else
return 0
fi
unset upstream local remote
else
return 0
fi
unset GIT_LOCAL
}
get_sources(){
if [[ -z "$VER" ]]; then
echo -e "\nWhich version of the BOX86 would you like to use?"
read -ep "`printf "\e[1mEnter git tag or branch:\e[0m (default: master) "`" VER
fi
[[ ! -z "$VER" ]] && GIT_FLAGS="--branch $VER"
stty -echo >/dev/null 2>&1
rmdir "${HERE}/tmp/src/box86" >/dev/null 2>&1
if [[ -d "${HERE}/tmp/src/box86" ]]; then
if is_update || [[ ! -z "${VER}" && "${VER}" != "master" ]]; then
printf "\nUpdating GIT Repository..."
rm -Rf "${HERE}/tmp/src/box86"
git clone ${GIT_FLAGS} --depth 1 "${GIT_REPO}" "${HERE}/tmp/src/box86" >/dev/null 2>&1
error="$?"; [[ "$error" == 0 ]] && echo -e " Done!\n" || error 7
fi
else
printf "\nCloning the box86 GIT repository..."
mkdir "${HERE}/tmp/src/box86"
git clone ${GIT_FLAGS} --depth 1 "${GIT_REPO}" "${HERE}/tmp/src/box86" >/dev/null 2>&1
error="$?"; [[ "$error" == 0 ]] && echo -e " Done!\n" || error 7
fi
[[ -d "${HERE}/base.AppDir" ]] || error 6
stty echo >/dev/null 2>&1
}
get_device_info(){
case "${BUILD_PLATFORM:-$(cat /proc/cpuinfo)}" in
# Raspberry Pi SBCs
*"Raspberry Pi"*)
pi_model="${BUILD_PLATFORM:-$(tr -d '\0' </proc/device-tree/model)}"
case "$pi_model" in
*"Raspberry Pi 4"*) pi_ver=4 ;;
*"Raspberry Pi 3"*) pi_ver=3 ;;
*"Raspberry Pi 2"*) pi_ver=2 ;;
*) error 4 # RPi 1/0 are not supported, cancel building.
esac
platform="rpi${pi_ver}" # used for artifact name
platform_full="Raspberry Pi ${pi_ver}"
cmake_flags=("-DRPI${pi_ver}=1")
;;
# Other ARM Boards
*"RK3399"*) platform='rk3399'; cmake_flags=('-DRK3399=1'); platform_full="RK3399" ;;
*"ODROID"*) platform='odroid'; cmake_flags=('-DODROID=1'); platform_full="ODROID" ;;
*"Gameshell"*) platform='gameshell'; cmake_flags=('-DGAMESHELL=1') ;;
*"Pandora"*) platform='pandora'; cmake_flags=('-DPANDORA=1') ;;
*"Pyra"*) platform='pyra'; cmake_flags=('-DPYRA=1') ;;
*) platform='arm'; cmake_flags=('-DARM_DYNAREC=ON') ;;
esac
[[ -z platform_full ]] && platform_full="${platform^}"
}
build_32(){
# TODO: Build script for 32-bit OS.
echo
}
make_chroot(){
check_dependencies mkarchroot pacman
[[ -d "${HERE}/tmp/src/chroot" ]] && error 12 "tmp/src/chroot"
echo "Please enter additional packages to install to the chroot enviroment."
echo "You can leave this field empty if you want to use the defaults only."
read -p "Pacman package list: (base-devel cmake python) " CHROOT_PACKAGES
stty -echo >/dev/null 2>&1
mkarchroot -sC "${HERE}/tools/pacman.conf" "${HERE}/tmp/src/chroot" base-devel cmake python ${CHROOT_PACKAGES} \
|| (stty echo >/dev/null 2>&1; sudo env HERE="${HERE}" PKG="CHROOT_PACKAGES" \
bash -c 'stty -echo >/dev/null 2>&1; pacman -Syr "${HERE}/tmp/src/chroot" \
--config "${HERE}/tools/pacman.conf" base-devel cmake python ${PKG}') \
|| error 11
[[ -d "${HERE}/tmp/src/chroot" ]] && CHROOT_DIR="${HERE}/tmp/src/chroot"
}
build_chroot(){
[[ -z "${CHROOT_DIR}" && -f "${HERE}/tmp/src/chroot/lib/ld-linux-armhf.so.3" ]] && \
CHROOT_DIR="${HERE}/tmp/src/chroot/" && \
echo "Found ARMHF chroot: \"${CHROOT_DIR}\"!"
if [[ -z "$CHROOT_DIR" ]]; then
until [[ ! -z "$LOOP_END" && "$LOOP_END" != 0 ]]; do
read -ep 'Enter the "armv7h" chroot path: ' CHROOT_DIR
if [[ ! -d "$CHROOT_DIR" ]]; then
echo "$CHROOT_DIR isn't a directory!"
echo "Please type the correct path to the directory."
elif [[ ! -f "${CHROOT_DIR}/lib/ld-linux-armhf.so.3" ]]; then
echo "$CHROOT_DIR has no ARMHF linker!"
else
LOOP_END=1
fi
done
fi
unset LOOP_END
LD_LIBRARY_PATH="${CHROOT_DIR}/lib:${LD_LIBRARY_PATH}"
BIN32="${CHROOT_DIR}/usr/bin"
INT32="${CHROOT_DIR}/lib/ld-linux-armhf.so.3"
check_dependencies --chroot make cmake gcc g++
chroot env flags="${cmake_flags[@]}" /usr/bin/bash -c \
'stty -echo >/dev/null 2>&1; cd /mnt/box86; \
mkdir build >/dev/null 2>&1; cd build; \
cmake .. ${flags} -DCMAKE_BUILD_TYPE=RelWithDebInfo; \
make -j$(nproc); stty echo >/dev/null 2>&1'
PACKAGE_MODE=0
}
build_toolchain(){
echo "Does not work :("
# TODO: Toolchain build method.
}
check_dependencies(){
if [[ "$1" == "--chroot" ]]; then
for depends in "${@:2}"; do
[[ -f "${BIN32}/${depends}" ]] || error 13
done
else
for depends in "${@}"; do
which "$depends" >> /dev/null 2>&1 || error 5
done
fi
}
install_box86(){
case "$PACKAGE_MODE" in
0)
pkgdir="${HERE}/tmp/final.AppDir/usr"
install -Dm755 "${HERE}/tmp/src/box86/build/box86" "${pkgdir}/bin/box86"
[[ ! -d "${pkgdir}/lib/i386-linux-gnu" ]] && mkdir -p "${pkgdir}/lib/i386-linux-gnu"
cp -Rdt "${pkgdir}/lib/i386-linux-gnu" "${HERE}/tmp/src/box86/x86lib/"*
chmod 755 "${pkgdir}/lib/i386-linux-gnu"
chmod -R 644 "${pkgdir}/lib/i386-linux-gnu/"*
install -Dm644 "${HERE}/tmp/src/box86/docs/LICENSE" "${pkgdir}/share/licenses/box86/LICENSE"
;;
esac
}
guess_pm(){
#FIXME: Debian CHROOT support (and probably others too):
if [[ -f /etc/pacman.conf && -f "${CHROOT_DIR}/etc/pacman.conf" ]]; then
pm_files(){
pacman -Qlr "$CHROOT_DIR" "$@" 2>/dev/null | awk '{print $2}'
}
pm_licenses(){
pacman -Qlr "$CHROOT_DIR" "$@" 2>/dev/null | grep -o '.*/usr/share/licenses/.*/' | sort | uniq | awk '{print $2}'
}
pm_search(){
pacman -Qlr "$CHROOT_DIR" 2>/dev/null | grep "$1" | awk '{print $1}' | sort | uniq
}
elif [[ -f "${CHROOT_DIR}/etc/pacman.conf" ]]; then
pm_files(){
chroot env LIBS="$@" /usr/bin/bash -c 'pacman -Ql $LIBS | awk {print\ \$2}'
}
pm_licenses(){
chroot env PKGS="${@}" /usr/bin/bash -c 'pacman -Ql $PKGS | grep -o ".*/usr/share/licenses/.*/" | sort | uniq | awk {print\ \$2}'
}
pm_search(){
chroot env FILE="$1" /usr/bin/bash -c 'pacman -Ql | grep -o "$FILE" | awk {print\ \$1} | sort | uniq'
}
else
[[ "$1" == "--strict" ]] && error 3 || warn "Unknown package manager of your host/chroot distribution."
returnvalue=3
fi
return $returnvalue
}
fix_links(){
echo -e "\nFixing symlinks:"
readarray -d '' FILES < <(find "${1}/usr/lib/"*.so* -type l -print0)
for file in "${FILES[@]}"; do
real="`ls -l "$file" | grep -o " /usr/lib.*" | grep -o "/usr/lib.*"`"
if [[ ! -z "$real" ]]; then
echo " -> `basename "$file"`"
fi
done
echo -e "Done!\n"
}
install_libs(){
case "$PACKAGE_MODE" in
0)
if [[ "$CP_LIB_MODE" -ge 0 ]] && [[ "$CP_LIB_MODE" -lt "${#LIB_MODE_ARR[@]}" ]] && [ "$CP_LIB_MODE" -eq "$CP_LIB_MODE" ] 2>/dev/null ; then
lib_mode="${LIB_MODE_ARR[$CP_LIB_MODE]}"
else
echo -e "\n\e[1mSelect the method on which libraries are copied:\e[0m "
select lib_mode in "${LIB_MODE_ARR[@]}"; do
[[ ! -z $lib_mode ]] && break
done
fi
stty -echo >/dev/null 2>&1
printf "\nCopying the \`/lib\` content from the current chroot..."
[[ ! -d "${HERE}/tmp/final.AppDir/usr/lib/" ]] && mkdir -p "${HERE}/tmp/final.AppDir/usr/lib/"
case "$lib_mode" in
*'all'*)
cp -dt "${HERE}/tmp/final.AppDir/usr/lib/" "${CHROOT_DIR}/usr/lib/"* >/dev/null 2>&1
error="$?"
;;
*'.so'*)
cd "${CHROOT_DIR}/usr/lib/"
readarray -d '' LIB_FILES < <(find * ! -type d -name '*.so' -print0 -o ! -type d -name '*.so.*' -print0)
for file in "${LIB_FILES[@]}"; do
cp --parents -dt "${HERE}/tmp/final.AppDir/usr/lib/" "${file}"
done
error="$?"
cd "${OLD_WORKDIR}"
;;
*'necessary'*)
guess_pm --strict;
#FIXME: Guess debian dependencies:
readarray LIB_FILES < <(pm_files "${PACMAN_BOX86_LIBS[@]}" | grep 'usr/lib' | sed 's~.*/usr/lib/~~g')
cd "${CHROOT_DIR}/usr/lib/"
for file in "${LIB_FILES[@]}"; do
file="$(tr -d '\n' <<<"${file}")"
if [[ -f "$file" ]] && [[ "$file" == *'.so' || "$file" == *'.so.'* ]]; then
cp --parents -dt "${HERE}/tmp/final.AppDir/usr/lib/" "${file}"
fi
done
error="$?"
cd "${OLD_WORKDIR}"
;;
*) error 10 ;;
esac
stty echo >/dev/null 2>&1
[[ "$error" == 0 ]] && echo -e " Done!" || error 9 "copying libraries from the current chroot"
fix_links "${HERE}/tmp/final.AppDir"
find "${HERE}/tmp/final.AppDir/usr/lib/" -xtype l -delete
;;
1)
#TODO: Install libs while building box86 with the toolchain.
echo "TODO!"
;;
esac
}
copy_licenses(){
case "$PACKAGE_MODE" in
0)
stty -echo
[[ ! -d "${HERE}/tmp/final.AppDir/usr/share/licenses/" ]] && mkdir -p "${HERE}/tmp/final.AppDir/usr/share/licenses/"
case "$lib_mode" in
*'all'*)
guess_pm
if [[ "$?" == 0 ]]; then
printf "Copying the licenses..."
LICENSE_PACK="$(pm_search 'lib/')"
readarray LICENSE_FILES < <(pm_licenses ${LICENSE_PACK})
for dir in "${LICENSE_FILES[@]}"; do
dir_final="$(tr -d '\n' <<<"$dir")"
cp -Rdt "${HERE}/tmp/final.AppDir/usr/share/licenses/" "$dir_final"
unset dir_final
done
echo -e " Done!\n"
else
warn "Skipped copying the licenses, AppImage will be for personal use only."
fi
;;
*'.so'*)
guess_pm
if [[ "$?" == 0 ]]; then
printf "Copying the licenses..."
LICENSE_PACK="$(printf "`pm_search 'lib/.*\.so\..*'`; pm_search 'lib/.*\.so$'" | sort | uniq | tr '\n' ' ')"
readarray LICENSE_FILES < <(pm_licenses ${LICENSE_PACK})
for dir in "${LICENSE_FILES[@]}"; do
dir_final="$(tr -d '\n' <<<"$dir")"
cp -Rdt "${HERE}/tmp/final.AppDir/usr/share/licenses/" "$dir_final"
unset dir_final
done
echo -e " Done!\n"
else
warn "Skipped copying the licenses, AppImage will be for personal use only."
fi
;;
*'necessary'*)
readarray LICENSE_FILES < <(pm_licenses "${PACMAN_BOX86_LIBS[@]}")
printf "Copying the licenses..."
for dir in "${LICENSE_FILES[@]}"; do
dir_final="$(tr -d '\n' <<<"$dir")"
cp -Rdt "${HERE}/tmp/final.AppDir/usr/share/licenses/" "$dir_final"
unset dir_final
done
echo -e " Done!\n"
;;
esac
stty echo
;;
1)
#TODO: Copy license information about the libraries.
echo "TODO!"
;;
esac
}
package_appdir(){
if [[ -d "${HERE}/tmp/final.AppDir" ]]; then
cp -Rdt "${HERE}/tmp/final.AppDir" "${HERE}/base.AppDir/"*
[[ -d "${HERE}/tmp/box86.AppDir" ]] && rm -Rf "${HERE}/tmp/box86.AppDir"
mv "${HERE}/tmp/final.AppDir" "${HERE}/tmp/box86.AppDir"
fi
}
package_appimage(){
ARCH="$ARCH" gen-appimage "${HERE}/tmp/box86.AppDir" "${OUT}/box86-${ARCH}-${platform}.AppImage"
}
# GOTO: Parse arguments.
argv=()
for var in "${@}"; do
case "$var" in
-*h*|--"help") unset ARCH BUILD_PLATFORM; help; exit 0 ;;
-*u*|"--usage") usage; echo; exit 0 ;;
-*v*|"--version") version; exit 0 ;;
*?*"="*) declare "$var" ;;
*) argv+=("$var") ;;
esac
done
unset var
ARCH="${ARCH:-${BOX86_APPIMAGE_ARCH:-$(uname -m)}}"
BUILD_PLATFORM="${BUILD_PLATFORM:-${BOX86_APPIMAGE_BUILD_PLATFORM}}"
CHROOT_DIR="${CHROOT_DIR:-${BOX86_APPIMAGE_CHROOT_DIR}}"
CP_LIB_MODE="${CP_LIB:-${BOX86_APPIMAGE_CP_LIB}}" # nah, I'm just too lazy to change the variable name in code.
RESET="${RESET:-${BOX86_APPIMAGE_RESET}}"
VER="${VER:-${BOX86_APPIMAGE_VER}}"
OUT="${OUT:-${BOX86_APPIMAGE_OUT}}"
BUILD_METHOD="${BUILD_METHOD:-${BOX86_APPIMAGE_BUILD_METHOD}}"
# GOTO: Main part of the script
tput smcup; clear
get_device_info
trap 'sleep 3s; clear; tput rmcup' EXIT
trap 'error 130' INT
PS3_DEFAULT="$PS3"
PS3="$(printf '\033[1mEnter number:\033[0m') "
if [[ ! -z "$RESET" ]]; then
case "$RESET" in
*"package"*) package_appdir; package_appimage;;
esac
exit 0
fi
if [[ "$(uname -m)" == "aarch64" ]]; then
if [[ "$BUILD_METHOD" -ge 0 ]] && [[ "$BUILD_METHOD" -lt "${#BUILD_METHOD_ARR[@]}" ]] && [ "$BUILD_METHOD" -eq "$BUILD_METHOD" ] 2>/dev/null; then
echo -e "\e[1mBUILD_METHOD:\e[0m ${BUILD_METHOD_ARR[${BUILD_METHOD}]}"
BUILD_METHOD="${BUILD_METHOD_ARR[${BUILD_METHOD}]}"
else
echo -e "\e[1mWith which method would you like to use to build the BOX86 on the `uname -m` host?\e[0m"
select BUILD_METHOD in "${BUILD_METHOD_ARR[@]}"; do
[[ ! -z "$BUILD_METHOD" ]] && break
done
fi
if [[ ! -z "$BUILD_METHOD" ]]; then
check_dependencies 'git' 'arch-chroot' 'mksquashfs'
workdirs; get_sources
echo "Platform: \"$(tr a-z A-Z <<<"${platform}")\"."
echo -e "CMAKE flags: ${cmake_flags[@]}\n"
case "$BUILD_METHOD" in
"chroot"*) build_chroot ;;
#"toolchain"*) build_toolchain ;;
"new chroot"*) make_chroot; build_chroot ;;
*) error 1 ;;
esac
install_box86;
if [[ "$ARCH" == "aarch64" ]]; then
install_libs
copy_licenses
fi
package_appdir; package_appimage
error="$?"; [[ "$error" == 0 ]] || error 9 "packaging the box86"
cleanup
fi
elif [[ "$(uname -m)" =~ "armv7" || "$(uname -m)" == "armhf" || "$(uname -m)" == "arm32" ]]; then
# TODO: Package on the ARMv7 hosts.
error 8
else
error 8
fi
PS3="$PS3_DEFAULT"
unset PS3_DEFAULT
hash -r
trap - EXIT INT
tput rmcup
echo -e "\n🎉️ Successfully packaged the Appmage!"
echo -e "(${OUT}/box86-${ARCH}-${platform}.AppImage)\n"
exit 0