dec00f61 |
#!/usr/bin/env bash |
e62ba4d3 |
# **info.sh**
|
dc97cb71 |
# Produce a report on the state of DevStack installs |
dec00f61 |
#
# Output fields are separated with '|' chars
# Output types are git,localrc,os,pip,pkg: |
c5dfecd8 |
# |
dec00f61 |
# git|<project>|<branch>[<shaq>] |
85ad108a |
# localrc|<var>=<value> |
dec00f61 |
# os|<var>=<value>
# pip|<package>|<version>
# pkg|<package>|<version>
function usage { |
dc97cb71 |
echo "$0 - Report on the DevStack configuration" |
dec00f61 |
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
|
a9e0a488 |
# Import common functions
source $TOP_DIR/functions
|
dec00f61 |
# 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
|
a9e0a488 |
# OS
# --
# Determine what OS we're using
GetDistro
echo "os|distro=$DISTRO"
echo "os|vendor=$os_VENDOR"
echo "os|release=$os_RELEASE"
|
dec00f61 |
# Repos
# -----
# git_report <dir> |
aee18c74 |
function git_report { |
dec00f61 |
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
# --------
|
d2bcbea5 |
# - Only check packages for the services enabled
# - Parse version info from the package metadata, not the package/file names |
dec00f61 |
|
8c43809e |
for p in $(get_packages $ENABLED_SERVICES); do |
a9e0a488 |
if [[ "$os_PACKAGE" = "deb" ]]; then
ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) |
00011c08 |
elif [[ "$os_PACKAGE" = "rpm" ]]; then |
a9e0a488 |
ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p) |
00011c08 |
else
exit_distro_not_supported "finding version of a package" |
a9e0a488 |
fi |
dec00f61 |
echo "pkg|${p}|${ver}"
done
|
a9e0a488 |
|
dec00f61 |
# Pips
# ----
|
8ec27220 |
CMD_PIP=$(get_pip_command) |
dec00f61 |
# Pip tells us what is currently installed
FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX) |
a9e0a488 |
$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null |
dec00f61 |
# Loop through our requirements and look for matches |
a9e0a488 |
while read line; do |
dec00f61 |
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 |
a9e0a488 |
done <$FREEZE_FILE |
dec00f61 |
rm $FREEZE_FILE
|
a9e0a488 |
|
dec00f61 |
# localrc
# -------
# Dump localrc with 'localrc|' prepended and comments and passwords left out
if [[ -r $TOP_DIR/localrc ]]; then |
d2bcbea5 |
RC=$TOP_DIR/localrc
elif [[ -f $RC_DIR/.localrc.auto ]]; then
RC=$TOP_DIR/.localrc.auto
fi
if [[ -n $RC ]]; then |
dec00f61 |
sed -e ' |
d2bcbea5 |
/^[ \t]*$/d;
/PASSWORD/s/=.*$/=\<password\>/; |
dec00f61 |
/^#/d;
s/^/localrc\|/; |
d2bcbea5 |
' $RC |
dec00f61 |
fi |