getinfo 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # small helper to extract information form *.ent files
  3. BASEDIR="$(readlink -f "$(dirname $0)")"
  4. getcurrent() {
  5. # search for an exact match to use the correct sources.list example
  6. cd $BASEDIR
  7. DISTROS="$(find . -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 2)"
  8. for DISTRO in $DISTROS; do
  9. if dpkg-vendor --is $DISTRO; then
  10. echo $DISTRO
  11. return 0
  12. fi
  13. done
  14. # if we haven't found a specific, look for a deriving
  15. # we do ubuntu and debian last as those are the biggest families
  16. # and would therefore potentially 'shadow' smaller families
  17. # (especially debian as it sorts quiet early)
  18. for DISTRO in $DISTROS; do
  19. if [ "$DISTRO" = 'debian' -o "$DISTRO" = 'ubuntu' ]; then continue; fi
  20. if dpkg-vendor --derives-from $DISTRO; then
  21. echo $DISTRO
  22. return 0
  23. fi
  24. done
  25. # Do the ubuntu/debian dance we talked about
  26. if dpkg-vendor --derives-from ubuntu; then
  27. echo $DISTRO
  28. return 0
  29. fi
  30. echo debian
  31. return 0
  32. }
  33. if [ "$1" = "--vendor" ]; then
  34. CURRENT_VENDOR="$2"
  35. shift 2
  36. else
  37. CURRENT_VENDOR=$(getcurrent)
  38. fi
  39. INFO="$(readlink -f "${BASEDIR}/$CURRENT_VENDOR/apt-vendor.ent")"
  40. VERBATIM="${BASEDIR}/../doc/apt-verbatim.ent"
  41. if [ -z "$INFO" ] || [ ! -e "$INFO" ]; then
  42. echo >&2 'The current vendor is not valid or not chosen by the buildsystem yet.'
  43. exit 1
  44. fi
  45. getrawfield() {
  46. awk "/<!ENTITY $1/ {f=NR} f && NR-1==f { print; exit 0 }" RS='"' "${2:-$INFO}"
  47. }
  48. getfield() {
  49. local FIELD="$(getrawfield "$@")"
  50. FIELD="${FIELD#*>}"
  51. echo "${FIELD%<*}"
  52. }
  53. case "$1" in
  54. debian-stable-codename|debian-oldstable-codename|debian-testing-codename|ubuntu-codename)
  55. getrawfield "$1" "$VERBATIM"
  56. ;;
  57. sourceslist-list-format|keyring-package|keyring-filename|keyring-master-filename|keyring-removed-filename|keyring-uri|current-codename)
  58. exec $0 --vendor $CURRENT_VENDOR 'vendor' "$@"
  59. ;;
  60. vendor)
  61. getfield "$2"
  62. ;;
  63. verbatim)
  64. getfield "$2" "$VERBATIM"
  65. ;;
  66. current)
  67. echo $CURRENT_VENDOR
  68. ;;
  69. *)
  70. echo >&2 "Unknown data field $1 requested"
  71. exit 2
  72. ;;
  73. esac