-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-ubuntu20.sh
287 lines (271 loc) · 9.72 KB
/
install-ubuntu20.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/data/data/com.termux/files/usr/bin/bash
pkg install wget -y
folder=ubuntu20-fs
cur=`pwd`
if [ -d "$folder" ]; then
first=1
echo "skipping downloading"
fi
tarball="ubuntu20-rootfs.tar.gz"
termux-setup-storage
if [ "$first" != 1 ];then
if [ ! -f $tarball ]; then
echo "Download Rootfs, this may take a while base on your internet speed."
case `dpkg --print-architecture` in
aarch64)
archurl="arm64" ;;
arm)
archurl="armhf" ;;
amd64)
archurl="amd64" ;;
x86_64)
archurl="amd64" ;;
*)
echo "unknown architecture"; exit 1 ;;
esac
wget "https://github.com/AndronixApp/AndronixOrigin/raw/master/Rootfs/Ubuntu20/focal-${archurl}.tar.gz" -O $tarball
fi
mkdir -p "$folder"
cd "$folder"
echo "Decompressing Rootfs, please be patient."
proot --link2symlink tar -xf ${cur}/${tarball} --exclude=dev||:
cd "$cur"
fi
mkdir -p ubuntu20-binds
mkdir -p ${folder}/proc/fakethings
if [ ! -f "${cur}/${folder}/proc/fakethings/stat" ]; then
cat <<- EOF > "${cur}/${folder}/proc/fakethings/stat"
cpu 5502487 1417100 4379831 62829678 354709 539972 363929 0 0 0
cpu0 611411 171363 667442 7404799 61301 253898 205544 0 0 0
cpu1 660993 192673 571402 7853047 39647 49434 29179 0 0 0
cpu2 666965 186509 576296 7853110 39012 48973 26407 0 0 0
cpu3 657630 183343 573805 7863627 38895 48768 26636 0 0 0
cpu4 620516 161440 594973 7899146 39438 47605 26467 0 0 0
cpu5 610849 155665 594684 7912479 40258 46870 26044 0 0 0
cpu6 857685 92294 387182 8096756 46609 22110 12364 0 0 0
cpu7 816434 273809 414043 7946709 49546 22311 11284 0 0 0
intr 601715486 0 0 0 0 70612466 0 2949552 0 93228 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12862684 625329 10382717 16209 55315 8510 0 0 0 0 11 11 13 270 192 40694 95 7 0 0 0 36850 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 286 6378 0 0 0 54 0 3239423 2575191 82725 0 0 127 0 0 0 1791277 850609 20 9076504 0 301 0 0 0 0 0 3834621 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 806645 0 0 0 0 0 7243 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2445850 52 1783 0 0 5091520 0 0 0 3 0 0 0 0 0 5475 0 198001 0 2 42 1289224 0 2 202483 4 0 8390 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3563336 4202122 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 17948 0 0 612 0 0 0 0 2103 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 11 11 12 0 12 0 52 752 0 0 0 0 0 0 0 743 0 14 0 0 12 0 0 1863 229 0 464 0 0 0 0 0 0 8588 97 7236426 92766 622 31 0 0 0 18 4 4 0 5 0 0 116013 7 0 0 752406
ctxt 826091808
btime 1611513513
processes 288493
procs_running 1
procs_blocked 0
softirq 175407567 14659158 51739474 28359 5901272 8879590 0 11988166 46104015 0 36107533
EOF
fi
if [ ! -f "${cur}/${folder}/proc/fakethings/version" ]; then
cat <<- EOF > "${cur}/${folder}/proc/fakethings/version"
Linux version 5.4.0-faked (andronix@fakeandroid) (gcc version 4.9.x (Andronix fake /proc/version) ) #1 SMP PREEMPT Sun Sep 13 00:00:00 IST 2020
EOF
fi
if [ ! -f "${cur}/${folder}/proc/fakethings/vmstat" ]; then
cat <<- EOF > "${cur}/${folder}/proc/fakethings/vmstat"
nr_free_pages 15717
nr_zone_inactive_anon 87325
nr_zone_active_anon 259521
nr_zone_inactive_file 95508
nr_zone_active_file 57839
nr_zone_unevictable 58867
nr_zone_write_pending 0
nr_mlock 58867
nr_page_table_pages 24569
nr_kernel_stack 49552
nr_bounce 0
nr_zspages 80896
nr_free_cma 0
nr_inactive_anon 87325
nr_active_anon 259521
nr_inactive_file 95508
nr_active_file 57839
nr_unevictable 58867
nr_slab_reclaimable 17709
nr_slab_unreclaimable 47418
nr_isolated_anon 0
nr_isolated_file 0
workingset_refault 33002180
workingset_activate 5498395
workingset_restore 2354202
workingset_nodereclaim 140006
nr_anon_pages 344014
nr_mapped 193745
nr_file_pages 218441
nr_dirty 0
nr_writeback 0
nr_writeback_temp 0
nr_shmem 1880
nr_shmem_hugepages 0
nr_shmem_pmdmapped 0
nr_anon_transparent_hugepages 0
nr_unstable 0
nr_vmscan_write 8904094
nr_vmscan_immediate_reclaim 139732
nr_dirtied 8470080
nr_written 16835370
nr_indirectly_reclaimable 8273152
nr_unreclaimable_pages 130861
nr_dirty_threshold 31217
nr_dirty_background_threshold 15589
pgpgin 198399484
pgpgout 31742368
pgpgoutclean 45542744
pswpin 3843200
pswpout 8903884
pgalloc_dma 192884869
pgalloc_normal 190990320
pgalloc_movable 0
allocstall_dma 0
allocstall_normal 3197
allocstall_movable 1493
pgskip_dma 0
pgskip_normal 0
pgskip_movable 0
pgfree 384653565
pgactivate 34249517
pgdeactivate 44271435
pglazyfree 192
pgfault 46133667
pgmajfault 5568301
pglazyfreed 0
pgrefill 55909145
pgsteal_kswapd 58467386
pgsteal_direct 255950
pgscan_kswapd 86628315
pgscan_direct 415889
pgscan_direct_throttle 0
pginodesteal 18
slabs_scanned 31242197
kswapd_inodesteal 1238474
kswapd_low_wmark_hit_quickly 11637
kswapd_high_wmark_hit_quickly 5411
pageoutrun 32167
pgrotated 213328
drop_pagecache 0
drop_slab 0
oom_kill 0
pgmigrate_success 729722
pgmigrate_fail 450
compact_migrate_scanned 43510584
compact_free_scanned 248175096
compact_isolated 1494774
compact_stall 6
compact_fail 3
compact_success 3
compact_daemon_wake 9438
compact_daemon_migrate_scanned 43502436
compact_daemon_free_scanned 248107303
unevictable_pgs_culled 66418
unevictable_pgs_scanned 0
unevictable_pgs_rescued 8484
unevictable_pgs_mlocked 78830
unevictable_pgs_munlocked 8508
unevictable_pgs_cleared 11455
unevictable_pgs_stranded 11455
swap_ra 0
swap_ra_hit 7
speculative_pgfault 221449963
EOF
fi
echo "Seeking for external storage (SD cards or USB hard drives)..."
EXTERNAL_FOLDER=$(find /storage -maxdepth 1 -type d | grep -E "/storage/[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$")
SEARCH_METHOD="UUID mechanism"
if [ -z "$EXTERNAL_FOLDER" ]
then
EXTERNAL_FOLDER=$(find /storage -maxdepth 1 -type d | grep -E "/storage/[A-Za-z0-9]{4}-[A-Za-z0-9]{4}$")
SEARCH_METHOD="Shorter UID (for FAT, exFAT and NTFS filesystems that do not support UUID)"
fi
if [ -z "$EXTERNAL_FOLDER" ]
then
EXTERNAL_FOLDER=$(mount | grep /mnt/media_rw | cut -d ' ' -f 3)
SEARCH_METHOD="Mounting point path"
fi
if [ -z "$EXTERNAL_FOLDER" ]
then
echo "The external drive is not where it was intended to be."
echo "Seeking for external drive on the whole system. Be sure to have a file named \"external-hook\" in your drive. Operation can take few minutes..."
EXTERNAL_FOLDER=$(find / -type f -name "external-hook" 2>/dev/null | sed 's@/external-hook@@g')
SEARCH_METHOD="Searching for \"external-hook\" file in whole system"
fi
if [ -z "$EXTERNAL_FOLDER" ]
then
echo "Can't find external drive."
exit 1
else
echo "External drive searching method: $SEARCH_METHOD"
echo "External drive path: $EXTERNAL_FOLDER"
fi
sleep 5
bin=start-ubuntu20.sh
echo "Writing launch script"
cat > $bin <<- EOM
#!/bin/bash
cd \$(dirname \$0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
command+=" --kill-on-exit"
command+=" --link2symlink"
command+=" -0"
command+=" -r $folder"
if [ -n "\$(ls -A ubuntu20-binds)" ]; then
for f in ubuntu20-binds/* ;do
. \$f
done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b /sys"
command+=" -b /data"
command+=" -b ubuntu20-fs/root:/dev/shm"
command+=" -b /proc/self/fd/2:/dev/stderr"
command+=" -b /proc/self/fd/1:/dev/stdout"
command+=" -b /proc/self/fd/0:/dev/stdin"
command+=" -b /dev/urandom:/dev/random"
command+=" -b /proc/self/fd:/dev/fd"
command+=" -b ${cur}/${folder}/proc/fakethings/stat:/proc/stat"
command+=" -b ${cur}/${folder}/proc/fakethings/vmstat:/proc/vmstat"
command+=" -b ${cur}/${folder}/proc/fakethings/version:/proc/version"
## uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home:/root"
command+=" -b ${EXTERNAL_FOLDER}:/external-storage"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" MOZ_FAKE_NO_SANDBOX=1"
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=C.UTF-8"
command+=" /bin/bash --login"
com="\$@"
if [ -z "\$1" ];then
exec \$command
else
\$command -c "\$com"
fi
EOM
mkdir -p ubuntu20-fs/var/tmp
rm -rf ubuntu20-fs/usr/local/bin/*
wget -q https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Rootfs/Ubuntu19/.profile -O ubuntu20-fs/root/.profile.1
cat $folder/root/.profile.1 >> $folder/root/.profile && rm -rf $folder/root/.profile.1
wget -q https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Rootfs/Ubuntu19/vnc -P ubuntu20-fs/usr/local/bin
wget -q https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Rootfs/Ubuntu19/vncpasswd -P ubuntu20-fs/usr/local/bin
wget -q https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Rootfs/Ubuntu19/vncserver-stop -P ubuntu20-fs/usr/local/bin
wget -q https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Rootfs/Ubuntu19/vncserver-start -P ubuntu20-fs/usr/local/bin
chmod +x ubuntu20-fs/root/.bash_profile
chmod +x ubuntu20-fs/root/.profile
chmod +x ubuntu20-fs/usr/local/bin/vnc
chmod +x ubuntu20-fs/usr/local/bin/vncpasswd
chmod +x ubuntu20-fs/usr/local/bin/vncserver-start
chmod +x ubuntu20-fs/usr/local/bin/vncserver-stop
touch $folder/root/.hushlogin
echo "127.0.0.1 localhost localhost" > $folder/etc/hosts
echo "nameserver 1.1.1.1" > $folder/etc/resolv.conf
chmod +x $folder/etc/resolv.conf
echo "fixing shebang of $bin"
termux-fix-shebang $bin
echo "making $bin executable"
chmod +x $bin
echo "removing image for some space"
rm $tarball
clear
echo "You can now launch Ubuntu with the ./${bin} script form next time"
sudo bash $bin