Termux一键安装proot环境
#!/bin/bash/n/n#字体颜色/n########################################################/nRED='//e[1;31m' # 红/nGREEN='//e[1;32m' # 绿/nYELLOW='//e[1;33m' # 黄/nBLUE='//e[1;34m' # 蓝/nPINK='//e[1;35m' # 粉红/nRES='//e[0m' # 清除颜色/n##字体颜色/n/n#常用变量和函数/n########################################################/ngettime(){/necho -e /'${YELLOW}[$(date +/'%Y-%m-%d %H:%M:%S/')]${RES} /'/n}/nvariable() {/n wheregit=$(grep -oP 'wheregit//s*://s*///'//K[^///'//+]' ${HOME}/.gancm/bot/variable.cfg )/n}/nself_install() {/n case ${2} in/n pip)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n pip install -y ${1}/n fi/n ;;/n pip3)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n pip3 install -y ${1}/n fi/n ;;/n apt)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n apt install -y ${1}/n fi/n ;;/n esac/n}/nhcjx() {/n echo -e /'${GREEN}请按回车键继续下一条指令...${RES}/'/n read -r/n}/n########################################################/n#效验/nvalidity(){/n validity_dir/n validity_git/n /n}/nvalidity_dir() {/n if [ ! -d ${HOME}/.gancm/ ]; then/n mkdir ${HOME}/.gancm//n fi/n if [ ! -d ${HOME}/.gancm/proot ]; then/n mkdir ${HOME}/.gancm/proot/n fi/n if [ ! -d ${HOME}/.gancm/download ]; then/n mkdir ${HOME}/.gancm/download/n fi/n if [ ! -d ${HOME}/.gancm/bot ]; then/n mkdir ${HOME}/.gancm/bot/n fi/n}/n/nvalidity_git() {/n if [ ! -f ${HOME}/.gancm/bot/variable.cfg ]; then/n wheregit=(/n whiptail --title /'选择默认安装源/' --menu /'以后的每次安装会优先考虑默认安装源/' 15 60 4 ///n /'Github/' /'1/' ///n /'Gitee/' /'2/' ///n /'0/' /'退出/' 3>&1 1>&2 2>&3/n )/n case ${wheregit} in/n 0)/n echo -e /'$(gettime) 未选择默认修改为 ${YELLOW}Gitee${RES} /'/n echo -e /'//n wheregit:/'Gitee/'//n /' > ${HOME}/.gancm/bot/variable.cfg/n return 0/n ;;/n *)/n echo -e /'//n wheregit:/'$wheregit/'//n /' > ${HOME}/.gancm/bot/variable.cfg/n ;;/n esac/n fi/n}/n/n#下载逻辑/n########################################################/n/n/nDownload_YunzaiBot() {/n echo 1/n}/n/n/n########################################################/n#proot相关/n/nstart_proot() {/n proot_list() {/n ls ${HOME}/.gancm/proot//n }/n list=0/n newproot_list=(/n for j in $(proot_list); do/n let list++/n for proot_list in $list; do/n oldproot_list=/'$j/' /'$list/' /'/n echo $oldproot_list/n done/n done/n )/n while true; do/n proot_number=(/n whiptail --title /'选择proor/' --menu /'proot选择/' 20 50 6 ///n $newproot_list 返回上级 0 3>&1 1>&2 2>&3/n )/n case ${proot_number} in/n 返回上级)/n break/n ;;/n *)/n unset LD_PRELOAD/n proot --link2symlink -0 -r ${HOME}/.gancm/proot/${proot_number} -b /dev -b /proc -b ${HOME}/.gancm/proot/${proot_number}/root:/dev/shm -w /root /usr/bin/env -i HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games TERM=xterm-256color LANG=zh_CN.UTF-8 /bin/bash --login/n break/n ;;/n esac/n done/n/n}/n/nDownload_proot_os() {/n proot_os_list=(/n whiptail --title /'选择系统镜像/' --menu /'按自己喜好来/' 15 60 4 ///n /'1/' /'乌班图18.04/' ///n /'2/' /'乌班图20.04/' ///n /'3/' /'乌班图22.04/' ///n /'0/' /'退出/' 3>&1 1>&2 2>&3/n )/n self_install proot apt/n case ${proot_os_list} in/n 1) /n os_name=ubuntu18.04_arm64_rootfs/n Download_proot_url=https://mirrors.tuna.tsinghua.edu.cn/lxc-images/images/ubuntu/bionic/arm64/default/20230829_07%3A43/rootfs.tar.xz/n ;;/n 2)/n os_name=ubuntu20.04_arm64_rootfs/n Download_proot_url=https://mirrors.tuna.tsinghua.edu.cn/lxc-images/images/ubuntu/focal/arm64/default/20230827_07%3A42/rootfs.tar.xz /n ;;/n 3)/n os_name=ubuntu22.04_arm64_rootfs/n Download_proot_url=https://mirrors.tuna.tsinghua.edu.cn/lxc-images/images/ubuntu/jammy/arm64/default/20230829_07%3A57/rootfs.tar.xz/n ;;/n )/n exit 1/n ;;/n esac/n echo -e /'$(gettime)${GREEN}正在下载 ${YELLOW}${os_name}${GREEN} 镜像文件${RES}/'/n if [ ! -f ${HOME}/.gancm/download/${os_name}.tar.xz ]; then/n if $(wget -q --show-progress ${Download_proot_url} -O ${HOME}/.gancm/download/${os_name}.tar.xz) ;then/n echo -e /'$(gettime)${GREEN}下载完成${RES}//n你可以使用 ${RED}rm -rf ${HOME}/.gancm/proot/${os_name}.tar.xz${RES} 来删除镜像已节省手机可用空间/'/n else/n echo -e /'$(gettime)${RED}下载失败${RES}/'/n exit 1/n fi/n else/n echo -e /'$(gettime)${GREEN}已存在文件${RES}//n${GREEN}是${RED}否${YELLOW}使用已下载的镜像${RES}[${GREEN}Y${RES}/${RED}N${RES}]/'/n read -p /'/' YES/n case $YES in/n Y|y|yes|YES)/n hcjx/n ;;/n N|m|No|NO)/n echo -e /'$(gettime)${YELLOW}重新下载文件.ing${RES}/'/n if $(wget -q --show-progress ${Download_proot_url} -O ${HOME}/.gancm/download/${os_name}.tar.xz) ;then/n echo -e /'$(gettime)${GREEN}下载完成${RES}//n你可以使用 ${RED}rm -rf ${HOME}/.gancm/proot/${os_name}.tar.xz${RES} 来删除镜像已节省手机可用空间/'/n else/n echo -e /'$(gettime)${RED}下载失败${RES}/'/n exit 1/n fi/n ;;/n esac/n fi/n /n if [ ! -d ${HOME}/.gancm/proot/${os_name}/ ]; then/n mkdir ${HOME}/.gancm/proot/${os_name}//n fi/n unset LD_PRELOAD/n cp -r ./proot/proot_proc ${HOME}/.gancm/proot/${os_name}.tar.xz/proc/n proot --link2symlink tar -xJf ${HOME}/.gancm/download/${os_name}.tar.xz -C ${HOME}/.gancm/proot/${os_name}/ --exclude='dev'||:/n proot_yh/n unset LD_PRELOAD/n}/nproot_yh() {/n unset LD_PRELOAD/n echo /'127.0.0.1 localhost/' > ${HOME}/.gancm/proot/${os_name}/etc/hosts/n cp $0 ${HOME}/.gancm/proot/${os_name}/root/mit.sh/n echo -e /'$(gettime)${GREEN}已将本脚本复制到容器${RES}/'/n cp -r ./proot/proot_proc/ ${HOME}/.gancm/proot/${os_name}/proc/n echo -e /'$(gettime)${GREEN}正在复制伪装proc文件${RES}/'/n /n echo -e '//ngettime(){/n echo -e /'${YELLOW}[$(date +/'%Y-%m-%d %H:%M:%S/')]${RES} /'/n}/nRED=//'/''//e[1;31m//'/'' # 红/nGREEN=//'/''//e[1;32m//'/'' # 绿/nYELLOW=//'/''//e[1;33m//'/'' # 黄/nBLUE=//'/''//e[1;34m//'/'' # 蓝/nPINK=//'/''//e[1;35m//'/'' # 粉红/nRES=//'/''//e[0m//'/'' # 清除颜色/n/nself_install() {/n case ${2} in/n pip)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n pip install -y ${1}/n fi/n ;;/n pip3)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n pip3 install -y ${1}/n fi/n ;;/n apt)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n apt install -y ${1}/n fi/n ;;/n pkg)/n if [ ! -f /'$(command -v ${1})/']; then/n echo -e /'$(gettime)${RED}目前并没有安装 ${1} 正在安装${RES}/'/n pkg install -y ${1}/n fi/n ;;/n esac/n}/n/necho -e /'$(gettime)${GREEN}修复时区${RES}/'/ncp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime/n/necho -e /'$(gettime)${GREEN}修复dns${RES}/'/nmkdir -p /run/systemd/resolve/necho -e /'//nnameserver 8.8.8.8/nnameserver 114.114.114.114/n/' > /run/systemd/resolve/stub-resolv.conf/n/n/necho -e /'$(gettime)${GREEN}禁用无用检测${RES}/'/ntouch ~/.hushlogin/n/necho -e /'$(gettime)${GREEN}换源中${RES}/'/necho -e /'//n# Generated by distrobuilder/n##deb https://ports.ubuntu.com/ubuntu-ports focal main restricted universe multiverse/n##deb https://ports.ubuntu.com/ubuntu-ports focal-updates main restricted universe multiverse/n##deb https://ports.ubuntu.com/ubuntu-ports focal-security main restricted universe multiverse/n# deb https://mirrors.huaweicloud.com/ubuntu-ports/ focal-proposed main restricted universe multiverse/ndeb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal main restricted universe multiverse/ndeb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse/ndeb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse/ndeb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse/n/n/' > /etc/apt/sources.list/napt-get update/n/necho -e /'$(gettime)${GREEN}安装常用软件${RES}/'/nself_install whiptail apt/nself_install pv apt/nself_install wget apt/nself_install git apt/nself_install jq apt/nself_install curl apt/nself_install bc apt/nself_install language-pack-zh-hans apt/n/nrm -rf $0/nexit/n' > ${HOME}/.gancm/proot/${os_name}/root/优化.sh/n/necho -e /'$(gettime)${GREEN}吐槽:为什么非要用proot调用的解压才有用${RES}//n$(gettime)${YELLOW}还没有进度条${RES}/'/nproot --link2symlink -0 -r ${HOME}/.gancm/proot/${os_name}/ -b /dev -b ${HOME}/.gancm/proot/${os_name}/root:/dev/shm -w /root /usr/bin/env -i HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games TERM=xterm-256color LANG=zh_CN.UTF-8 /bin/bash 优化.sh/n /n}/n#主要逻辑/n########################################################/ncase ${1} in/n -h|--help)/n echo 1/n hcjx/n ;;/n *)/n /n case $(uname -o) in/n Android)/n validity/n variable/n self_install whiptail pkg/n self_install pv pkg/n self_install wget pkg/n self_install git pkg/n self_install jq pkg/n self_install curl pkg/n self_install bc pkg/n self_install language-pack-zh-hans pkg/n open=(/n whiptail --title /'选择功能/' --menu /'termux按自己需求来/' 15 60 4 ///n /'1/' /'proot/' ///n /'2/' /'待添加/' ///n /'0/' /'退出/' 3>&1 1>&2 2>&3/n )/n case $open in/n 1)/n open=(/n whiptail --title /'选择功能/' --menu /'termux按自己需求来/' 15 60 4 ///n /'1/' /'安装proot/' ///n /'2/' /'启动proot/' ///n /'3/' /'删除proot/' /// /n /'0/' /'退出/' 3>&1 1>&2 2>&3/n )/n case $open in/n 1)/n Download_proot_os/n ;;/n 2)/n start_proot/n ;;/n 3)/n echo -e /'$(gettime)${RED}Ctrl + C 终止删除 回车确定执行/'/n hcjx/n rm -rfv ${HOME}/.gancm/proot/${os_name}//n ;;/n 0)/n return 0/n ;;/n esac/n ;;/n esac/n ;;/n *)/n echo /'$(gettime)待添加/'/n ;;/n /n :;;/n /nesac/n/n
原文地址: https://www.cveoy.top/t/topic/pgF5 著作权归作者所有。请勿转载和采集!