getinfo 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. INFO="$(readlink -f "${BASEDIR}/$(getcurrent)/apt-vendor.ent")"
  34. VERBATIM="${BASEDIR}/../doc/apt-verbatim.ent"
  35. if [ -z "$INFO" ] || [ ! -e "$INFO" ]; then
  36. echo >&2 'The current vendor is not valid or not chosen by the buildsystem yet.'
  37. exit 1
  38. fi
  39. getrawfield() {
  40. awk "/<!ENTITY $1/ {f=NR} f && NR-1==f { print; exit 0 }" RS='"' "${2:-$INFO}"
  41. }
  42. getfield() {
  43. local FIELD="$(getrawfield "$@")"
  44. FIELD="${FIELD#*>}"
  45. echo "${FIELD%<*}"
  46. }
  47. case "$1" in
  48. debian-stable-codename|debian-oldstable-codename|debian-testing-codename|ubuntu-codename)
  49. getrawfield "$1" "$VERBATIM"
  50. ;;
  51. keyring-package|keyring-filename|keyring-master-filename|keyring-removed-filename|keyring-uri|current-codename)
  52. exec $0 'vendor' "$@"
  53. ;;
  54. vendor)
  55. getfield "$2"
  56. ;;
  57. verbatim)
  58. getfield "$2" "$VERBATIM"
  59. ;;
  60. current)
  61. getcurrent
  62. ;;
  63. *)
  64. echo >&2 "Unknown data field $1 requested"
  65. exit 2
  66. ;;
  67. esac