This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
/
ubuntu.sh
executable file
·86 lines (86 loc) · 2.78 KB
/
ubuntu.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
#!/data/data/com.termux/files/usr/bin/bash
folder=ubuntu-fs
if [ -d "$folder" ]; then
first=1
echo "skipping downloading"
fi
if [ "$first" != 1 ];then
if [ ! -f "ubuntu.tar.gz" ]; then
echo "downloading ubuntu-image"
if [ "$(dpkg --print-architecture)" = "aarch64" ];then
wget https://partner-images.canonical.com/core/artful/current/ubuntu-artful-core-cloudimg-arm64-root.tar.gz -O ubuntu.tar.gz
elif [ "$(dpkg --print-architecture)" = "arm" ];then
wget https://partner-images.canonical.com/core/artful/current/ubuntu-artful-core-cloudimg-armhf-root.tar.gz -O ubuntu.tar.gz
elif [ "$(dpkg --print-architecture)" = "i686" ];then
wget https://partner-images.canonical.com/core/artful/current/ubuntu-artful-core-cloudimg-i386-root.tar.gz -O ubuntu.tar.gz
elif [ "$(dpkg --print-architecture)" = "i386" ];then
wget https://partner-images.canonical.com/core/artful/current/ubuntu-artful-core-cloudimg-i386-root.tar.gz -O ubuntu.tar.gz
else
echo "unknown architecture"
exit 1
fi
fi
cur=`pwd`
mkdir -p $folder
cd $folder
echo "decompressing ubuntu image"
proot --link2symlink tar -xf $cur/ubuntu.tar.gz --exclude='dev'||:
echo "fixing nameserver, otherwise it can't connect to the internet"
echo "nameserver 8.8.8.8" > etc/resolv.conf
stubs=()
stubs+=('usr/sbin/groupadd')
stubs+=('usr/sbin/groupdel')
stubs+=('usr/bin/groups')
stubs+=('usr/sbin/useradd')
stubs+=('usr/sbin/usermod')
stubs+=('usr/sbin/userdel')
stubs+=('usr/bin/chage')
stubs+=('usr/bin/mesg')
for f in ${stubs[@]};do
echo "Writing stub: $f"
echo -e "#!/bin/sh\nexit" > "$f"
done
cd $cur
fi
mkdir -p binds
bin=start.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+=" --link2symlink"
command+=" -0"
command+=" -r $folder"
if [ -n "\$(ls -A binds)" ]; then
for f in binds/* ;do
. \$f
done
fi
command+=" -b /system"
command+=" -b /dev/"
command+=" -b /sys/"
command+=" -b /proc/"
#uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home"
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=\$LANG"
command+=" /bin/bash --login"
com="\$@"
if [ -z "\$1" ];then
exec \$command
else
\$command -c "\$com"
fi
EOM
echo "fixing shebang of $bin"
termux-fix-shebang $bin
echo "making $bin executable"
chmod +x $bin
echo "You can now launch Ubuntu with the ./start.sh script"