-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.py
More file actions
executable file
·233 lines (196 loc) · 7.53 KB
/
install.py
File metadata and controls
executable file
·233 lines (196 loc) · 7.53 KB
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
#!/usr/bin/env python3
import subprocess
import requests
import os
import tempfile
import shutil
#BASE_URL = 'http://termux.net/'
BASE_URL = 'https://packages.termux.dev/apt/'
# Create mirror using
# lftp -c "mirror --use-pget-n=10 --verbose http://termux.net"
# azcopy --source dists/ --destination https://termuxdist.blob.core.windows.net/dists --recursive --dest-key $(az storage account keys list --account-name termuxdist --output tsv --query "[0].value")
DEFAULT_PKG = ['apt', 'bash', 'busybox', 'ca-certificates', 'command-not-found', 'dash', 'dash', 'dpkg', 'gdbm', 'gpgv', 'libandroid-support', 'libbz2', 'libc++', 'libcrypt', 'libcurl', 'libffi', 'libgcrypt', 'libgpg-error', 'liblzma', 'libnghttp2', 'libsqlite', 'ndk-sysroot', 'ncurses', 'ncurses-ui-libs', 'openssl', 'python', 'python-pip', 'readline', 'termux-am', 'termux-exec', 'termux-tools', 'qt5-base', 'qt5-declarative', 'libicu', 'swig', 'gettext', 'ripgrep']
# The checked-in debs are built using the neos branch on:
# https://github.com/commaai/termux-packages/tree/neos/
#
# Quick Start:
# * start docker: scripts/run-docker.sh
# * build inside container: ./build-package.sh -a aarch64 python
# * copy the deb from termux-packages/debs/
LOCAL_OVERRIDE_PKG = {
#'rust': 'rust_1.38.0-4_aarch64.deb',
#'python': 'python_3.8.5_aarch64.deb',
#'swig': 'swig_4.0.1-1_aarch64.deb',
#'libicu': 'libicu_65.1-1_aarch64.deb',
#'gettext': 'gettext_0.20.1-3_aarch64.deb',
#'ripgrep': 'ripgrep_11.0.2-1_aarch64.deb',
'qt5-base': 'qt5-base_5.12.8-28_aarch64.deb',
'qt5-declarative': 'qt5-declarative_5.12.8-28_aarch64.deb',
'apt': 'apt_2.7.1-1_aarch64.deb' # patched to remove stupid ass "can't run as root" bullshit only an asshole would add fuck those guys i mean it's my FUCKING OS let me do WHAT I WANT assholes. you know what? this ramble is getting me all sweaty. i'm spiraling. anyway, i fixed that bullshit. at least this isn't the longest single line in the file.
}
def load_packages():
pkg_deps = {}
pkg_filenames = {}
r = requests.get(BASE_URL + 'termux-root/dists/stable/main/binary-aarch64/Packages').text
r2 = requests.get(BASE_URL + 'termux-main/dists/stable/main/binary-aarch64/Packages').text
print(BASE_URL + 'dists/stable/main/binary-aarch64/Packages')
for l in r.split('\n'):
if l.startswith("Package:"):
pkg_name = l.split(': ')[1]
pkg_depends = []
elif l.startswith('Depends: '):
pkg_depends = l.split(': ')[1].split(',')
pkg_depends = [p.replace(' ', '') for p in pkg_depends]
# strip version (eg. gnupg (>= 2.2.9-1))
pkg_depends = [p.split('(')[0] for p in pkg_depends]
elif l.startswith('Filename: '):
pkg_filename = l.split(': ')[1]
pkg_deps[pkg_name] = pkg_depends
pkg_filenames[pkg_name] = "termux-root/"+pkg_filename
for l in r2.split('\n'):
if l.startswith("Package:"):
pkg_name = l.split(': ')[1]
pkg_depends = []
elif l.startswith('Depends: '):
pkg_depends = l.split(': ')[1].split(',')
pkg_depends = [p.replace(' ', '') for p in pkg_depends]
pkg_depends = [p.replace('|dropbear','') for p in pkg_depends]
# strip version (eg. gnupg (>= 2.2.9-1))
pkg_depends = [p.split('(')[0] for p in pkg_depends]
elif l.startswith('Filename: '):
pkg_filename = l.split(': ')[1]
pkg_deps[pkg_name] = pkg_depends
pkg_filenames[pkg_name] = "termux-main/"+pkg_filename
return pkg_deps, pkg_filenames
def get_dependencies(pkg_deps, pkg_name):
r = [pkg_name]
try:
new_deps = pkg_deps[pkg_name]
for dep in new_deps:
r += get_dependencies(pkg_deps, dep)
except KeyError:
pass
return r
def install_package(pkg_deps, pkg_filenames, pkg):
if not os.path.exists('out'):
os.mkdir('out')
build_usr_dir = os.getcwd()
tmp_dir = tempfile.mkdtemp()
if pkg in LOCAL_OVERRIDE_PKG:
deb_name = LOCAL_OVERRIDE_PKG[pkg]
deb_path = os.path.join(os.path.join(build_usr_dir, "debs"), deb_name)
print("Using local copy of package %s - %s - %s" % (pkg, tmp_dir, deb_name))
elif pkg in pkg_filenames:
url = BASE_URL + pkg_filenames[pkg]
print("Downloading %s - %s - %s" % (pkg, tmp_dir, url))
r = requests.get(url)
deb_name = 'out.deb'
deb_path = os.path.join(tmp_dir, deb_name)
open(deb_path, 'wb').write(r.content)
else:
print("%s not found" % pkg)
return ""
subprocess.check_call(['ar', 'x', deb_path], cwd=tmp_dir)
subprocess.check_call(['tar', '-C', './out', '-p', '-xf', os.path.join(tmp_dir, 'data.tar.xz')])
if os.path.exists(os.path.join(tmp_dir, 'control.tar.gz')):
subprocess.check_call(['tar', '-xf', os.path.join(tmp_dir, 'control.tar.gz')], cwd=tmp_dir)
else:
subprocess.check_call(['tar', '-xf', os.path.join(tmp_dir, 'control.tar.xz')], cwd=tmp_dir)
control = open(os.path.join(tmp_dir, 'control')).read()
control += 'Status: install ok installed\n'
files = subprocess.check_output(['dpkg', '-c', deb_path], cwd=tmp_dir, encoding='utf-8')
file_list = ""
for f in files.split('\n'):
try:
filename = f.split()[5][1:]
if filename == '/':
filename = '/.' # this is what apt does
file_list += filename + "\n"
except IndexError:
pass
info_path = 'out/data/data/com.termux/files/usr/var/lib/dpkg/info'
if not os.path.exists(info_path):
os.makedirs(info_path)
open(os.path.join(info_path, pkg + '.list'), 'w').write(file_list)
copies = ['conffiles', 'postinst', 'prerm']
for copy in copies:
f = os.path.join(tmp_dir, copy)
if os.path.exists(f):
target = os.path.join(info_path, pkg + '.' + copy)
shutil.copyfile(f, target)
return control
if __name__ == "__main__":
to_install = DEFAULT_PKG
to_install += [
'autoconf',
'automake',
'bison',
'clang',
'cmake',
'coreutils',
'curl',
'ffmpeg',
'flex',
'gdb',
'git',
'git-lfs',
'htop',
'jq',
'libcurl',
# 'libcurl-dev',
'libffi',
# 'libffi-dev',
'libjpeg-turbo',
# 'libjpeg-turbo-dev',
'liblz4',
# 'liblz4-dev',
'liblzo',
# 'liblzo-dev',
'libmpc',
'libtool',
'libuuid',
# 'libuuid-dev',
#'libzmq',
'libpcap',
# 'libpcap-dev',
'make',
'man',
'nano',
'ncurses',
# 'ncurses-dev',
'openssh',
'openssl',
# 'openssl-dev',
'openssl-tool',
'patchelf',
'pkg-config',
'rsync',
'strace',
'tar',
'tmux',
'vim',
'wget',
'xz-utils',
'zlib',
# 'zlib-dev',
'binutils',
'binutils-libs',
'binutils-bin',
'gnupg'
]
pkg_deps, pkg_filenames = load_packages()
deps = []
for pkg in to_install:
deps += get_dependencies(pkg_deps, pkg)
deps = set(deps)
status = ""
for pkg in deps:
s = install_package(pkg_deps, pkg_filenames, pkg)
status += s + "\n"
print(deps)
try:
os.makedirs('out/data/data/com.termux/files/usr/var/lib/dpkg/')
except OSError:
pass
status_file = 'out/data/data/com.termux/files/usr/var/lib/dpkg/status'
open(status_file, 'w').write(status)