Created
August 12, 2023 03:09
-
-
Save ilhan-athn7/fb1f4e141bc1f6fa02659fe803b885f8 to your computer and use it in GitHub Desktop.
Single script to login chroot on android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sh | |
# Execute from Termux app, running as root results no sound. | |
# Must have pulseaudio and termux-x11. | |
# Must have root access. | |
if [ "$(id -u)" -eq "$TERMUX_APP__UID" ]; then | |
### Start pulseaudio | |
pulseaudio --start --load=" \ | |
module-native-protocol-tcp auth-ip-acl=127.0.0.1 \ | |
auth-anonymous=1" --exit-idle-time=-1 | |
### Run again as root | |
su -c sh "$(pwd)"/"$0" | |
fi | |
if [ "$(id -u)" -eq "0" ]; then | |
### Mount directories | |
rootdir='/data/archlinux' | |
mnt_dirs='/dev /sys /proc /sdcard' | |
mount -o remount,dev,suid /data | |
for dirs in $mnt_dirs; do | |
mount --bind "$dirs" "$rootdir""$dirs"; done | |
mount --bind /dev/pts "$rootdir"/dev/pts | |
mkdir -p /dev/shm | |
mount -t tmpfs tmpfs /dev/shm | |
mount --bind /dev/shm "$rootdir"/dev/shm | |
mount --bind "$TMPDIR" "$rootdir"/tmp | |
### Start Termux:X11 | |
unset LD_LIBRARY_PATH LD_PRELOAD | |
env \ | |
TMPDIR="$rootdir"/tmp \ | |
XKB_CONFIG_ROOT="$rootdir"/usr/share/X11/xkb \ | |
CLASSPATH="$(/system/bin/pm path com.termux.x11 | cut -d: -f2)" \ | |
app_process / com.termux.x11.CmdEntryPoint :0 & | |
### Login chroot | |
chroot "$rootdir" /bin/su -l ilhan | |
### Kill tasks | |
pkill -f "app_process.*x11" | |
pkill -f "pulseaudio" | |
### Unmount directories | |
umount "$rootdir"/dev/pts | |
umount "$rootdir"/tmp | |
for dirs in $mnt_dirs; do | |
umount "$rootdir""$dirs"; done | |
umount "$rootdir"/dev/shm | |
umount /dev/shm | |
rmdir /dev/shm | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment