Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Neo-Oli
GitHub Repository: Neo-Oli/termux-ubuntu
Path: blob/master/ubuntu.sh
144 views
1
#!/data/data/com.termux/files/usr/bin/bash
2
folder=ubuntu-fs
3
if [ -d "$folder" ]; then
4
first=1
5
echo "skipping downloading"
6
fi
7
tarball="ubuntu.tar.gz"
8
if [ "$first" != 1 ];then
9
if [ ! -f $tarball ]; then
10
echo "downloading ubuntu-image"
11
case `dpkg --print-architecture` in
12
aarch64)
13
archurl="arm64" ;;
14
arm)
15
archurl="armhf" ;;
16
amd64)
17
archurl="amd64" ;;
18
i*86)
19
archurl="i386" ;;
20
x86_64)
21
archurl="amd64" ;;
22
*)
23
echo "unknown architecture"; exit 1 ;;
24
esac
25
wget "https://partner-images.canonical.com/core/disco/current/ubuntu-disco-core-cloudimg-${archurl}-root.tar.gz" -O $tarball
26
fi
27
cur=`pwd`
28
mkdir -p "$folder"
29
cd "$folder"
30
echo "decompressing ubuntu image"
31
proot --link2symlink tar -xf ${cur}/${tarball} --exclude='dev'||:
32
echo "fixing nameserver, otherwise it can't connect to the internet"
33
echo "nameserver 1.1.1.1" > etc/resolv.conf
34
cd "$cur"
35
fi
36
mkdir -p binds
37
bin=start-ubuntu.sh
38
echo "writing launch script"
39
cat > $bin <<- EOM
40
#!/bin/bash
41
cd \$(dirname \$0)
42
## unset LD_PRELOAD in case termux-exec is installed
43
unset LD_PRELOAD
44
command="proot"
45
command+=" --link2symlink"
46
command+=" -0"
47
command+=" -r $folder"
48
if [ -n "\$(ls -A binds)" ]; then
49
for f in binds/* ;do
50
. \$f
51
done
52
fi
53
command+=" -b /dev"
54
command+=" -b /proc"
55
## uncomment the following line to have access to the home directory of termux
56
#command+=" -b /data/data/com.termux/files/home:/root"
57
## uncomment the following line to mount /sdcard directly to /
58
#command+=" -b /sdcard"
59
command+=" -w /root"
60
command+=" /usr/bin/env -i"
61
command+=" HOME=/root"
62
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
63
command+=" TERM=\$TERM"
64
command+=" LANG=C.UTF-8"
65
command+=" /bin/bash --login"
66
com="\$@"
67
if [ -z "\$1" ];then
68
exec \$command
69
else
70
\$command -c "\$com"
71
fi
72
EOM
73
74
echo "fixing shebang of $bin"
75
termux-fix-shebang $bin
76
echo "making $bin executable"
77
chmod +x $bin
78
echo "You can now launch Ubuntu with the ./${bin} script"
79
80