Skip to content

Commit

Permalink
feat: add initial works for termux support
Browse files Browse the repository at this point in the history
  • Loading branch information
SaicharanKandukuri committed Dec 4, 2023
1 parent 0c1437c commit 60df6ef
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 38 deletions.
82 changes: 76 additions & 6 deletions plugins/envsetup
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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=$*
Expand All @@ -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
Expand Down Expand Up @@ -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
19 changes: 8 additions & 11 deletions plugins/gz-packer.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 8 additions & 10 deletions plugins/j-packer.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 8 additions & 11 deletions plugins/lz-packer.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 60df6ef

Please sign in to comment.