apt-get 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. set -e
  3. set -u
  4. mode=unknown
  5. for param in "$@"; do
  6. case "$param" in
  7. install | download | purge | remove | upgrade | dist-upgrade)
  8. mode=binuris
  9. break
  10. ;;
  11. source)
  12. mode=srcuris
  13. break
  14. ;;
  15. check | update | autoclean | autoremove)
  16. mode=noop
  17. break
  18. ;;
  19. esac
  20. done
  21. # let's fail as early as possible:
  22. if [ "$mode" = unknown ]; then
  23. echo "E: unsupported apt-get operation, mode is still unknown" >&2
  24. echo "E: requested operation follows:" "$@" >&2
  25. exit 1
  26. fi
  27. if [ "$mode" = binuris ]; then
  28. 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
  29. apt-get.real "$@"
  30. elif [ "$mode" = srcuris ]; then
  31. # all uris: perl -ne 'if (/^'\''(.+)'\'' (\S+)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }'
  32. # only dsc: perl -ne 'if (/^'\''(.+)'\'' (\S+\.dsc)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }'
  33. apt-get.real "$@" --print-uris|perl -ne 'if (/^'\''(.+)'\'' (\S+\.dsc)/) { my ($url, $filename) = ($1, $2); print "$filename $url\n"; }' >> /debootstrap/$mode.tmp
  34. apt-get.real "$@"
  35. while read filename uri; do
  36. # extract source and version w/o taking the GnuPG version in the signature section, and add uri after that
  37. s_v=$(awk '/^(Source|Version):/ {print $2}' "$filename" | head -2 | xargs)
  38. echo "$s_v $uri" >> /debootstrap/$mode
  39. done < /debootstrap/$mode.tmp
  40. rm /debootstrap/$mode.tmp
  41. else
  42. # handle both noop and unknown here, each into its own file; unknown should be empty:
  43. echo "command:" "$@" >> /debootstrap/$mode
  44. apt-get.real "$@"
  45. fi