-
Notifications
You must be signed in to change notification settings - Fork 36
/
install.sh
executable file
·202 lines (145 loc) · 5.11 KB
/
install.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
#!/data/data/com.termux/files/usr/bin/bash
# -*- coding: utf-8 -*-
function print_ew () {
if [[ "$1" == "error" ]]; then
s_text="\x1b[38;5;1m[ERROR]:";
text="$2\n";
elif [[ "$1" == "warn" ]]; then
s_text="\x1b[38;5;220m[WARNING]:";
text="$2\n";
elif [[ "$1" == "question" ]]; then
s_text="\x1b[38;5;128m[QUESTION]:";
text="$2";
elif [[ "$1" == "info" ]]; then
s_text="\x1b[38;5;83m[Installer thread/INFO]:";
text="$2\n";
else
s_text="\x1b[38;5;31m[$1]:";
text="$2\n";
fi
current_time="$( date +"%k:%M:%S" )";
printf "\x1b[38;5;214m[${current_time}] ${s_text}\x1b[0m \x1b[38;5;87m$text\x1b[0m";
}
if [[ "$(uname -o)" != "Android" ]]; then # check termux
print_ew "error" "this script is for Termux. " && exit 1;
fi
fn_install () {
clear;
directory=ubuntu-fs;
UBUNTU_VERSION=jammy;
if [ -d "$directory" ]; then
first=1
print_ew "warn" "Skipping the download and the extraction"
elif [ -z "$(command -v proot)" ]; then
print_ew "error" "Please install proot." && exit 1;
elif [ -z "$(command -v wget)" ]; then
print_ew "error" "Please install wget." && exit 1;
fi
if [ "$first" != 1 ]; then
if [ -f "ubuntu.tar.gz" ]; then
rm -rf ubuntu.tar.gz > /dev/null 2>&1;
fi
if [ ! -f "ubuntu.tar.gz" ]; then
print_ew "info" "Downloading the ubuntu rootfs, please wait 2 minute...";
ARCHITECTURE=$(dpkg --print-architecture);
case "$ARCHITECTURE" in
aarch64)
ARCHITECTURE=arm64 ;;
arm)
ARCHITECTURE=armhf ;;
amd64|x86_64)
ARCHITECTURE=amd64 ;;
*)
print_ew "error" "Unknown architecture :- $ARCHITECTURE" && exit 1 ;;
esac
wget "https://partner-images.canonical.com/core/${UBUNTU_VERSION}/current/ubuntu-${UBUNTU_VERSION}-core-cloudimg-${ARCHITECTURE}-root.tar.gz" -q -O ubuntu.tar.gz;
print_ew "info" "Download complete!";
fi
cur=`pwd`;
mkdir -p $directory > /dev/null 2>&1;
cd $directory;
print_ew "info" "Decompressing the ubuntu rootfs, please wait...";
proot --link2symlink tar -zxf $cur/ubuntu.tar.gz --exclude='dev'||:;
print_ew "info" "The ubuntu rootfs have been successfully decompressed!";
print_ew "info" "Fixing the resolv.conf, so that you have access to the internet";
printf "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > etc/resolv.conf;
stubs=();
stubs+=('usr/bin/groups');
for f in ${stubs[@]};do
print_ew "info" "Writing stubs, please wait...";
echo -e "#!/bin/sh\nexit" > "$f";
done
print_ew "info" "Successfully wrote stubs!";
cd $cur;
fi
mkdir -p ubuntu-binds;
bin=start.sh;
print_ew "info" "Creating the start script, please wait...";
cat > $bin <<- EOM
#!/bin/bash
# -*- coding: utf-8 -*-
cd \$(dirname \$0);
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD;
command="proot";
## uncomment following line if you are having FATAL: kernel too old message.
#command+=" -k 4.14.81";
command+=" --link2symlink";
command+=" -0";
command+=" -r $directory";
if [ -n "\$(ls -A ubuntu-binds)" ]; then
for f in ubuntu-binds/* ;do
. \$f;
done
fi
command+=" -b /dev";
command+=" -b /proc";
command+=" -b /sys";
command+=" -b ubuntu-fs/tmp:/dev/shm";
command+=" -b /data/data/com.termux";
command+=" -b /:/host-rootfs";
command+=" -b /sdcard";
command+=" -b /storage";
command+=" -b /mnt";
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=C.UTF-8";
command+=" /bin/bash --login";
com="\$@";
if [ -z "\$1" ]; then
exec \$command;
else
\$command -c "\$com";
fi
EOM
print_ew "info" "The start script has been successfully created!";
print_ew "info" "Fixing shebang of start.sh, please wait...";
termux-fix-shebang $bin > /dev/null 2>&1;
print_ew "info" "Successfully fixed shebang of start.sh!";
print_ew "info" "Making start.sh executable please wait...";
chmod +x $bin > /dev/null 2>&1;
print_ew "info" "Successfully made start.sh executable";
print_ew "info" "Cleaning up please wait...";
rm ubuntu.tar.gz -rf > /dev/null 2>&1;
print_ew "info" "Successfully cleaned up!";
print_ew "info" "installation completed! Run => bash start.sh";
rm -rf .git 2>&1;
}
trap '' 2
if [ "$1" == "-y" ]; then
fn_install;
elif [ "$1" == "" ]; then
print_ew "question" "Do you want to install ubuntu-in-termux? [Y/n] " && read cmd;
if [ "$cmd" == "y" ]; then
fn_install;
elif [ "$cmd" == "Y" ]; then
fn_install;
else
print_ew "error" "Installation aborted.";
fi
else
print_ew "error" "Installation aborted.";
fi