blob: a872d59d1883d753ec5e92dfc0129240a561a276 [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:
Dean Troyerc5dfecd2012-09-08 14:20:43 -05009#
Dean Troyerdec00f62011-12-30 17:43:20 -060010# git|<project>|<branch>[<shaq>]
11# localtc|<var>=<value>
12# os|<var>=<value>
13# pip|<package>|<version>
14# pkg|<package>|<version>
15
16function usage {
17 echo "$0 - Report on the devstack configuration"
18 echo ""
19 echo "Usage: $0"
20 exit 1
21}
22
23if [ "$1" = "-h" ]; then
24 usage
25fi
26
27# Keep track of the current directory
28TOOLS_DIR=$(cd $(dirname "$0") && pwd)
29TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
30cd $TOP_DIR
31
Dean Troyera9e0a482012-07-09 14:07:23 -050032# Import common functions
33source $TOP_DIR/functions
34
Dean Troyerdec00f62011-12-30 17:43:20 -060035# Source params
36source $TOP_DIR/stackrc
37
38DEST=${DEST:-/opt/stack}
39FILES=$TOP_DIR/files
40if [[ ! -d $FILES ]]; then
41 echo "ERROR: missing devstack/files - did you grab more than just stack.sh?"
42 exit 1
43fi
44
Dean Troyera9e0a482012-07-09 14:07:23 -050045
46# OS
47# --
48
49# Determine what OS we're using
50GetDistro
51
52echo "os|distro=$DISTRO"
53echo "os|vendor=$os_VENDOR"
54echo "os|release=$os_RELEASE"
55if [ -n "$os_UPDATE" ]; then
56 echo "os|version=$os_UPDATE"
57fi
58
59
Dean Troyerdec00f62011-12-30 17:43:20 -060060# Repos
61# -----
62
63# git_report <dir>
64function git_report() {
65 local dir=$1
66 local proj ref branch head
67 if [[ -d $dir/.git ]]; then
68 pushd $dir >/dev/null
69 proj=$(basename $dir)
70 ref=$(git symbolic-ref HEAD)
71 branch=${ref##refs/heads/}
72 head=$(git show-branch --sha1-name $branch | cut -d' ' -f1)
73 echo "git|${proj}|${branch}${head}"
74 popd >/dev/null
75 fi
76}
77
78for i in $DEST/*; do
79 if [[ -d $i ]]; then
80 git_report $i
81 fi
82done
83
Dean Troyerdec00f62011-12-30 17:43:20 -060084
85# Packages
86# --------
87
88# - We are going to check packages only for the services needed.
89# - We are parsing the packages files and detecting metadatas.
Dean Troyerdec00f62011-12-30 17:43:20 -060090
Dean Troyera9e0a482012-07-09 14:07:23 -050091if [[ "$os_PACKAGE" = "deb" ]]; then
92 PKG_DIR=$FILES/apts
93else
94 PKG_DIR=$FILES/rpms
95fi
Dean Troyerdec00f62011-12-30 17:43:20 -060096
Dean Troyera9e0a482012-07-09 14:07:23 -050097for p in $(get_packages $PKG_DIR); do
98 if [[ "$os_PACKAGE" = "deb" ]]; then
99 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
100 else
101 ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
102 fi
Dean Troyerdec00f62011-12-30 17:43:20 -0600103 echo "pkg|${p}|${ver}"
104done
105
Dean Troyera9e0a482012-07-09 14:07:23 -0500106
Dean Troyerdec00f62011-12-30 17:43:20 -0600107# Pips
108# ----
109
Vincent Untz8ec27222012-11-29 09:25:31 +0100110CMD_PIP=$(get_pip_command)
Dean Troyerdec00f62011-12-30 17:43:20 -0600111
112# Pip tells us what is currently installed
113FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
Dean Troyera9e0a482012-07-09 14:07:23 -0500114$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
Dean Troyerdec00f62011-12-30 17:43:20 -0600115
116# Loop through our requirements and look for matches
Dean Troyera9e0a482012-07-09 14:07:23 -0500117while read line; do
Dean Troyerdec00f62011-12-30 17:43:20 -0600118 if [[ -n "$line" ]]; then
119 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
120 # Handle URLs
121 p=${BASH_REMATCH[1]}
122 ver=${BASH_REMATCH[2]}
123 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
124 # Normal pip packages
125 p=${BASH_REMATCH[1]}
126 ver=${BASH_REMATCH[2]}
127 else
128 # Unhandled format in freeze file
129 #echo "unknown: $p"
130 continue
131 fi
132 echo "pip|${p}|${ver}"
133 else
134 # No match in freeze file
135 #echo "unknown: $p"
136 continue
137 fi
Dean Troyera9e0a482012-07-09 14:07:23 -0500138done <$FREEZE_FILE
Dean Troyerdec00f62011-12-30 17:43:20 -0600139
140rm $FREEZE_FILE
141
Dean Troyera9e0a482012-07-09 14:07:23 -0500142
Dean Troyerdec00f62011-12-30 17:43:20 -0600143# localrc
144# -------
145
146# Dump localrc with 'localrc|' prepended and comments and passwords left out
147if [[ -r $TOP_DIR/localrc ]]; then
148 sed -e '
149 /PASSWORD/d;
150 /^#/d;
151 s/^/localrc\|/;
Dean Troyera9e0a482012-07-09 14:07:23 -0500152 ' $TOP_DIR/localrc
Dean Troyerdec00f62011-12-30 17:43:20 -0600153fi