-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapt_downloader.sh
executable file
·51 lines (44 loc) · 1.25 KB
/
apt_downloader.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
#!/bin/env bash
infolder=$(pwd)/infolder
tmp=/tmp/aptdownloader
workdir=${tmp}/workdir
set -o pipefail
progress_file="$(pwd)/data/last_package.txt"
package_list="$(pwd)/data/package_list.txt"
touch ${progress_file}
last_line_number=$(head -n 1 ${progress_file})
current_line_number=${last_line_number:-1}
mkdir -p ${workdir}
if [[ ! -f ${package_list} ]]; then
echo "[+] create package list"
apt-cache search . | awk -F" - " '{print $1}' > ${package_list}
echo "[+] done"
fi
extract_package () {
local package_name=$1
pushd ${workdir}
local status=$?
if [[ ${status} -ne 0 ]]; then
echo "[-] ERROR: moving to ${workdir}"
exit ${status}
fi
rm -rf *
mkdir -p extracted
apt-get download $package
for debfile in $(ls *.deb); do
rm -rf extracted/*
dpkg-deb -x ${debfile} extracted/
for elf in $(find extracted/ -exec file {} \; | grep -Po ".*(?i)(?=: elf)")
do
cp ${elf} ${infolder}/
done
rm ${debfile}
done
popd
}
for package in $(awk "NR>${current_line_number}" ${package_list}); do
echo "[+] ${package}"
extract_package ${package}
current_line_number=$((current_line_number+1))
echo ${current_line_number} > ${progress_file}
done