Skip to content

Commit 7ed2441

Browse files
Merge pull request #30 from 23xvx/add-support-platform-termux
Keep improving plugins/envsetup
2 parents 04d800f + 43a9380 commit 7ed2441

File tree

6 files changed

+74
-43
lines changed

6 files changed

+74
-43
lines changed

plugins/envsetup

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ do_mount() {
112112
do_unmount()
113113
{
114114
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
115-
lshout "Skipping unmount for termux"
115+
lshout "Skip unmount for termux"
116116
else
117117
local chroot_dir=$1
118118
points="$chroot_dir/dev $chroot_dir/sys $chroot_dir/proc"
@@ -221,7 +221,9 @@ see_for_directory() {
221221
no_to_directory() {
222222
dir="$1"
223223
if [ -d "$dir" ]; then
224-
if ! $NO_DIR_CHECK_OVERRIDE; then
224+
if [ "$NO_DIR_CHECK_OVERRIDE" == "true" ]; then
225+
return 0
226+
else
225227
die "directory exits: $dir"
226228
fi
227229
fi
@@ -261,10 +263,26 @@ do_build() {
261263
export DISABLE_USER_SETUP=false
262264
fi
263265

264-
includes_packages
265266
foreign_arch "$arch"
266-
no_to_directory "$target_dir"
267267

268+
#Disable cross architecture building in Termux
269+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
270+
case $worker_arch in
271+
aarch64) termux_arch="arm64" ;;
272+
arm*) termux_arch="armhf" ;;
273+
amd64|x86_64) termux_arch="amd64" ;;
274+
*) die "Unknown architecture" ;;
275+
esac
276+
if [ "$termux_arch" != "$arch" ]; then
277+
lshout "Skip building $target_dir for termux"
278+
return 0
279+
else
280+
lshout "Building on Termux"
281+
fi
282+
fi
283+
284+
includes_packages
285+
no_to_directory "$target_dir"
268286

269287
export chroot_dir
270288
chroot_dir=$target_dir
@@ -287,24 +305,6 @@ do_build() {
287305
suite="jammy"
288306
fi
289307

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-
308308
shout "debootstraping $suite to $target_dir"
309309

310310
if [[ -n $OVERRIDER_MIRROR ]]; then
@@ -323,6 +323,7 @@ do_build() {
323323
fi
324324

325325
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
326+
dpkg_depends_on debootstrap
326327
_debootstrap="$(which debootstrap)"
327328
FOREIGN=""
328329
ENABLE_USER_SETUP=false
@@ -346,7 +347,7 @@ do_build() {
346347
do_second_stage "$target_dir" "$arch"
347348
fi
348349

349-
if $ENABLE_USER_SETUP; then
350+
if [ "$ENABLE_USER_SETUP" == "true" ]; then
350351
setup_user
351352
fi
352353

@@ -405,6 +406,17 @@ do_qemu_user_emulation() {
405406
fi
406407
}
407408

409+
setup_user() {
410+
shout "Setting up user"
411+
cp plugins/setup-user.sh $chroot_dir
412+
sed -i "s/FS_USER/$FS_USER/g" $chroot_dir/setup-user.sh
413+
sed -i "s/FS_PASS/$FS_PASS/g" $chroot_dir/setup-user.sh
414+
install_pkg "openssl"
415+
run_cmd "chmod +x /setup-user.sh"
416+
run_cmd "/bin/bash /setup-user.sh"
417+
run_cmd "rm -rf /setup-user.sh"
418+
}
419+
408420
do_chroot_proot_ae() {
409421
local chroot_dir=$1
410422
shift
@@ -434,7 +446,6 @@ do_chroot_proot_ae() {
434446
--cwd=/root -L \
435447
--kernel-release=5.4.0-faked \
436448
--rootfs="${root_fs_path}" \
437-
-w /root \
438449
/usr/bin/env -i \
439450
HOME=/root \
440451
PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
@@ -472,9 +483,11 @@ do_compress() {
472483
export chroot_dir=$1
473484
TARGET_FILE="$(basename ${chroot_dir})"
474485

475-
if [ "$termux_build" == "false" ]; then
476-
lshout "skip compressing $chroot_dir "
477-
return 0
486+
if [ "$FS_COOK_PLATFORM" == "termux" ]; then
487+
if [ ! -d "$chroot_dir" ]; then
488+
lshout "Skip compressing $chroot_dir "
489+
return 0
490+
fi
478491
fi
479492

480493
if [ -n "$OVERRIDER_COMPRESSION_TYPE" ]; then

plugins/gz-packer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
target=$1
44

55
tar \
6-
--exclude={/data,/dev,/apex,/vendor,/system,/sdcard} \
7-
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
6+
--exclude={/data,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
88
--exclude="*.l2s.*" \
99
--exclude=/${0} \
1010
--exclude="/${target}.tar.gz" \

plugins/j-packer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
target=$1
44

55
tar \
6-
--exclude={/data,/dev,/apex,/vendor,/system,/sdcard} \
7-
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
6+
--exclude={/data,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
88
--exclude="*.l2s.*" \
99
--exclude=/${0} \
1010
--exclude="/${target}.tar.gz" \

plugins/lz-packer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
target=$1
44

55
tar \
6-
--exclude={/data,/dev,/apex,/vendor,/system,/sdcard} \
7-
--exclude={/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
6+
--exclude={/data,/apex,/vendor,/system,/sdcard} \
7+
--exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found/*} \
88
--exclude="*.l2s.*" \
99
--exclude=/${0} \
1010
--exclude="/${target}.tar.gz" \

plugins/setup-user.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# username = FS_USER
4+
# password = FS_PASS
5+
6+
useradd -m \
7+
-p "$(openssl passwd -1 FS_PASS)" \
8+
-G sudo \
9+
-d /home/FS_USER \
10+
-k /etc/skel \
11+
-s /bin/bash \
12+
FS_USER
13+
echo FS_USER ALL=\(root\) ALL > /etc/sudoers.d/FS_USER
14+
chmod 0440 /etc/sudoers.d/FS_USER

setup.sh

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

33
# sudo check
4-
if [ "$(id -u)" != "0" ]; then
5-
if ! command -v sudo >/dev/null 2>&1; then
6-
echo "This script requires sudo or root privileges but none present."
7-
exit 1
8-
else
9-
SUDO="$(command -v sudo)"
4+
if [ "$(uname -o)" = "Android" ]; then
5+
echo "Running in Termux"
6+
apt update
7+
apt install debootstrap which -y
8+
else
9+
if [ "$(id -u)" != "0" ]; then
10+
if ! command -v sudo >/dev/null 2>&1; then
11+
echo "This script requires sudo or root privileges but none present."
12+
exit 1
13+
else
14+
SUDO="$(command -v sudo)"
15+
fi
1016
fi
17+
$SUDO apt update
18+
$SUDO apt install -y qemu-user-static binfmt-support
1119
fi
12-
13-
deps="qemu-user-static binfmt-support"
14-
15-
$SUDO apt install -y "$deps"

0 commit comments

Comments
 (0)