From 60df6ef9b1e9962217838106403f2e97965f361b Mon Sep 17 00:00:00 2001 From: saicharankandukuri Date: Mon, 4 Dec 2023 16:09:17 +0530 Subject: [PATCH] feat: add initial works for termux support --- plugins/envsetup | 82 ++++++++++++++++++++++++++++++++++++++++---- plugins/gz-packer.sh | 19 +++++----- plugins/j-packer.sh | 18 +++++----- plugins/lz-packer.sh | 19 +++++----- 4 files changed, 100 insertions(+), 38 deletions(-) diff --git a/plugins/envsetup b/plugins/envsetup index 98becc5..adb05f3 100755 --- a/plugins/envsetup +++ b/plugins/envsetup @@ -33,11 +33,14 @@ ROOT_DIR="$(git rev-parse --show-toplevel)" # sudo check if [ "$(id -u)" != "0" ]; then - if ! command -v sudo >/dev/null 2>&1; then - echo "This script requires sudo or root privileges but none present." - exit 1 + if [ "$FS_COOK_PLATFORM" == "termux" ]; then + SUDO="" else - SUDO="$(command -v sudo)" + if command -v sudo &>/dev/null; then + SUDO="sudo" + else + die "This script requires root privileges" + fi fi fi @@ -290,6 +293,12 @@ do_build() { _debootstrap=$(which debootstrap) fi + if [ "$FS_COOK_PLATFORM" == "termux" ]; then + _debootstrap="$(which debootstrap)" + FOREIGN="" + ENABLE_USER_SETUP=false + fi + ( $SUDO $_debootstrap \ $FOREIGN \ @@ -301,7 +310,11 @@ do_build() { $MIRROR ) || die "Couldn't debootstrap..." - do_second_stage "$target_dir" "$arch" + if [ "$FS_COOK_PLATFORM" == "termux" ]; then + lshout "Skipping second stage for termux" + else + do_second_stage "$target_dir" "$arch" + fi if $ENABLE_USER_SETUP; then setup_user @@ -362,7 +375,49 @@ do_qemu_user_emulation() { fi } -do_chroot_ae() { +do_chroot_proot_ae() { + local chroot_dir=$1 + shift + local cmd_string=$* + local root_fs_path=${chroot_dir} + local container_user=root + + unset LD_PRELOAD + proot \ + --link2symlink \ + --sysvipc \ + --kill-on-exit \ + -b /system \ + -b /sys \ + -b /proc \ + -b /dev \ + -b /dev/urandom:/dev/random \ + -b /proc/self/fd/1:/dev/stdout \ + -b /proc/self/fd/2:/dev/stderr \ + -b /proc/self/fd/0:/dev/stdin \ + -b /proc/self/fd:/dev/fd \ + -b /data/data/com.termux/files/usr \ + -b /data/data/com.termux/files/home \ + -b /data/data/com.termux/cache \ + -b /storage/self/primary:/sdcard \ + -b "${root_fs_path}"/tmp:/dev/shm \ + --root-id \ + --cwd=/root -L \ + --kernel-release=5.4.0-faked \ + --kill-on-exit \ + --rootfs="${root_fs_path}" \ + -w /root \ + /usr/bin/env -i \ + HOME=/root \ + PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \ + TERM="$TERM" \ + LANG=C.UTF-8 \ + /bin/su -l $container_user \ + $cmd_string + +} + +do_chroot_root_ae() { local chroot_dir=$1 shift local command=$* @@ -376,6 +431,14 @@ do_chroot_ae() { fi } +do_chroot_ae() { + if [ $BUILD_PALTFORM == "termux" ]; then + do_chroot_proot_ae "$@" + else + do_chroot_root_ae "$@" + fi +} + do_compress() { #compression export TARGET_FILE @@ -480,3 +543,10 @@ install_pkg() } banner + +export BUILD_PALTFORM="linux" + +if [ "$FS_COOK_PLATFORM" == "termux" ]; then + lshout "Running on termux" + BUILD_PALTFORM="termux" +fi diff --git a/plugins/gz-packer.sh b/plugins/gz-packer.sh index ae27b9a..65b7381 100755 --- a/plugins/gz-packer.sh +++ b/plugins/gz-packer.sh @@ -1,19 +1,16 @@ #!/usr/bin/env bash target=$1 -target_source=/ -# target_source= tar \ - --exclude="${target_source}"dev/* \ - --exclude="${target_source}"run/* \ - --exclude="${target_source}"proc/* \ - --exclude="${target_source}"sys/* \ - --exclude="${target_source}"tmp/* \ - --exclude="${target_source}"${0} \ - --exclude="${target_source}${target}.tar.gz" \ + --exclude={/dev,/apex,/vendor,/system,/sdcard} \ + --exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \ + --exclude="*.l2s.*" \ + --exclude=/${0} \ + --exclude="/${target}.tar.gz" \ --exclude-caches-all \ + --one-file-system \ -cpf \ - - "${target_source}" -P \ - | pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\ + - / -P \ + | pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\ gzip --best > "${target}".tar.gz diff --git a/plugins/j-packer.sh b/plugins/j-packer.sh index 0cfac83..edd14b9 100755 --- a/plugins/j-packer.sh +++ b/plugins/j-packer.sh @@ -1,18 +1,16 @@ #!/usr/bin/env bash target=$1 -target_source=/ tar \ - --exclude="${target_source}"dev/* \ - --exclude="${target_source}"run/* \ - --exclude="${target_source}"proc/* \ - --exclude="${target_source}"sys/* \ - --exclude="${target_source}"tmp/* \ - --exclude="${target_source}"${0} \ - --exclude="${target_source}${target}.tar.xz" \ + --exclude={/dev,/apex,/vendor,/system,/sdcard} \ + --exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \ + --exclude="*.l2s.*" \ + --exclude=/${0} \ + --exclude="/${target}.tar.gz" \ --exclude-caches-all \ + --one-file-system \ -cpf \ - - "${target_source}" -P \ - | pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\ + - / -P \ + | pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\ bzip2 --best > "${target}".tar.xz diff --git a/plugins/lz-packer.sh b/plugins/lz-packer.sh index 2260821..b406949 100755 --- a/plugins/lz-packer.sh +++ b/plugins/lz-packer.sh @@ -1,19 +1,16 @@ #!/usr/bin/env bash target=$1 -target_source=/ -# target_source= tar \ - --exclude="${target_source}"dev/* \ - --exclude="${target_source}"run/* \ - --exclude="${target_source}"proc/* \ - --exclude="${target_source}"sys/* \ - --exclude="${target_source}"tmp/* \ - --exclude="${target_source}"${0} \ - --exclude="${target_source}${target}.tar.lz" \ + --exclude={/dev,/apex,/vendor,/system,/sdcard} \ + --exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \ + --exclude="*.l2s.*" \ + --exclude=/${0} \ + --exclude="/${target}.tar.gz" \ --exclude-caches-all \ + --one-file-system \ -cpf \ - - "${target_source}" -P \ - | pv -s $(($(du -skx "${target_source}" | awk '{print $1}') * 1024)) |\ + - / -P \ + | pv -s $(($(du -skx / | awk '{print $1}') * 1024)) |\ lz4 -9 > "${target}".tar.lz # use high compression