devstack/tools/info.sh
Ian Wienand 7710e7fc27 Only use lsb_release for distro tags
The existing GetOSVersion has a lot of unused code which is wrong in
several ways

 - the only path tested in upstream CI is with lsb_release, because
   it's pre-installed on all nodes

 - the /etc/redhat-release checking probably still works, but is
   unnecessary

 - If using lsb_release, os_UPDATE has never actually been set.

 - the /etc/SuSE-release branch checking is broken if the lsb package
   is actually installed.  lsb checking does not set os_UPDATE but yet
   the SuSE DISTRO setting relies on this to set a patch level (and so
   does some of the rpm tags).  SuSE 11 is up to update 3, but the rpm
   matching is stuck hard-coded to update 2.  I'm guessing
   installation is actually broken there.

 - the debian checking branch is broken.  The VERSION tags have been
   removed and were not supposed to be relied on anyway (see notes in
   [1])

This simplifies things:

 - remove OSX checking (moved here after discussions in
   I31d0fdd30928ecc8d959a95838b1d3affd28ac6f)

 - only use the output of lsb_release.

 - A small best-effort check to pre-install lsb packages if not
   detected (that avoids chicken-egg-problem of package-install
   wrappers relying on os_* flags).

 - The unset os_UPDATE is removed.  It's only previous use was for
   setting separate suse versions in the DISTRO element for matching
   during package installs (since removed)

 - DISTRO setting is modified to use the parts of os_RELEASE it wants.
   Per-above, this is the correct place to parse out specifics.

 - Call out the is_* functions, which are a better way to detect
   platforms

 - Export the variables as read-only, since they shouldn't be reset

[1] http://sources.debian.net/src/base-files/7.5/debian/changelog/

Change-Id: I46a2c36d95327087085df07cb797eb91249a893c
2016-01-12 09:23:35 +11:00

150 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# **info.sh**
# Produce a report on the state of DevStack installs
#
# Output fields are separated with '|' chars
# Output types are git,localrc,os,pip,pkg:
#
# git|<project>|<branch>[<shaq>]
# localtc|<var>=<value>
# os|<var>=<value>
# pip|<package>|<version>
# pkg|<package>|<version>
function usage {
echo "$0 - Report on the DevStack configuration"
echo ""
echo "Usage: $0"
exit 1
}
if [ "$1" = "-h" ]; then
usage
fi
# Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
cd $TOP_DIR
# Import common functions
source $TOP_DIR/functions
# Source params
source $TOP_DIR/stackrc
DEST=${DEST:-/opt/stack}
FILES=$TOP_DIR/files
if [[ ! -d $FILES ]]; then
echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
exit 1
fi
# OS
# --
# Determine what OS we're using
GetDistro
echo "os|distro=$DISTRO"
echo "os|vendor=$os_VENDOR"
echo "os|release=$os_RELEASE"
# Repos
# -----
# git_report <dir>
function git_report {
local dir=$1
local proj ref branch head
if [[ -d $dir/.git ]]; then
pushd $dir >/dev/null
proj=$(basename $dir)
ref=$(git symbolic-ref HEAD)
branch=${ref##refs/heads/}
head=$(git show-branch --sha1-name $branch | cut -d' ' -f1)
echo "git|${proj}|${branch}${head}"
popd >/dev/null
fi
}
for i in $DEST/*; do
if [[ -d $i ]]; then
git_report $i
fi
done
# Packages
# --------
# - Only check packages for the services enabled
# - Parse version info from the package metadata, not the package/file names
for p in $(get_packages $ENABLED_SERVICES); do
if [[ "$os_PACKAGE" = "deb" ]]; then
ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
elif [[ "$os_PACKAGE" = "rpm" ]]; then
ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
else
exit_distro_not_supported "finding version of a package"
fi
echo "pkg|${p}|${ver}"
done
# Pips
# ----
CMD_PIP=$(get_pip_command)
# Pip tells us what is currently installed
FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
# Loop through our requirements and look for matches
while read line; do
if [[ -n "$line" ]]; then
if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
# Handle URLs
p=${BASH_REMATCH[1]}
ver=${BASH_REMATCH[2]}
elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
# Normal pip packages
p=${BASH_REMATCH[1]}
ver=${BASH_REMATCH[2]}
else
# Unhandled format in freeze file
continue
fi
echo "pip|${p}|${ver}"
else
# No match in freeze file
continue
fi
done <$FREEZE_FILE
rm $FREEZE_FILE
# localrc
# -------
# Dump localrc with 'localrc|' prepended and comments and passwords left out
if [[ -r $TOP_DIR/localrc ]]; then
RC=$TOP_DIR/localrc
elif [[ -f $RC_DIR/.localrc.auto ]]; then
RC=$TOP_DIR/.localrc.auto
fi
if [[ -n $RC ]]; then
sed -e '
/^[ \t]*$/d;
/PASSWORD/s/=.*$/=\<password\>/;
/^#/d;
s/^/localrc\|/;
' $RC
fi