#!/bin/bash -e
cd $(dirname $0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
command+=" --link2symlink"
command+=" -0"
command+=" -r /data/data/com.termux/files/home/rootfs"
if [ -n "$(ls -A /data/data/com.termux/files/home/fs-bd)" ]; then
	    for f in /data/data/com.termux/files/home/fs-bd/* ;do
		          . $f
			      done
fi
command+=" -q ./qemu-x86_64-static"
command+=" -b /dev"
command+=" -b /proc"
command+=" -b /sys"
command+=" -b /data/data/com.termux/files/home/rootfs/root:/dev/shm"
## 挂载termux HOME目录到 /root (建议关闭)
#command+=" -b /data/data/com.termux/files/home:/root"
## 挂载手机/sdcard到 / (建议打开)
command+=" -b /sdcard"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=$TERM"
##修改语言
command+=" LANG=zh_CN.UTF-8"
##修改默认命令行 ps:已美化
command+=" /bin/bash --login"
com="$@"
if [ -z "$1" ];then
	    exec $command
    else
	        $command -c "$com"
fi
