summaryrefslogtreecommitdiffstats
path: root/data/wrappers/apt-get
blob: 9f94d818b4388d4fedce040a2be94eaf67c6db03 (plain)
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
#!/bin/sh
set -e
set -u

mode=unknown
for param in "$@"; do
  case "$param" in
    install | download | purge | remove | upgrade | dist-upgrade)
      mode=binuris
      break
    ;;
    source)
      mode=srcuris
      break
    ;;
    check | update | autoclean | autoremove)
      mode=noop
      break
    ;;
  esac
done

# let's fail as early as possible:
if [ "$mode" = unknown ]; then
  echo "E: unsupported apt-get operation, mode is still unknown" >&2
  echo "E: requested operation follows:" "$@"                    >&2
  exit 1
fi

if [ "$mode" = binuris ]; then
  apt-get.real "$@" --print-uris|perl -ne 'if (/^'\''(.+)'\'' ([^_]+)_([^_]+)_/) { my ($url, $package, $version)=($1,$2,$3); $version =~ s/%3a/:/g; print "$package $version $url\n"; }' >> /debootstrap/$mode
  apt-get.real "$@"
elif [ "$mode" = srcuris ]; then
  # all uris: perl -ne 'if (/^'\''(.+)'\'' (\S+)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }'
  # only dsc: perl -ne 'if (/^'\''(.+)'\'' (\S+\.dsc)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }'
  apt-get.real "$@" --print-uris|perl -ne 'if (/^'\''(.+)'\'' (\S+\.dsc)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }' >> /debootstrap/$mode.tmp
  apt-get.real "$@"
  while read filename uri; do
    # extract source and version w/o taking the GnuPG version in the signature section, and add uri after that
    s_v=$(awk '/^(Source|Version):/ {print $2}' "$filename" | head -2 | xargs)
    echo "$s_v $uri" >> /debootstrap/$mode
  done < /debootstrap/$mode.tmp
  rm /debootstrap/$mode.tmp
else
  # handle both noop and unknown here, each into its own file; unknown should be empty:
  echo "command:" "$@" >> /debootstrap/$mode
  apt-get.real "$@"
fi