Skip to content

Commit 04d800f

Browse files
Merge pull request #29 from 23xvx/add-support-platform-termux
Fix errors in Termux
2 parents c77c31a + e45a567 commit 04d800f

File tree

1 file changed

+68
-39
lines changed

1 file changed

+68
-39
lines changed

plugins/envsetup

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@
2424
# SOFTWARE.
2525

2626
export ROOT_DIR
27+
export BUILD_PALTFORM="linux"
2728

28-
if [ -z $ENABLE_USER_SETUP ]; then
29-
export ENABLE_USER_SETUP=false
30-
fi
29+
_c_magneta="\e[95m"
30+
_c_green="\e[32m"
31+
_c_red="\e[31m"
32+
_c_blue="\e[34m"
33+
RST="\e[0m"
3134

32-
ROOT_DIR="$(git rev-parse --show-toplevel)"
35+
die() { echo -e "${_c_red}[E] ${*}${RST}";exit 1;:;}
36+
warn() { echo -e "${_c_red}[W] ${*}${RST}";:;}
37+
shout() { echo -e "${_c_blue}[-] ${*}${RST}";:;}
38+
lshout() { echo -e "${_c_blue}-> ${*}${RST}";:;}
39+
msg() { echo -e "${*} \e[0m" >&2;:;}
40+
41+
# Check if environment is Termux
42+
if [ "$(uname -o)" = "Android" ]; then
43+
export FS_COOK_PLATFORM="termux"
44+
fi
3345

3446
# sudo check
3547
if [ "$(id -u)" != "0" ]; then
@@ -44,17 +56,11 @@ if [ "$(id -u)" != "0" ]; then
4456
fi
4557
fi
4658

47-
_c_magneta="\e[95m"
48-
_c_green="\e[32m"
49-
_c_red="\e[31m"
50-
_c_blue="\e[34m"
51-
RST="\e[0m"
59+
if [ -z $ENABLE_USER_SETUP ]; then
60+
export ENABLE_USER_SETUP=false
61+
fi
5262

53-
die() { echo -e "${_c_red}[E] ${*}${RST}";exit 1;:;}
54-
warn() { echo -e "${_c_red}[W] ${*}${RST}";:;}
55-
shout() { echo -e "${_c_blue}[-] ${*}${RST}";:;}
56-
lshout() { echo -e "${_c_blue}-> ${*}${RST}";:;}
57-
msg() { echo -e "${*} \e[0m" >&2;:;}
63+
ROOT_DIR="$(git rev-parse --show-toplevel)"
5864

5965
trim_quotes() {
6066
# Usage: trim_quotes "string"
@@ -105,24 +111,28 @@ do_mount() {
105111

106112
do_unmount()
107113
{
108-
local chroot_dir=$1
109-
points="$chroot_dir/dev $chroot_dir/sys $chroot_dir/proc"
110-
see_for_directory "$points"
111-
if is_mounted "$chroot_dir/dev"; then
112-
shout "unmounting: $chroot_dir/dev"
113-
$SUDO umount "$chroot_dir"/dev/pts
114-
$SUDO umount "$chroot_dir"/dev
115-
fi
116-
117-
if is_mounted "$chroot_dir"/proc; then
118-
shout "unmounting: $chroot_dir/proc"
119-
$SUDO umount $chroot_dir/proc
120-
fi
121-
122-
if is_mounted "$chroot_dir"/sys; then
123-
shout "unmounting: $chroot_dir/sys"
124-
$SUDO umount "$chroot_dir"/sys
125-
fi
114+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
115+
lshout "Skipping unmount for termux"
116+
else
117+
local chroot_dir=$1
118+
points="$chroot_dir/dev $chroot_dir/sys $chroot_dir/proc"
119+
see_for_directory "$points"
120+
if is_mounted "$chroot_dir/dev"; then
121+
shout "unmounting: $chroot_dir/dev"
122+
$SUDO umount "$chroot_dir"/dev/pts
123+
$SUDO umount "$chroot_dir"/dev
124+
fi
125+
126+
if is_mounted "$chroot_dir"/proc; then
127+
shout "unmounting: $chroot_dir/proc"
128+
$SUDO umount $chroot_dir/proc
129+
fi
130+
131+
if is_mounted "$chroot_dir"/sys; then
132+
shout "unmounting: $chroot_dir/sys"
133+
$SUDO umount "$chroot_dir"/sys
134+
fi
135+
fi
126136
}
127137

128138
is_mounted() {
@@ -255,6 +265,7 @@ do_build() {
255265
foreign_arch "$arch"
256266
no_to_directory "$target_dir"
257267

268+
258269
export chroot_dir
259270
chroot_dir=$target_dir
260271

@@ -276,6 +287,24 @@ do_build() {
276287
suite="jammy"
277288
fi
278289

290+
#Disable cross architecture building in Termux
291+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
292+
case $worker_arch in
293+
aarch64) termux_arch="arm64" ;;
294+
arm*) termux_arch="armhf" ;;
295+
amd64|x86_64) termux_arch="amd64" ;;
296+
*) die "Unknown architecture" ;;
297+
esac
298+
if [ "$termux_arch" != "$arch" ]; then
299+
lshout "Skipping cross architecture building for termux"
300+
termux_build=false
301+
return 0
302+
else
303+
lshout "Building on Termux"
304+
termux_build=true
305+
fi
306+
fi
307+
279308
shout "debootstraping $suite to $target_dir"
280309

281310
if [[ -n $OVERRIDER_MIRROR ]]; then
@@ -312,6 +341,7 @@ do_build() {
312341

313342
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
314343
lshout "Skipping second stage for termux"
344+
arch_translate "$arch"
315345
else
316346
do_second_stage "$target_dir" "$arch"
317347
fi
@@ -441,6 +471,11 @@ do_compress() {
441471
export TARGET_FILE
442472
export chroot_dir=$1
443473
TARGET_FILE="$(basename ${chroot_dir})"
474+
475+
if [ "$termux_build" == "false" ]; then
476+
lshout "skip compressing $chroot_dir "
477+
return 0
478+
fi
444479

445480
if [ -n "$OVERRIDER_COMPRESSION_TYPE" ]; then
446481
case $OVERRIDER_COMPRESSION_TYPE in
@@ -541,14 +576,8 @@ install_pkg()
541576

542577
banner
543578

544-
export BUILD_PALTFORM="linux"
545-
546-
#Check if environment is Termux
547-
if [ "$(uname -o)" = "Android" ]; then
548-
export FS_COOK_PLATFORM="termux"
549-
fi
550-
551579
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
552580
lshout "Running on termux"
553581
BUILD_PALTFORM="termux"
554582
fi
583+

0 commit comments

Comments
 (0)