blob: bf40e827d5c82ef327ac62da6e65bbf19b8e0f92 [file] [log] [blame]
Dean Troyerdec00f62011-12-30 17:43:20 -06001#!/usr/bin/env bash
Dean Troyere62ba4d2012-06-27 22:07:34 -05002
3# **info.sh**
4
5# Produce a report on the state of devstack installs
Dean Troyerdec00f62011-12-30 17:43:20 -06006#
7# Output fields are separated with '|' chars
8# Output types are git,localrc,os,pip,pkg:
9# git|<project>|<branch>[<shaq>]
10# localtc|<var>=<value>
11# os|<var>=<value>
12# pip|<package>|<version>
13# pkg|<package>|<version>
14
15function usage {
16 echo "$0 - Report on the devstack configuration"
17 echo ""
18 echo "Usage: $0"
19 exit 1
20}
21
22if [ "$1" = "-h" ]; then
23 usage
24fi
25
26# Keep track of the current directory
27TOOLS_DIR=$(cd $(dirname "$0") && pwd)
28TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
29cd $TOP_DIR
30
Dean Troyera9e0a482012-07-09 14:07:23 -050031# Import common functions
32source $TOP_DIR/functions
33
Dean Troyerdec00f62011-12-30 17:43:20 -060034# Source params
35source $TOP_DIR/stackrc
36
37DEST=${DEST:-/opt/stack}
38FILES=$TOP_DIR/files
39if [[ ! -d $FILES ]]; then
40 echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
41 exit 1
42fi
43
Dean Troyera9e0a482012-07-09 14:07:23 -050044
45# OS
46# --
47
48# Determine what OS we're using
49GetDistro
50
51echo "os|distro=$DISTRO"
52echo "os|vendor=$os_VENDOR"
53echo "os|release=$os_RELEASE"
54if [ -n "$os_UPDATE" ]; then
55 echo "os|version=$os_UPDATE"
56fi
57
58
Dean Troyerdec00f62011-12-30 17:43:20 -060059# Repos
60# -----
61
62# git_report <dir>
63function git_report() {
64 local dir=$1
65 local proj ref branch head
66 if [[ -d $dir/.git ]]; then
67 pushd $dir >/dev/null
68 proj=$(basename $dir)
69 ref=$(git symbolic-ref HEAD)
70 branch=${ref##refs/heads/}
71 head=$(git show-branch --sha1-name $branch | cut -d' ' -f1)
72 echo "git|${proj}|${branch}${head}"
73 popd >/dev/null
74 fi
75}
76
77for i in $DEST/*; do
78 if [[ -d $i ]]; then
79 git_report $i
80 fi
81done
82
Dean Troyerdec00f62011-12-30 17:43:20 -060083
84# Packages
85# --------
86
87# - We are going to check packages only for the services needed.
88# - We are parsing the packages files and detecting metadatas.
Dean Troyerdec00f62011-12-30 17:43:20 -060089
Dean Troyera9e0a482012-07-09 14:07:23 -050090if [[ "$os_PACKAGE" = "deb" ]]; then
91 PKG_DIR=$FILES/apts
92else
93 PKG_DIR=$FILES/rpms
94fi
Dean Troyerdec00f62011-12-30 17:43:20 -060095
Dean Troyera9e0a482012-07-09 14:07:23 -050096for p in $(get_packages $PKG_DIR); do
97 if [[ "$os_PACKAGE" = "deb" ]]; then
98 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
99 else
100 ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
101 fi
Dean Troyerdec00f62011-12-30 17:43:20 -0600102 echo "pkg|${p}|${ver}"
103done
104
Dean Troyera9e0a482012-07-09 14:07:23 -0500105
Dean Troyerdec00f62011-12-30 17:43:20 -0600106# Pips
107# ----
108
Dean Troyera9e0a482012-07-09 14:07:23 -0500109if [[ "$os_PACKAGE" = "deb" ]]; then
110 CMD_PIP=/usr/bin/pip
111else
112 CMD_PIP=/usr/bin/pip-python
113fi
Dean Troyerdec00f62011-12-30 17:43:20 -0600114
115# Pip tells us what is currently installed
116FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
Dean Troyera9e0a482012-07-09 14:07:23 -0500117$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
Dean Troyerdec00f62011-12-30 17:43:20 -0600118
119# Loop through our requirements and look for matches
Dean Troyera9e0a482012-07-09 14:07:23 -0500120while read line; do
Dean Troyerdec00f62011-12-30 17:43:20 -0600121 if [[ -n "$line" ]]; then
122 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
123 # Handle URLs
124 p=${BASH_REMATCH[1]}
125 ver=${BASH_REMATCH[2]}
126 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
127 # Normal pip packages
128 p=${BASH_REMATCH[1]}
129 ver=${BASH_REMATCH[2]}
130 else
131 # Unhandled format in freeze file
132 #echo "unknown: $p"
133 continue
134 fi
135 echo "pip|${p}|${ver}"
136 else
137 # No match in freeze file
138 #echo "unknown: $p"
139 continue
140 fi
Dean Troyera9e0a482012-07-09 14:07:23 -0500141done <$FREEZE_FILE
Dean Troyerdec00f62011-12-30 17:43:20 -0600142
143rm $FREEZE_FILE
144
Dean Troyera9e0a482012-07-09 14:07:23 -0500145
Dean Troyerdec00f62011-12-30 17:43:20 -0600146# localrc
147# -------
148
149# Dump localrc with 'localrc|' prepended and comments and passwords left out
150if [[ -r $TOP_DIR/localrc ]]; then
151 sed -e '
152 /PASSWORD/d;
153 /^#/d;
154 s/^/localrc\|/;
Dean Troyera9e0a482012-07-09 14:07:23 -0500155 ' $TOP_DIR/localrc
Dean Troyerdec00f62011-12-30 17:43:20 -0600156fi