OSDN Git Service

update master
authorzfuns <zfuns@qq.com>
Tue, 19 Oct 2021 23:25:00 +0000 (07:25 +0800)
committerzfuns <zfuns@qq.com>
Tue, 19 Oct 2021 23:25:00 +0000 (07:25 +0800)
atilo [new file with mode: 0755]

diff --git a/atilo b/atilo
new file mode 100755 (executable)
index 0000000..08b488c
--- /dev/null
+++ b/atilo
@@ -0,0 +1,342 @@
+#!/data/data/com.termux/files/usr/bin/bash
+#set -u -x -e
+INDIR="$HOME/.atilo"
+test ! -d $INDIR && mkdir $INDIR
+INED_LIST=(`ls ${INDIR}`)
+ARCH_LIST=('aarch64' 'armhf')
+LOCAL_ARCH=$(dpkg --print-architecture)
+LINUX_LIST=('alpine' 'aosc' 'arch' 'centos' 'debian' 'fedora' 'kali' 'opensuse' 'ubuntu' 'termux' 'parrot' 'backbox' 'void')
+
+tips() { printf " $@ \n";}
+warn() { printf "\033[1;33m $@ \033[0m\n";}
+error() { printf "[\033[1;31m $@ \033[0m]\n";}
+cutline(){ tips "******************************************";}
+
+###### 显示说明
+#apertis
+#alpine
+#ubuntu
+#debian
+#kali
+show_help(){
+cutline
+tips "atilo 0.19.5 (Bash Script) by http://funs.ml"
+tips "用法: atilo [选项] [参数]"
+tips ""
+tips "apertis\t\t| 安装apertis"
+tips "fedora \t\t| 安装fedora"
+tips "debian \t\t| 安装debian"
+tips "alpine \t\t| 安装alpine"
+tips "aosc   \t\t| 安装aosc"
+tips "arch   \t\t| 安装archlinux"
+tips "kali   \t\t| 安装kali"
+tips "void   \t\t| 安装voidlinux"
+tips "parrot \t\t| 安装parrot"
+tips "backbox\t\t| 安装backbox"
+tips "ubuntu \t\t| 安装ubuntu"
+tips "centos \t\t| 安装centos"
+tips "opensuse \t\t| 安装opensuse"
+#tips "termux \t\t| 安装termux"
+tips "run      \t\t| 运行一个linux"
+tips "rm     \t\t| 删除安装的linux"
+cutline
+exit 0
+}
+
+run_proot(){
+               cd $INDIR
+               unset LD_PRELOAD
+               #export PROOT_NO_SECCOMP=1
+        proot \
+        -l \
+        -0 \
+        -k \
+               "\\Linux\\${NAME}\\5.4-fake\#1\\${LOCAL_ARCH}\\localhost\\-1\\" \
+        -r ${NAME} \
+        -b /sdcard \
+        -b /dev \
+        -b /proc \
+        -b /sys \
+        -b /data/data/com.termux/files/home \
+        -w /root \
+        -b ${NAME}/tmp:/dev/shm \
+        -b ${NAME}/proc/.stat:/proc/stat \
+               -b ${NAME}/proc/.uptime:/proc/uptime \
+        /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=${TERM} \
+        /bin/su -l
+exit
+}
+###########################################
+
+############## 删除linux ###############j
+rm_linux(){
+       set +e
+       if echo "${LINUX_LIST[@]}" | grep -w "${1}" &>/dev/null;
+       then
+                       chmod -R 0755 ${INDIR}/${1} > /dev/null 2>&1;
+                       rm -rf ${INDIR}/${1} ${PREFIX}/bin/start${1} > /dev/null 2>&1;
+                       tips "删除${1}成功"; exit 0;
+       else 
+                       warn "! 输入错误"; exit 1;
+       fi
+}
+
+####################################
+
+is_installed(){
+               if echo "${INED_LIST[@]}" | grep -wq "$1";then true
+               else
+                               echo "未安装${1}"
+                               exit 1
+               fi
+}
+
+
+if [ $# = 0 ]; then show_help; fi
+sh=bash
+zip=pxvf
+
+get_arch(){
+               if [ $LOCAL_ARCH == "${ARCH_LIST[0]}" ];
+                               then ARCH="arm64"
+               elif [ ${LOCAL_ARCH} == "${ARCH_LIST[1]}" ];
+                               then ARCH="armhf"
+               else warn "! 未知架构 ${LOCAL_ARCH}\n只支持(aarch64,armhf)"
+               fi
+}
+
+get_durl(){ 
+               url="https://api.funs.ml/rootfs/?url=${NAME}_${LOCAL_ARCH}.tgz"
+}
+
+#######################################
+
+get_arch
+###### linux列表
+case "$1" in
+    apertis)
+               NAME=apertis; zip=pxJf;
+               mirrors=0
+               mirrorshost=0
+               mirrorspath=0;;
+    alpine) 
+               NAME=alpine; zip=pzxf; sh=ash;
+               mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="dl-cdn.alpinelinux.org"
+               mirrorspath="etc/apk/repositories";;
+       arch) 
+               NAME=arch; zip=pxzf;
+           mirrors="mirrors.bfsu.edu.cn\/archlinuxarm"
+               mirrorshost="mirror.archlinuxarm.org"
+           mirrorspath="etc/pacman.d/mirrorlist"
+           #attach="pacman-key --init;pacman-key --populate archlinuxarm;locale-gen"
+           attach="echo hello";;
+
+       centos) 
+               NAME=centos; zip=pxf;
+           mirrors=0 #"mirrors.tuna.tsinghua.edu.cn\/centos"
+               mirrorshost=0 #"mirrorlist.centos.org"
+               mirrorspath=0 #"etc/yum.repos.d/CentOS-Base.repo"
+           attach="echo ...";;
+
+       ubuntu) 
+               NAME=ubuntu; zip=pxJf;
+           mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="ports.ubuntu.com"
+           mirrorspath="etc/apt/sources.list"
+           #attach="apt update;apt install -y perl apt-utils dialog locales";;
+           attach="locale-gen zh_CN.UTF-8 && sed -i '/^LANG/c'LANG=zh_CN.UTF-8'' /etc/default/locale";;
+
+       fedora) 
+               NAME=fedora;
+               if [ ${LOCAL_ARCH} != "arm" ];then
+                               zip=pxf;
+               fi
+               mirrors=0;
+               mirrorshost=0
+               attach="dnf update";;
+
+       debian) 
+               NAME=debian; zip=pxf;
+           mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="deb.debian.org"
+           mirrorspath="etc/apt/sources.list"
+           attach="apt update;apt install -y perl apt-utils dialog locales";;
+       aosc) 
+               NAME=aosc; zip=pxf;
+           mirrors="mirrors.bfsu.edu.cn\/anthon"
+               mirrorshost="repo.aosc.io"
+               mirrorspath="etc/apt/sources.list"
+           attach="apt-gen-list m tuna;apt update;ln -s /usr/bin/perl5.24.3 /usr/bin/perl;dpkg --configure -a";;
+       backbox) 
+               NAME=backbox; zip=pxf
+               mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="ports.ubuntu.com"
+               mirrorspath="etc/apt/sources.list"
+               attach="apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 680E1A5A78A7ABE1;apt update;apt install -y apt-utils dialog";;
+       parrot) 
+               NAME=parrot; zip=pxf;
+               mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="ba.mirror.garr.it\/mirrors"
+               mirrorspath="etc/apt/sources.list"
+               attach="apt update";;
+
+       opensuse) 
+               NAME=opensuse; zip=pxf;
+           mirrors=0 ##"mirrors.tuna.tsinghua.edu.cn\/opensuse"
+               mirrorshost=0 ##"download.opensuse.org"
+               mirrorspath=0 ##"etc/zypp/repos.d/repo-update.repo"
+           attach="zypper up";;
+
+       kali) 
+               NAME=kali; zip=pxf;
+        mirrors="mirrors.bfsu.edu.cn"
+               mirrorshost="http.kali.org"
+               mirrorspath="etc/apt/sources.list"
+        attach="locale-gen zh_CN.UTF-8 && apt update && apt install apt-utils -y";;
+
+    void) 
+               NAME=void; zip=pxf;
+               mirrors="mirrors.bfsu.edu.cn\/voidlinux"
+               mirrorshost="alpha.de.repo.voidlinux.org"
+               mirrorspath="usr/share/xbps.d/*-repository-*.conf"
+               attach="echo ...";;
+       
+#      termux) NAME=termux; zip=pJx;
+#              mirrors="deb http://mirrors.tuna.tsinghua.edu.cn/termux/ stable main"
+#              mirrorshost=0
+#              mirrorspath="etc/apt/sources.list"
+#              attach="pkg up";;
+
+       rm) rm_linux $2;;
+       run) is_installed $2;NAME=$2;run_proot;;
+       *) warn "! 未知选项: '$1'";exit 1;
+esac
+#######################################
+
+############ 下载 ##############
+mkdir -p ${INDIR}/${NAME}
+cd ${INDIR}/${NAME}
+tips ""
+cutline
+get_durl
+
+if [ ! -f "${NAME}.tgz" ];then
+               touch ${NAME}.tgz
+               (curl -A funs -sfL ${url} -o ${NAME}.tgz) &
+               all_size=$(curl ${url} -sfLI |grep -i "Content-Length:" |awk -F "[Cc]ontent-[Ll]ength: " '{print $2}'|dos2unix)
+               if [ "$all_size" == '' ]; then
+                               tips "+ 下载错误 (请检查链接是否能正常访问)\n   ${url}"
+                               rm -rf ${INDIR}/$1
+                               cutline
+                               exit 1
+               fi
+               while [[ $all_size != $dow_size ]]
+               do 
+                               dow_size=$(wc -c ${NAME}.tgz |awk -F ' ' '{print $1}')
+                               echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"' + 下载根目录文件 ... '`echo "scale=2;${dow_size} / (${all_size} / 100)"|bc`'%'
+               done
+               echo -ne '\n\n'
+               wait
+else
+               tips "+ 跳过文件下载 ..."
+               tips ""
+fi
+#########################################
+
+
+############# 解压 ##############
+tips "+ 解压根目录文件 ..."
+tips ""
+if [ ${LOCAL_ARCH} == "arm" ];then
+  if [ ${NAME} == "fedora" ];then
+       tar xvf fedora.tgz --strip-components=1 --exclude json --exclude VERSION
+       tar xpf layer.tar
+       chmod +w .
+       rm layer.tar
+       rm fedora.tgz
+  fi
+fi
+if [ ${NAME} == "termux" ];then
+       unzip -q termux.tgz
+else
+       set +e
+       proot -0 -l tar ${zip} ${NAME}.tgz --exclude=dev
+       if [ "$?" != "0" ]; then
+               tips "+ 解压错误"
+               exit 0
+       fi
+fi
+###########################################
+
+
+########### 设置 DNS ##########
+tips "+ 设置DNS服务器 ..."
+tips ""
+rm -r ${INDIR}/${NAME}/etc/resolv.conf 2>/dev/null
+echo -e "nameserver 119.29.29.29\nnameserver 8.8.8.8" > ${INDIR}/${NAME}/etc/resolv.conf
+#echo "export USER=root" >> ~/${cmd}/etc/profile
+#echo "export LC_ALL=zh_CN.utf8" >> ~/${cmd}/etc/profile
+#echo "zh_CN.UTF-8 UTF-8" >> ~/${cmd}/etc/locale.gen
+#echo "export DISPLAY=127.0.0.1:0" >> ~/${cmd}/etc/profile
+#echo "export PULSE_SERVER=tcp:127.0.0.1:4712" >> ~/${cmd}/etc/profile
+#########################################
+proot -0 sed -i 's#root:.*#root:$6$9XNS6Hzz0bzrPIwm$whRSUOZ6o5dkSeORcBKup2YZUt7/Z4hhqDvJ6lG0o5ApmwfrP/3eObde6OLHfekjoheKWkVZ0ZNZ3H1.WcX/Z1:18549:0:99999:7:::#g' ${INDIR}/${NAME}/etc/shadow
+echo -e "pts/0\npts/1" >> ${INDIR}/${NAME}/etc/securetty 2>/dev/null
+chmod 700 ${INDIR}/${NAME}/proc/
+proot -0 echo '843422.42 3355754.32' > ${INDIR}/${NAME}/proc/.uptime
+proot -0 cat <<- EOF > ${INDIR}/${NAME}/proc/.stat
+cpu  1050008 127632 898432 43828767 37203 63 99244 0 0 0
+cpu0 212383 20476 204704 8389202 7253 42 12597 0 0 0
+cpu1 224452 24947 215570 8372502 8135 4 42768 0 0 0
+cpu2 222993 17440 200925 8424262 8069 9 17732 0 0 0
+cpu3 186835 8775 195974 8486330 5746 3 8360 0 0 0
+cpu4 107075 32886 48854 8688521 3995 4 5758 0 0 0
+cpu5 90733 20914 27798 1429573 2984 1 11419 0 0 0
+intr 53261351 0 686 1 0 0 1 12 31 1 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7818 0 0 0 0 0 0 0 0 255 33 1912 33 0 0 0 0 0 0 3449534 2315885 2150546 2399277 696281 339300 22642 19371 0 0 0 0 0 0 0 0 0 0 0 2199 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2445 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 162240 14293 2858 0 151709 151592 0 0 0 284534 0 0 0 0 0 0 0 0 0 0 0 0 0 0 185353 0 0 938962 0 0 0 0 736100 0 0 1 1209 27960 0 0 0 0 0 0 0 0 303 115968 452839 2 0 0 0 0 0 0 0 0 0 0 0 0 0 160361 8835 86413 1292 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3592 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6091 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 35667 0 0 156823 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 138 2667417 0 41 4008 952 16633 533480 0 0 0 0 0 0 262506 0 0 0 0 0 0 126 0 0 1558488 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 8 0 0 6 0 0 0 10 3 4 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 1 1 83806 0 1 1 0 1 0 1 1 319686 2 8 0 0 0 0 0 0 0 0 0 244534 0 1 10 9 0 10 112 107 40 221 0 0 0 144
+ctxt 90182396
+btime 1595203295
+processes 270853
+procs_running 2
+procs_blocked 0
+softirq 25293348 2883 7658936 40779 539155 497187 2864 1908702 7229194 279723 7133925
+EOF
+chmod +rw ${INDIR}/${NAME}/etc/passwd
+chmod +rw ${INDIR}/${NAME}/etc/shadow
+chmod +rw ${INDIR}/${NAME}/etc/group
+echo "aid_$(id -un):x:$(id -u):$(id -g):Android user:/:/usr/sbin/nologin" >> ${INDIR}/${NAME}/etc/passwd
+echo "aid_$(id -un):*:18446:0:99999:7:::" >> ${INDIR}/${NAME}/etc/shadow
+for g in $(id -G); do
+               echo "aid_$(id -gn "$g"):x:${g}:root,aid_$(id -un)" >> ${INDIR}/${NAME}/etc/group
+        if [ -f "${HOME}/${NAME}/etc/gshadow" ]; then
+                               chmod +rw ${INDIR}/${NAME}/etc/gshadow
+                               echo "aid_$(id -gn "$g"):*::root,aid_$(id -un)" >> ${INDIR}/${NAME}/etc/gshadow
+        fi
+done
+
+############# 修改源 ##########
+set -e
+ch_mirrors(){
+#      echo -e "$mirrors" > "$mirrorspath"
+       sed -i "s/${mirrorshost}/${mirrors}/" $mirrorspath
+       tips "+ 修改软件源 ...     "
+}
+if [ "$mirrors" != "0" ]; then "ch_mirrors"; fi
+################################
+#tips "+ 修复系统 ... "
+#cutline
+#tips ""
+#start${cmd} ${attach} #> /dev/null 2>&1
+tips ""
+
+############ 全部完成 ################
+tips "+ 安装完成"
+cutline
+tips "+ 启动${NAME}的命令\033[1;33m atilo run ${NAME}\033[0m"
+tips "+ 默认账号:root 密码:root"
+cutline
+tips ""
+#######################################