Skip to content

Commit 60df6ef

Browse files
feat: add initial works for termux support
1 parent 0c1437c commit 60df6ef

File tree

4 files changed

+100
-38
lines changed

4 files changed

+100
-38
lines changed

plugins/envsetup

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ ROOT_DIR="$(git rev-parse --show-toplevel)"
3333

3434
# sudo check
3535
if [ "$(id -u)" != "0" ]; then
36-
if ! command -v sudo >/dev/null 2>&1; then
37-
echo "This script requires sudo or root privileges but none present."
38-
exit 1
36+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
37+
SUDO=""
3938
else
40-
SUDO="$(command -v sudo)"
39+
if command -v sudo &>/dev/null; then
40+
SUDO="sudo"
41+
else
42+
die "This script requires root privileges"
43+
fi
4144
fi
4245
fi
4346

@@ -290,6 +293,12 @@ do_build() {
290293
_debootstrap=$(which debootstrap)
291294
fi
292295

296+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
297+
_debootstrap="$(which debootstrap)"
298+
FOREIGN=""
299+
ENABLE_USER_SETUP=false
300+
fi
301+
293302
(
294303
$SUDO $_debootstrap \
295304
$FOREIGN \
@@ -301,7 +310,11 @@ do_build() {
301310
$MIRROR
302311
) || die "Couldn't debootstrap..."
303312

304-
do_second_stage "$target_dir" "$arch"
313+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
314+
lshout "Skipping second stage for termux"
315+
else
316+
do_second_stage "$target_dir" "$arch"
317+
fi
305318

306319
if $ENABLE_USER_SETUP; then
307320
setup_user
@@ -362,7 +375,49 @@ do_qemu_user_emulation() {
362375
fi
363376
}
364377

365-
do_chroot_ae() {
378+
do_chroot_proot_ae() {
379+
local chroot_dir=$1
380+
shift
381+
local cmd_string=$*
382+
local root_fs_path=${chroot_dir}
383+
local container_user=root
384+
385+
unset LD_PRELOAD
386+
proot \
387+
--link2symlink \
388+
--sysvipc \
389+
--kill-on-exit \
390+
-b /system \
391+
-b /sys \
392+
-b /proc \
393+
-b /dev \
394+
-b /dev/urandom:/dev/random \
395+
-b /proc/self/fd/1:/dev/stdout \
396+
-b /proc/self/fd/2:/dev/stderr \
397+
-b /proc/self/fd/0:/dev/stdin \
398+
-b /proc/self/fd:/dev/fd \
399+
-b /data/data/com.termux/files/usr \
400+
-b /data/data/com.termux/files/home \
401+
-b /data/data/com.termux/cache \
402+
-b /storage/self/primary:/sdcard \
403+
-b "${root_fs_path}"/tmp:/dev/shm \
404+
--root-id \
405+
--cwd=/root -L \
406+
--kernel-release=5.4.0-faked \
407+
--kill-on-exit \
408+
--rootfs="${root_fs_path}" \
409+
-w /root \
410+
/usr/bin/env -i \
411+
HOME=/root \
412+
PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
413+
TERM="$TERM" \
414+
LANG=C.UTF-8 \
415+
/bin/su -l $container_user \
416+
$cmd_string
417+
418+
}
419+
420+
do_chroot_root_ae() {
366421
local chroot_dir=$1
367422
shift
368423
local command=$*
@@ -376,6 +431,14 @@ do_chroot_ae() {
376431
fi
377432
}
378433

434+
do_chroot_ae() {
435+
if [ $BUILD_PALTFORM == "termux" ]; then
436+
do_chroot_proot_ae "$@"
437+
else
438+
do_chroot_root_ae "$@"
439+
fi
440+
}
441+
379442
do_compress() {
380443
#compression
381444
export TARGET_FILE
@@ -480,3 +543,10 @@ install_pkg()
480543
}
481544

482545
banner
546+
547+
export BUILD_PALTFORM="linux"
548+
549+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
550+
lshout "Running on termux"
551+
BUILD_PALTFORM="termux"
552+
fi

plugins/gz-packer.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#!/usr/bin/env bash
22

33
target=$1
4-
target_source=/
5-
# target_source=
64

75
tar \
8-
--exclude="${target_source}"dev/* \
9-
--exclude="${target_source}"run/* \
10-
--exclude="${target_source}"proc/* \
11-
--exclude="${target_source}"sys/* \
12-
--exclude="${target_source}"tmp/* \
13-
--exclude="${target_source}"${0} \
14-
--exclude="${target_source}${target}.tar.gz" \
6+
--exclude={/dev,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
8+
--exclude="*.l2s.*" \
9+
--exclude=/${0} \
10+
--exclude="/${target}.tar.gz" \
1511
--exclude-caches-all \
12+
--one-file-system \
1613
-cpf \
17-
- "${target_source}" -P \
18-
| pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\
14+
- / -P \
15+
| pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\
1916
gzip --best > "${target}".tar.gz

plugins/j-packer.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#!/usr/bin/env bash
22

33
target=$1
4-
target_source=/
54

65
tar \
7-
--exclude="${target_source}"dev/* \
8-
--exclude="${target_source}"run/* \
9-
--exclude="${target_source}"proc/* \
10-
--exclude="${target_source}"sys/* \
11-
--exclude="${target_source}"tmp/* \
12-
--exclude="${target_source}"${0} \
13-
--exclude="${target_source}${target}.tar.xz" \
6+
--exclude={/dev,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
8+
--exclude="*.l2s.*" \
9+
--exclude=/${0} \
10+
--exclude="/${target}.tar.gz" \
1411
--exclude-caches-all \
12+
--one-file-system \
1513
-cpf \
16-
- "${target_source}" -P \
17-
| pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\
14+
- / -P \
15+
| pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\
1816
bzip2 --best > "${target}".tar.xz

plugins/lz-packer.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#!/usr/bin/env bash
22

33
target=$1
4-
target_source=/
5-
# target_source=
64

75
tar \
8-
--exclude="${target_source}"dev/* \
9-
--exclude="${target_source}"run/* \
10-
--exclude="${target_source}"proc/* \
11-
--exclude="${target_source}"sys/* \
12-
--exclude="${target_source}"tmp/* \
13-
--exclude="${target_source}"${0} \
14-
--exclude="${target_source}${target}.tar.lz" \
6+
--exclude={/dev,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
8+
--exclude="*.l2s.*" \
9+
--exclude=/${0} \
10+
--exclude="/${target}.tar.gz" \
1511
--exclude-caches-all \
12+
--one-file-system \
1613
-cpf \
17-
- "${target_source}" -P \
18-
| pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\
14+
- / -P \
15+
| pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\
1916
lz4 -9 > "${target}".tar.lz # use high compression

0 commit comments

Comments
 (0)