OSDN Git Service

update
[atilo/atilo.git] / atilo
1 #!/data/data/com.termux/files/usr/bin/bash
2 #set -u -x -e
3 INDIR="$HOME/.atilo"
4 test ! -d $INDIR && mkdir $INDIR
5 INED_LIST=(`ls ${INDIR}`)
6 ARCH_LIST=('aarch64' 'armhf')
7 LOCAL_ARCH=$(dpkg --print-architecture)
8 LINUX_LIST=('alpine' 'aosc' 'arch' 'centos' 'debian' 'fedora' 'kali' 'opensuse' 'ubuntu' 'termux' 'parrot' 'backbox' 'void')
9
10 tips() { printf " $@ \n";}
11 warn() { printf "\033[1;33m $@ \033[0m\n";}
12 error() { printf "[\033[1;31m $@ \033[0m]\n";}
13 cutline(){ tips "******************************************";}
14
15 ###### 显示说明
16 #apertis
17 #alpine
18 #ubuntu
19 #debian
20 #kali
21 show_help(){
22 cutline
23 tips "atilo 0.19.5 (Bash Script) by http://funs.ml"
24 tips "用法: atilo [选项] [参数]"
25 tips ""
26 tips "apertis\t\t| 安装apertis"
27 tips "fedora \t\t| 安装fedora"
28 tips "debian \t\t| 安装debian"
29 tips "alpine \t\t| 安装alpine"
30 tips "aosc   \t\t| 安装aosc"
31 tips "arch   \t\t| 安装archlinux"
32 tips "kali   \t\t| 安装kali"
33 tips "void   \t\t| 安装voidlinux"
34 tips "parrot \t\t| 安装parrot"
35 tips "backbox\t\t| 安装backbox"
36 tips "ubuntu \t\t| 安装ubuntu"
37 tips "centos \t\t| 安装centos"
38 tips "opensuse \t\t| 安装opensuse"
39 #tips "termux \t\t| 安装termux"
40 tips "run       \t\t| 运行一个linux"
41 tips "rm     \t\t| 删除安装的linux"
42 cutline
43 exit 0
44 }
45
46 run_proot(){
47                 cd $INDIR
48                 unset LD_PRELOAD
49                 #export PROOT_NO_SECCOMP=1
50         proot \
51         -l \
52         -0 \
53         -k \
54                 "\\Linux\\${NAME}\\5.4-fake\#1\\${LOCAL_ARCH}\\localhost\\-1\\" \
55         -r ${NAME} \
56         -b /sdcard \
57         -b /dev \
58         -b /proc \
59         -b /sys \
60         -b /data/data/com.termux/files/home \
61         -w /root \
62         -b ${NAME}/tmp:/dev/shm \
63         -b ${NAME}/proc/.stat:/proc/stat \
64                 -b ${NAME}/proc/.uptime:/proc/uptime \
65         /usr/bin/env -i \
66         HOME=/root \
67         PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games \
68         TERM=${TERM} \
69         /bin/su -l
70 exit
71 }
72 ###########################################
73
74 ############## 删除linux ###############j
75 rm_linux(){
76         set +e
77         if echo "${LINUX_LIST[@]}" | grep -w "${1}" &>/dev/null;
78         then
79                         chmod -R 0755 ${INDIR}/${1} > /dev/null 2>&1;
80                         rm -rf ${INDIR}/${1} ${PREFIX}/bin/start${1} > /dev/null 2>&1;
81                         tips "删除${1}成功"; exit 0;
82         else 
83                         warn "! 输入错误"; exit 1;
84         fi
85 }
86
87 ####################################
88
89 is_installed(){
90                 if echo "${INED_LIST[@]}" | grep -wq "$1";then true
91                 else
92                                 echo "未安装${1}"
93                                 exit 1
94                 fi
95 }
96
97
98 if [ $# = 0 ]; then show_help; fi
99 sh=bash
100 zip=pxvf
101
102 get_arch(){
103                 if [ $LOCAL_ARCH == "${ARCH_LIST[0]}" ];
104                                 then ARCH="arm64"
105                 elif [ ${LOCAL_ARCH} == "${ARCH_LIST[1]}" ];
106                                 then ARCH="armhf"
107                 else warn "! 未知架构 ${LOCAL_ARCH}\n只支持(aarch64,armhf)"
108                 fi
109 }
110
111 get_durl(){ 
112                 url="https://api.funs.ml/rootfs/?url=${NAME}_${LOCAL_ARCH}.tgz"
113 }
114
115 #######################################
116
117 get_arch
118 ###### linux列表
119 case "$1" in
120     apertis)
121                 NAME=apertis; zip=pxJf;
122                 mirrors=0
123                 mirrorshost=0
124                 mirrorspath=0;;
125     alpine) 
126                 NAME=alpine; zip=pzxf; sh=ash;
127                 mirrors="mirrors.bfsu.edu.cn"
128                 mirrorshost="dl-cdn.alpinelinux.org"
129                 mirrorspath="etc/apk/repositories";;
130         arch) 
131                 NAME=arch; zip=pxzf;
132             mirrors="mirrors.bfsu.edu.cn\/archlinuxarm"
133                 mirrorshost="mirror.archlinuxarm.org"
134             mirrorspath="etc/pacman.d/mirrorlist"
135             #attach="pacman-key --init;pacman-key --populate archlinuxarm;locale-gen"
136             attach="echo hello";;
137
138         centos) 
139                 NAME=centos; zip=pxf;
140             mirrors=0 #"mirrors.tuna.tsinghua.edu.cn\/centos"
141                 mirrorshost=0 #"mirrorlist.centos.org"
142                 mirrorspath=0 #"etc/yum.repos.d/CentOS-Base.repo"
143             attach="echo ...";;
144
145         ubuntu) 
146                 NAME=ubuntu; zip=pxJf;
147             mirrors="mirrors.bfsu.edu.cn"
148                 mirrorshost="ports.ubuntu.com"
149             mirrorspath="etc/apt/sources.list"
150             #attach="apt update;apt install -y perl apt-utils dialog locales";;
151             attach="locale-gen zh_CN.UTF-8 && sed -i '/^LANG/c'LANG=zh_CN.UTF-8'' /etc/default/locale";;
152
153         fedora) 
154                 NAME=fedora;
155                 if [ ${LOCAL_ARCH} != "arm" ];then
156                                 zip=pxf;
157                 fi
158                 mirrors=0;
159                 mirrorshost=0
160                 attach="dnf update";;
161
162         debian) 
163                 NAME=debian; zip=pxf;
164             mirrors="mirrors.bfsu.edu.cn"
165                 mirrorshost="deb.debian.org"
166             mirrorspath="etc/apt/sources.list"
167             attach="apt update;apt install -y perl apt-utils dialog locales";;
168         aosc) 
169                 NAME=aosc; zip=pxf;
170             mirrors="mirrors.bfsu.edu.cn\/anthon"
171                 mirrorshost="repo.aosc.io"
172                 mirrorspath="etc/apt/sources.list"
173             attach="apt-gen-list m tuna;apt update;ln -s /usr/bin/perl5.24.3 /usr/bin/perl;dpkg --configure -a";;
174         backbox) 
175                 NAME=backbox; zip=pxf
176                 mirrors="mirrors.bfsu.edu.cn"
177                 mirrorshost="ports.ubuntu.com"
178                 mirrorspath="etc/apt/sources.list"
179                 attach="apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 680E1A5A78A7ABE1;apt update;apt install -y apt-utils dialog";;
180         parrot) 
181                 NAME=parrot; zip=pxf;
182                 mirrors="mirrors.bfsu.edu.cn"
183                 mirrorshost="ba.mirror.garr.it\/mirrors"
184                 mirrorspath="etc/apt/sources.list"
185                 attach="apt update";;
186
187         opensuse) 
188                 NAME=opensuse; zip=pxf;
189             mirrors=0 ##"mirrors.tuna.tsinghua.edu.cn\/opensuse"
190                 mirrorshost=0 ##"download.opensuse.org"
191                 mirrorspath=0 ##"etc/zypp/repos.d/repo-update.repo"
192             attach="zypper up";;
193
194         kali) 
195                 NAME=kali; zip=pxf;
196         mirrors="mirrors.bfsu.edu.cn"
197                 mirrorshost="http.kali.org"
198                 mirrorspath="etc/apt/sources.list"
199         attach="locale-gen zh_CN.UTF-8 && apt update && apt install apt-utils -y";;
200
201     void) 
202                 NAME=void; zip=pxf;
203                 mirrors="mirrors.bfsu.edu.cn\/voidlinux"
204                 mirrorshost="alpha.de.repo.voidlinux.org"
205                 mirrorspath="usr/share/xbps.d/*-repository-*.conf"
206                 attach="echo ...";;
207         
208 #       termux) NAME=termux; zip=pJx;
209 #               mirrors="deb http://mirrors.tuna.tsinghua.edu.cn/termux/ stable main"
210 #               mirrorshost=0
211 #               mirrorspath="etc/apt/sources.list"
212 #               attach="pkg up";;
213
214         rm) rm_linux $2;;
215         run) is_installed $2;NAME=$2;run_proot;;
216         *) warn "! 未知选项: '$1'";exit 1;
217 esac
218 #######################################
219
220 ############ 下载 ##############
221 mkdir -p ${INDIR}/${NAME}
222 cd ${INDIR}/${NAME}
223 tips ""
224 cutline
225 get_durl
226
227 if [ ! -f "${NAME}.tgz" ];then
228                 touch ${NAME}.tgz
229                 (curl -A funs -sfL ${url} -o ${NAME}.tgz) &
230                 all_size=$(curl ${url} -sfLI |grep -i "Content-Length:" |awk -F "[Cc]ontent-[Ll]ength: " '{print $2}'|dos2unix)
231                 if [ "$all_size" == '' ]; then
232                                 tips "+ 下载错误 (请检查链接是否能正常访问)\n   ${url}"
233                                 rm -rf ${INDIR}/$1
234                                 cutline
235                                 exit 1
236                 fi
237                 while [[ $all_size != $dow_size ]]
238                 do 
239                                 dow_size=$(wc -c ${NAME}.tgz |awk -F ' ' '{print $1}')
240                                 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`'%'
241                 done
242                 echo -ne '\n\n'
243                 wait
244 else
245                 tips "+ 跳过文件下载 ..."
246                 tips ""
247 fi
248 #########################################
249
250
251 ############# 解压 ##############
252 tips "+ 解压根目录文件 ..."
253 tips ""
254 if [ ${LOCAL_ARCH} == "arm" ];then
255   if [ ${NAME} == "fedora" ];then
256         tar xvf fedora.tgz --strip-components=1 --exclude json --exclude VERSION
257         tar xpf layer.tar
258         chmod +w .
259         rm layer.tar
260         rm fedora.tgz
261   fi
262 fi
263 if [ ${NAME} == "termux" ];then
264         unzip -q termux.tgz
265 else
266         set +e
267         proot -0 -l tar ${zip} ${NAME}.tgz --exclude=dev
268         if [ "$?" != "0" ]; then
269                 tips "+ 解压错误"
270                 exit 0
271         fi
272 fi
273 ###########################################
274
275
276 ########### 设置 DNS ##########
277 tips "+ 设置DNS服务器 ..."
278 tips ""
279 rm -r ${INDIR}/${NAME}/etc/resolv.conf 2>/dev/null
280 echo -e "nameserver 119.29.29.29\nnameserver 8.8.8.8" > ${INDIR}/${NAME}/etc/resolv.conf
281 #echo "export USER=root" >> ~/${cmd}/etc/profile
282 #echo "export LC_ALL=zh_CN.utf8" >> ~/${cmd}/etc/profile
283 #echo "zh_CN.UTF-8 UTF-8" >> ~/${cmd}/etc/locale.gen
284 #echo "export DISPLAY=127.0.0.1:0" >> ~/${cmd}/etc/profile
285 #echo "export PULSE_SERVER=tcp:127.0.0.1:4712" >> ~/${cmd}/etc/profile
286 #########################################
287 proot -0 sed -i 's#root:.*#root:$6$9XNS6Hzz0bzrPIwm$whRSUOZ6o5dkSeORcBKup2YZUt7/Z4hhqDvJ6lG0o5ApmwfrP/3eObde6OLHfekjoheKWkVZ0ZNZ3H1.WcX/Z1:18549:0:99999:7:::#g' ${INDIR}/${NAME}/etc/shadow
288 echo -e "pts/0\npts/1" >> ${INDIR}/${NAME}/etc/securetty 2>/dev/null
289 chmod 700 ${INDIR}/${NAME}/proc/
290 proot -0 echo '843422.42 3355754.32' > ${INDIR}/${NAME}/proc/.uptime
291 proot -0 cat <<- EOF > ${INDIR}/${NAME}/proc/.stat
292 cpu  1050008 127632 898432 43828767 37203 63 99244 0 0 0
293 cpu0 212383 20476 204704 8389202 7253 42 12597 0 0 0
294 cpu1 224452 24947 215570 8372502 8135 4 42768 0 0 0
295 cpu2 222993 17440 200925 8424262 8069 9 17732 0 0 0
296 cpu3 186835 8775 195974 8486330 5746 3 8360 0 0 0
297 cpu4 107075 32886 48854 8688521 3995 4 5758 0 0 0
298 cpu5 90733 20914 27798 1429573 2984 1 11419 0 0 0
299 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
300 ctxt 90182396
301 btime 1595203295
302 processes 270853
303 procs_running 2
304 procs_blocked 0
305 softirq 25293348 2883 7658936 40779 539155 497187 2864 1908702 7229194 279723 7133925
306 EOF
307 chmod +rw ${INDIR}/${NAME}/etc/passwd
308 chmod +rw ${INDIR}/${NAME}/etc/shadow
309 chmod +rw ${INDIR}/${NAME}/etc/group
310 echo "aid_$(id -un):x:$(id -u):$(id -g):Android user:/:/usr/sbin/nologin" >> ${INDIR}/${NAME}/etc/passwd
311 echo "aid_$(id -un):*:18446:0:99999:7:::" >> ${INDIR}/${NAME}/etc/shadow
312 for g in $(id -G); do
313                 echo "aid_$(id -gn "$g"):x:${g}:root,aid_$(id -un)" >> ${INDIR}/${NAME}/etc/group
314         if [ -f "${HOME}/${NAME}/etc/gshadow" ]; then
315                                 chmod +rw ${INDIR}/${NAME}/etc/gshadow
316                                 echo "aid_$(id -gn "$g"):*::root,aid_$(id -un)" >> ${INDIR}/${NAME}/etc/gshadow
317         fi
318 done
319
320 ############# 修改源 ##########
321 set -e
322 ch_mirrors(){
323 #       echo -e "$mirrors" > "$mirrorspath"
324         sed -i "s/${mirrorshost}/${mirrors}/" $mirrorspath
325         tips "+ 修改软件源 ...     "
326 }
327 if [ "$mirrors" != "0" ]; then "ch_mirrors"; fi
328 ################################
329 #tips "+ 修复系统 ... "
330 #cutline
331 #tips ""
332 #start${cmd} ${attach} #> /dev/null 2>&1
333 tips ""
334
335 ############ 全部完成 ################
336 tips "+ 安装完成"
337 cutline
338 tips "+ 启动${NAME}的命令\033[1;33m atilo run ${NAME}\033[0m"
339 tips "+ 默认账号:root 密码:root"
340 cutline
341 tips ""
342 #######################################