Debian Codegraph @

debian/cross/download-deb

raw
1 #!/bin/sh
2
3 # wrapper to download a binary package from a full APT repository
4 # (hopefully checking the archive signatures while at it)
5 #
6 # Copyright 2016 Niko Tyni <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the same terms as Perl itself.
10 #
11 # TODO: apt-key handling?
12 #
13
14 set -e
15
16 while getopts s:p:d:v: f
17 do
18 case $f in
19 p) package="$OPTARG";;
20 s) sources="$OPTARG";;
21 d) debdir="$OPTARG";;
22 v) version="$OPTARG";;
23 esac
24 done
25 shift `expr $OPTIND - 1`
26
27 if [ ! -n "$package" ] && [ -r debian/control ]; then
28 package=$(sed -n 's/^Package: *\(libperl5\..*\)/\1/ p' debian/control)
29 fi
30
31 if [ ! -n "$package" ]; then
32 echo "cannot guess name of package to download, aborting" 1>&2
33 exit 1
34 fi
35
36 if [ ! -n "$sources" ]; then
37 sources="deb http://httpredir.debian.org/debian unstable main"
38 fi
39
40 if [ ! -n "$version" ]; then
41 version=$(dpkg-parsechangelog -Sversion)
42 fi
43
44 if [ ! -n "$debdir" ]; then
45 debdir=.
46 fi
47
48 if [ $# = 0 ]; then
49 echo "Usage: $0 [ -p <package>[,<package2>,...] ] [ -d <debdir> ] [ -v <version> ] [ -s '<full sources.list line>' ] <arch> [...]" 1>&2
50 exit 1
51 fi
52
53 EXITCODE=0
54
55 for ARCH in "$@"
56 do
57 APTTMP=$(mktemp -d)
58 echo "$sources" > $APTTMP/sources.list
59 APTOPTIONS="-o APT::Architecture=$ARCH -o Dir::State=$APTTMP \
60 -o Dir::Cache=$APTTMP -o Debug::NoLocking=true \
61 -o Acquire::Languages=none \
62 -o Dir::Etc::Sourcelist=$APTTMP/sources.list"
63 apt-get $APTOPTIONS update
64 for p in $(echo $package | sed 's/,/ /g'); do
65 (cd "$debdir"; apt-get $APTOPTIONS download $p:$ARCH=$version) || EXITCODE=$?
66 done
67 rm -rf "$APTTMP"
68 done
69 exit $EXITCODE