blob: ef1f3380e271703c02a3878789ec0b305a12e400 [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
Vincent Untzc18b9652012-12-04 12:36:34 +010091if is_ubuntu; then
Dean Troyera9e0a482012-07-09 14:07:23 -050092 PKG_DIR=$FILES/apts
Vincent Untz00011c02012-12-06 09:56:32 +010093elif is_fedora; then
Dean Troyera9e0a482012-07-09 14:07:23 -050094 PKG_DIR=$FILES/rpms
Vincent Untzf2a18c02012-12-04 18:34:25 +010095elif is_suse; then
96 PKG_DIR=$FILES/rpms-suse
Vincent Untz00011c02012-12-06 09:56:32 +010097else
98 exit_distro_not_supported "list of packages"
Dean Troyera9e0a482012-07-09 14:07:23 -050099fi
Dean Troyerdec00f62011-12-30 17:43:20 -0600100
Dean Troyera9e0a482012-07-09 14:07:23 -0500101for p in $(get_packages $PKG_DIR); do
102 if [[ "$os_PACKAGE" = "deb" ]]; then
103 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
Vincent Untz00011c02012-12-06 09:56:32 +0100104 elif [[ "$os_PACKAGE" = "rpm" ]]; then
Dean Troyera9e0a482012-07-09 14:07:23 -0500105 ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
Vincent Untz00011c02012-12-06 09:56:32 +0100106 else
107 exit_distro_not_supported "finding version of a package"
Dean Troyera9e0a482012-07-09 14:07:23 -0500108 fi
Dean Troyerdec00f62011-12-30 17:43:20 -0600109 echo "pkg|${p}|${ver}"
110done
111
Dean Troyera9e0a482012-07-09 14:07:23 -0500112
Dean Troyerdec00f62011-12-30 17:43:20 -0600113# Pips
114# ----
115
Vincent Untz8ec27222012-11-29 09:25:31 +0100116CMD_PIP=$(get_pip_command)
Dean Troyerdec00f62011-12-30 17:43:20 -0600117
118# Pip tells us what is currently installed
119FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
Dean Troyera9e0a482012-07-09 14:07:23 -0500120$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
Dean Troyerdec00f62011-12-30 17:43:20 -0600121
122# Loop through our requirements and look for matches
Dean Troyera9e0a482012-07-09 14:07:23 -0500123while read line; do
Dean Troyerdec00f62011-12-30 17:43:20 -0600124 if [[ -n "$line" ]]; then
125 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
126 # Handle URLs
127 p=${BASH_REMATCH[1]}
128 ver=${BASH_REMATCH[2]}
129 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
130 # Normal pip packages
131 p=${BASH_REMATCH[1]}
132 ver=${BASH_REMATCH[2]}
133 else
134 # Unhandled format in freeze file
135 #echo "unknown: $p"
136 continue
137 fi
138 echo "pip|${p}|${ver}"
139 else
140 # No match in freeze file
141 #echo "unknown: $p"
142 continue
143 fi
Dean Troyera9e0a482012-07-09 14:07:23 -0500144done <$FREEZE_FILE
Dean Troyerdec00f62011-12-30 17:43:20 -0600145
146rm $FREEZE_FILE
147
Dean Troyera9e0a482012-07-09 14:07:23 -0500148
Dean Troyerdec00f62011-12-30 17:43:20 -0600149# localrc
150# -------
151
152# Dump localrc with 'localrc|' prepended and comments and passwords left out
153if [[ -r $TOP_DIR/localrc ]]; then
154 sed -e '
155 /PASSWORD/d;
156 /^#/d;
157 s/^/localrc\|/;
Dean Troyera9e0a482012-07-09 14:07:23 -0500158 ' $TOP_DIR/localrc
Dean Troyerdec00f62011-12-30 17:43:20 -0600159fi