-
Notifications
You must be signed in to change notification settings - Fork 2
/
deb-download.sh
executable file
·437 lines (380 loc) · 20.6 KB
/
deb-download.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/bin/bash
usage="$(basename "$0") [-h] [-d DISTRO] [-r RELEASE] [-p \"PACKAGE1 PACKAGE2 ..\"] [-k AABBCCDDEEFF0011] [-t \"ppa:user/ppa\"] [-s]
Download deb-package(s) for given distribution release,
where:
-h show this help text
-d distro name (debian, ubuntu, mint, astra, kali)
-r release name (buster, focal, 20.3, 2.12, rolling)
-p packages
-k key for apt-key command (optional)
-t extra PPA repository for Ubuntu or full deb-line (optional)
-s also download source-code for deb-package(s) (optional)
-b use deb-package(s) from backports pocket (optional)"
get_source=0
use_backports=0
while getopts ":hd:r:p:k:t:sb" opt; do
case "$opt" in
h) echo "$usage"; exit;;
d) distro=$OPTARG;;
r) release=$OPTARG;;
p) packages=$OPTARG;;
k) apt_key=$OPTARG;;
t) third_party_repo=$OPTARG;;
s) get_source=1;;
b) use_backports=1;;
\?) echo "Error: Unimplemented option chosen!"; echo "$usage" >&2; exit 1;;
esac
done
# mandatory arguments
if [ ! "$distro" ] || [ ! "$release" ] || [ ! "$packages" ]; then
echo "Error: arguments -d, -r and -p must be provided!"
echo "$usage" >&2; exit 1
fi
# commands which are dynamically generated from optional arguments
apt_key_command="true"
third_party_repo_command="true"
get_source_command="true"
use_backports_command=""
# distros and their versions
supported_ubuntu_releases="trusty|xenial|bionic|focal|jammy|lunar|mantic|noble|oracular|devel";
eol_ubuntu_releases="precise|quantal|raring|saucy|utopic|vivid|wily|yakkety|zesty|artful|cosmic|disco|eoan|groovy|hirsute|impish|kinetic";
ubuntu_release_is_eol=0;
supported_debian_releases="oldoldstable|buster|oldstable|bullseye|stable|bookworm";
debian_releases_newsecurity="oldstable|bullseye|stable|bookworm";
testing_debian_releases="testing|trixie";
rolling_debian_releases="sid|unstable|experimental";
non_free_firmware_debian_releases="stable|bookworm|$testing_debian_releases|$rolling_debian_releases"
eol_debian_releases="squeeze|wheezy|jessie|stretch";
debian_release_is_eol=0;
supported_mint_releases="lmde5|lmde6|19$|19.1|19.2|19.3|20$|20.1|20.2|20.3|21$|21.1|21.2|21.3|22$";
eol_mint_releases="lmde4|17$|18$"; # lmde2 and lmde3 are broken because of archival
supported_astra_releases="2.12|1.7|1.8";
supported_kali_releases="rolling";
no_install_suggests="--no-install-suggests";
no_update="-n";
add_sources="";
gpg_pkg="gpg";
software_properties_pkg="software-properties-common"
# main code
if [ "$distro" != "debian" ] && [ "$distro" != "ubuntu" ] && [ "$distro" != "mint" ] && [ "$distro" != "astra" ] && [ "$distro" != "kali" ]; then
echo "Error: only Debian, Ubuntu, Mint, Astra and Kali are supported!";
exit 1;
else
if [ "$distro" == "ubuntu" ]; then
ubuntu_releases="$supported_ubuntu_releases|$eol_ubuntu_releases"
if ! echo "$release" | grep -wEq "$ubuntu_releases"
then
echo "Error: Ubuntu $release is not supported!";
echo "Supported Ubuntu releases are ${ubuntu_releases//|/, }.";
exit 1;
else
if echo "$release" | grep -wEq "$eol_ubuntu_releases"
then
echo "Warning: Ubuntu $release is EOL, but script will continue to run.";
ubuntu_release_is_eol=1;
fi
fi
fi
if [ "$distro" == "debian" ]; then
debian_releases="$supported_debian_releases|$eol_debian_releases|$testing_debian_releases|$rolling_debian_releases"
if ! echo "$release" | grep -wEq "$debian_releases"
then
echo "Error: Debian $release is not supported!";
echo "Supported Debian releases are ${debian_releases//|/, }.";
exit 1;
else
if echo "$release" | grep -wEq "$eol_debian_releases"
then
echo "Warning: Debian $release is EOL, but script will continue run.";
debian_release_is_eol=1;
# workaround for Debain Squeeze - it does not have `--no-install-suggests`
# and has problem with GPG signature
if [[ "$release" == "squeeze" || "$release" == "jessie" ]]; then
no_install_suggests="--force-yes";
fi
fi
fi
fi
if [ "$distro" == "mint" ]; then
mint_releases="$supported_mint_releases|$eol_mint_releases"
if ! echo "$release" | grep -wEq "$mint_releases"
then
echo "Error: Mint $release is not supported!";
mint_temp="${mint_releases//|/, }"
echo "Supported Mint releases are ${mint_temp//$/}".;
exit 1;
else
if echo "$release" | grep -wEq "$eol_mint_releases"
then
echo "Warning: Mint $release is EOL, but script will continue run.";
fi
fi
fi
if [ "$distro" == "astra" ]; then
if ! echo "$release" | grep -wEq "$supported_astra_releases"
then
echo "Error: Astra $release is not supported!";
echo "Supported Astra releases are ${supported_astra_releases//|/, }".;
exit 1;
fi
fi
if [ "$distro" == "kali" ]; then
if ! echo "$release" | grep -wEq "$supported_kali_releases"
then
echo "Error: Kali $release is not supported!";
echo "Supported Kali releases are ${supported_kali_releases//|/, }".;
exit 1;
fi
fi
fi
# prepare storage folder
rm -rf storage
mkdir -p storage
cd storage || { echo "Error: can't cd to storage directory!"; exit 3; }
# prepare Dockerfile
if [ "$distro" == "ubuntu" ] || [ "$distro" == "debian" ]; then
echo "FROM $distro:$release" > Dockerfile
elif [ "$distro" == "astra" ]; then
if [ "$release" == "2.12" ]; then
echo "FROM registry.astralinux.ru/library/orel:latest" > Dockerfile
elif [ "$release" == "1.7" ]; then
echo "FROM registry.astralinux.ru/library/astra/ubi17:latest" > Dockerfile
elif [ "$release" == "1.8" ]; then
echo "FROM registry.astralinux.ru/library/astra/ubi18:1.8" > Dockerfile
fi
elif [ "$distro" == "mint" ]; then
if ! echo "$release" | grep -q "^lmde"
then
echo "FROM linuxmintd/mint$release-amd64" > Dockerfile
else
echo "FROM linuxmintd/$release-amd64" > Dockerfile
fi
no_update=""
if [ $get_source == 1 ] && [ -n "$third_party_repo" ]; then
echo "Warning: add-apt-repository on Mint does not support '-s' option, so getting sources is not possible, ignoring this option for third-party repositories."
fi
else
echo "FROM kalilinux/kali-$release" > Dockerfile
fi
if [ $use_backports == 1 ]; then
if [[ "$distro" == "astra" || "$distro" == "mint" || "$distro" == "kali" ]]; then
echo "Warning: backports are not yet supported for Astra, Kali and Mint."
fi
fi
cat << EOF >> Dockerfile
RUN [ -z "$http_proxy" ] && echo "Using direct network connection" || echo 'Acquire::http::Proxy "$http_proxy";' > /etc/apt/apt.conf.d/99proxy
EOF
if [ "$distro" == "ubuntu" ]; then
if [ $ubuntu_release_is_eol == 1 ]; then
echo "RUN echo 'deb http://old-releases.ubuntu.com/ubuntu $release main universe multiverse restricted' > /etc/apt/sources.list
RUN echo 'deb http://old-releases.ubuntu.com/ubuntu $release-updates main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb http://old-releases.ubuntu.com/ubuntu $release-security main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
if [ $use_backports == 1 ]; then
if [ "$release" != "precise" ]; then
echo "RUN echo 'deb http://old-releases.ubuntu.com/ubuntu $release-backports main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
use_backports_command="-t $release-backports"
fi
fi
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://old-releases.ubuntu.com/ubuntu $release main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb-src http://old-releases.ubuntu.com/ubuntu $release-updates main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb-src http://old-releases.ubuntu.com/ubuntu $release-security main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
if [ $use_backports == 1 ]; then
if [ "$release" != "precise" ]; then
echo "RUN echo 'deb-src http://old-releases.ubuntu.com/ubuntu $release-backports main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
fi
else # fixes missed *multiverse* for at least *precise*
echo "RUN echo 'deb http://archive.ubuntu.com/ubuntu $release main universe multiverse restricted' > /etc/apt/sources.list
RUN echo 'deb http://archive.ubuntu.com/ubuntu $release-updates main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb http://archive.ubuntu.com/ubuntu $release-security main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
if [ $use_backports == 1 ]; then
echo "RUN echo 'deb http://archive.ubuntu.com/ubuntu $release-backports main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
use_backports_command="-t $release-backports"
fi
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://archive.ubuntu.com/ubuntu $release main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb-src http://archive.ubuntu.com/ubuntu $release-updates main universe multiverse restricted' >> /etc/apt/sources.list
RUN echo 'deb-src http://archive.ubuntu.com/ubuntu $release-security main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
if [ $use_backports == 1 ]; then
echo "RUN echo 'deb-src http://archive.ubuntu.com/ubuntu $release-backports main universe multiverse restricted' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
fi
fi
if [ "$distro" == "debian" ]; then
if [ $debian_release_is_eol == 1 ]; then
echo "RUN echo 'deb http://archive.debian.org/debian $release main contrib non-free' > /etc/apt/sources.list" >> Dockerfile
echo "RUN echo 'deb http://archive.debian.org/debian-security $release/updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://archive.debian.org/debian $release main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
echo "RUN echo 'deb-src http://archive.debian.org/debian-security $release/updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
if [ "$release" != "wheezy" ]; then
if [ $use_backports == 1 ]; then
echo "RUN echo 'deb http://archive.debian.org/debian/ $release-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://archive.debian.org/debian/ $release-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
use_backports_command="--force-yes --allow-unauthenticated -t $release-backports"
fi
fi
else # adding *contrib* and *non-free*
echo "RUN echo 'deb http://deb.debian.org/debian/ $release main contrib non-free' > /etc/apt/sources.list" >> Dockerfile
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb http://deb.debian.org/debian/ $release non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
if [ $use_backports == 1 ]; then
if [ "$release" == "buster" ]; then
echo "RUN echo 'deb http://archive.debian.org/debian buster-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
else
echo "RUN echo 'deb http://deb.debian.org/debian/ $release-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb http://deb.debian.org/debian/ $release-backports non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
use_backports_command="-t $release-backports"
fi
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
if [ $use_backports == 1 ]; then
if [ "$release" == "buster" ]; then
echo "RUN echo 'deb-src http://archive.debian.org/debian buster-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
else
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release-backports main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release-backports non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
fi
# not adding updates
if ! echo "$release" | grep -wEq "$rolling_debian_releases"
then
echo "RUN echo 'deb http://deb.debian.org/debian/ $release-updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb http://deb.debian.org/debian/ $release-updates non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
echo "RUN echo 'deb http://security.debian.org/debian-security/ $release-security non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release-updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
# adding *non-free-firmware* for *bookworm* and newer
if echo "$release" | grep -wEq "$non_free_firmware_debian_releases"
then
echo "RUN echo 'deb-src http://deb.debian.org/debian/ $release-updates non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
echo "RUN echo 'deb-src http://security.debian.org/debian-security/ $release-security non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
fi
# not adding debian-security
if ! echo "$release" | grep -wEq "$testing_debian_releases|$rolling_debian_releases|$debian_releases_newsecurity"
then
echo "RUN echo 'deb http://security.debian.org/debian-security/ $release/updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://security.debian.org/debian-security/ $release/updates main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
# adding security in new fashion
if echo "$release" | grep -wEq "$debian_releases_newsecurity"
then
echo "RUN echo 'deb http://security.debian.org/debian-security/ $release-security main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://security.debian.org/debian-security/ $release-security main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
no_update=""
fi
fi
if [ "$distro" == "astra" ]; then
if [ "$release" == "1.7" ]; then
echo "RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-main/ 1.7_x86-64 main contrib non-free' > /etc/apt/sources.list
RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-update/ 1.7_x86-64 main contrib non-free' >> /etc/apt/sources.list
RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-base/ 1.7_x86-64 main contrib non-free' >> /etc/apt/sources.list
RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-extended/ 1.7_x86-64 main contrib non-free' >> /etc/apt/sources.list
RUN echo '# deb http://dl.astralinux.ru/astra/stable/1.7_x86-64/repository-extended/ 1.7_x86-64 astra-ce' >> /etc/apt/sources.list" >> Dockerfile
elif [ "$release" == "1.8" ]; then
echo "RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.8_x86-64/repository-main/ 1.8_x86-64 main contrib non-free non-free-firmware' > /etc/apt/sources.list
RUN echo 'deb http://dl.astralinux.ru/astra/stable/1.8_x86-64/repository-extended/ 1.8_x86-64 main contrib non-free non-free-firmware' >> /etc/apt/sources.list" >> Dockerfile
elif [ "$release" == "2.12" ]; then
echo "RUN echo 'deb http://dl.astralinux.ru/astra/stable/2.12_x86-64/repository orel main contrib non-free' > /etc/apt/sources.list" >> Dockerfile
no_update=""
fi
if [ $get_source == 1 ]; then
echo "Warning: sources for Astra Linux are not available, but script will try to run further."
fi
fi
if [ "$distro" == "kali" ]; then
if [ $get_source == 1 ]; then
echo "RUN echo 'deb-src http://http.kali.org/kali kali-$release main contrib non-free' >> /etc/apt/sources.list" >> Dockerfile
fi
fi
# 32-bit packages
if [[ "$distro" == "debian" || "$distro" == "ubuntu" || "$distro" == "mint" || "$distro" == "astra" ]]; then
# add 32-bit
if [ "$(arch)" == "x86_64" ]; then
if [[ "$release" != "squeeze" && "$release" != "precise" ]]; then
echo "RUN dpkg --add-architecture i386" >> Dockerfile
fi
fi
fi
# source code
if [ $get_source == 1 ]; then
if [ "$distro" != "mint" ] && [ -n "$third_party_repo" ]; then
add_sources="-s";
fi
get_source_command="apt-get install dpkg-dev --no-install-recommends -y $use_backports_command && apt-get source ${packages[*]} $use_backports_command --print-uris | grep ^\'http:// | awk '{print \$1}' | sed \"s|'||g\" >> /var/cache/apt/archives/urls.txt && apt-get source ${packages[*]} $use_backports_command"
fi
# third-party repository key and PPA/deb-line
if [ -n "$apt_key" ]; then
apt_key_command="apt-get install -y gnupg && apt-key adv --recv-keys --keyserver keyserver.ubuntu.com $apt_key"
fi
if [ -n "$third_party_repo" ]; then
if [ "$distro" == "astra" ]; then
echo "Warning: add-apt-repository command is not yet supported on AstraLinux, but script will try to run further."
else
if [ "$release" == "precise" ]; then
software_properties_pkg="python-software-properties"
gpg_pkg=""
no_update=""
if [ $get_source == 1 ]; then
add_sources="" # not needed on precise, deb-src is already enabled automatically
fi
elif [[ "$release" == "trusty" || "$release" == "xenial" ]]; then
gpg_pkg=""
no_update=""
fi
third_party_repo_command="apt-get install -y python3-launchpadlib || apt-get install -y python-launchpadlib || true; apt-get install $software_properties_pkg gnupg $gpg_pkg dirmngr --no-install-recommends -y && add-apt-repository -y $add_sources $no_update \"$third_party_repo\" && apt-get update";
fi
fi
# prepare download script
cat << EOF > script.sh
set -x
export DEBIAN_FRONTEND=noninteractive
rm -rfv /var/cache/apt/archives/partial
cd /var/cache/apt/archives
apt-get update && \
$apt_key_command && \
$third_party_repo_command && \
$get_source_command || true && \
apt-get install -y --no-install-recommends $no_install_suggests --reinstall --download-only ${packages[*]} $use_backports_command --print-uris | grep ^\'http:// | awk '{print \$1}' | sed "s|'||g" >> /var/cache/apt/archives/urls.txt &&
apt-get install -y --no-install-recommends $no_install_suggests --reinstall --download-only ${packages[*]} $use_backports_command
chown -R "$(id --user):$(id --group)" /var/cache/apt/archives
EOF
# build container
docker build . -t "dd-$distro-$release"
# run script inside container
docker run --rm -v "${PWD}":/var/cache/apt/archives -it "dd-$distro-$release" sh /var/cache/apt/archives/script.sh