3 # deb-download-from-pool.sh - download specific packages from the pool
5 # Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 MIRROR="${MIRROR:-https://deb.debian.org/debian}"
23 DEBUG_MIRROR="${DEBUG_MIRROR:-http://debug.mirrors.debian.org/debian-debug}"
26 PROG_NAME=$(basename "$0")
28 usage: $PROG_NAME [--all|-h|--help] <package> [<version>]
30 Helper script to download specific packages from the pool directory of
35 --all download all related packages even if currently
37 -h, --help display this usage message and exit
42 Some settings can be changed via environment variables:
51 dpkg --validate-pkgname -- "$1" || { usage 1>&2; exit 1; }
55 if [ "x$SOURCE_PACKAGE" = "x" ];
57 SOURCE_PACKAGE=$(apt-cache show "$PACKAGE" | grep Source | head -1 | cut -d ' ' -f 2)
58 if [ "x$SOURCE_PACKAGE" = "x" ];
60 SOURCE_PACKAGE="$PACKAGE"
64 if [ "x$POOL_DIRECTORY" = "x" ];
66 POOL_DIRECTORY=$(apt-cache showsrc "$SOURCE_PACKAGE" | grep Directory | head -1 | cut -d ' ' -f 2)
69 POOL_URL="${MIRROR}/${POOL_DIRECTORY}"
73 echo "Available versions, pass one of these as the second argument:"
74 wget -q "$POOL_URL" -O - | grep "${SOURCE_PACKAGE}_.*\\.dsc" | sed -e 's/^.*<a .*>.*_\(.*\)\.dsc<\/a>.*$/\1/g'
78 dpkg --validate-version -- "$2" || { usage 1>&2; exit 1; }
82 ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
83 PACKAGES=$(wget -q "$POOL_URL" -O - | \
84 grep -e "${VERSION}[^_]*_${ARCH}" \
85 -e "${VERSION}[^_]*_all" | \
86 sed -e 's/^.* href="\([^"]*\)".*$/\1/g')
90 PNAME=$(echo "$p" | cut -d '_' -f 1);
91 STATUS=$(grep-status -X \( -F Architecture "$ARCH" --or -F Architecture all \) --and -X -F Package "$PNAME" -n -s Status || true)
92 if [ "$STATUS" = "install ok installed" ] || [ "$DOWNLOAD_ALL" = "true" ];
94 wget -nv "${POOL_URL}/${p}"
100 [ $# -eq 0 ] && { usage 1>&2 && exit 1; }
118 echo "Error: Unknown option '${1}'" 1>&2
128 MIRROR=$DEBUG_MIRROR download "$@"