]> git.saurik.com Git - apt.git/blobdiff - vendor/getinfo
Tags should use StoreString, not WriteStringInMap.
[apt.git] / vendor / getinfo
index 861fd3d17da4e1880df52978e46ebde7ace1ed4b..37eb74cef629b906edd129c905f55e90bb5543a7 100755 (executable)
@@ -2,7 +2,48 @@
 # small helper to extract information form *.ent files
 
 BASEDIR="$(readlink -f "$(dirname $0)")"
 # small helper to extract information form *.ent files
 
 BASEDIR="$(readlink -f "$(dirname $0)")"
-INFO="$(readlink -f "${BASEDIR}/current/apt-vendor.ent")"
+
+getcurrent() {
+       # search for an exact match to use the correct sources.list example
+       cd $BASEDIR
+       DISTROS="$(find . -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 2)"
+       for DISTRO in $DISTROS; do
+               if dpkg-vendor --is $DISTRO; then
+                       echo $DISTRO
+                       return 0
+               fi
+       done
+
+       # if we haven't found a specific, look for a deriving
+       # we do ubuntu and debian last as those are the biggest families
+       # and would therefore potentially 'shadow' smaller families
+       # (especially debian as it sorts quiet early)
+       for DISTRO in $DISTROS; do
+               if [ "$DISTRO" = 'debian' -o "$DISTRO" = 'ubuntu' ]; then continue; fi
+               if dpkg-vendor --derives-from $DISTRO; then
+                       echo $DISTRO
+                       return 0
+               fi
+       done
+
+       # Do the ubuntu/debian dance we talked about
+       if dpkg-vendor --derives-from ubuntu; then
+               echo $DISTRO
+               return 0
+       fi
+
+       echo debian
+       return 0
+}
+
+if [ "$1" = "--vendor" ]; then
+       CURRENT_VENDOR="$2"
+       shift 2
+else
+       CURRENT_VENDOR=$(getcurrent)
+fi
+INFO="$(readlink -f "${BASEDIR}/$CURRENT_VENDOR/apt-vendor.ent")"
+VERBATIM="${BASEDIR}/../doc/apt-verbatim.ent"
 
 if [ -z "$INFO" ] || [ ! -e "$INFO" ]; then
        echo >&2 'The current vendor is not valid or not chosen by the buildsystem yet.'
 
 if [ -z "$INFO" ] || [ ! -e "$INFO" ]; then
        echo >&2 'The current vendor is not valid or not chosen by the buildsystem yet.'
@@ -10,7 +51,7 @@ if [ -z "$INFO" ] || [ ! -e "$INFO" ]; then
 fi
 
 getrawfield() {
 fi
 
 getrawfield() {
-       grep --max-count=1 "^<!ENTITY $1 \"" "${2:-$INFO}" | cut -d'"' -f 2
+       awk "/<!ENTITY $1/ {f=NR} f && NR-1==f { print; exit 0 }" RS='"' "${2:-$INFO}"
 }
 
 getfield() {
 }
 
 getfield() {
@@ -20,14 +61,20 @@ getfield() {
 }
 
 case "$1" in
 }
 
 case "$1" in
-debian-stable-codename)
-       getrawfield 'stable-codename' "${BASEDIR}/../doc/apt-verbatim.ent"
+debian-stable-codename|debian-oldstable-codename|debian-testing-codename|ubuntu-codename)
+       getrawfield "$1" "$VERBATIM"
+       ;;
+sourceslist-list-format|keyring-package|keyring-filename|keyring-master-filename|keyring-removed-filename|keyring-uri|current-codename)
+       exec $0 --vendor $CURRENT_VENDOR 'vendor' "$@"
+       ;;
+vendor)
+       getfield "$2"
        ;;
        ;;
-ubuntu-codename)
-       getrawfield 'ubuntu-codename' "${BASEDIR}/../doc/apt-verbatim.ent"
+verbatim)
+       getfield "$2" "$VERBATIM"
        ;;
        ;;
-keyring-package|keyring-filename|keyring-master-filename|keyring-removed-filename|keyring-uri|current-distro-codename)
-       getfield "$1"
+current)
+       echo $CURRENT_VENDOR
        ;;
 *)
        echo >&2 "Unknown data field $1 requested"
        ;;
 *)
        echo >&2 "Unknown data field $1 requested"