blob: 1e521b9c4b76d5a515e9b4bcb566c29dd203d856 [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
Dean Troyerd2bcbea2014-01-13 11:22:41 -060088# - Only check packages for the services enabled
89# - Parse version info from the package metadata, not the package/file names
Dean Troyerdec00f62011-12-30 17:43:20 -060090
Isaku Yamahata8c438092013-02-12 22:30:56 +090091for p in $(get_packages $ENABLED_SERVICES); do
Dean Troyera9e0a482012-07-09 14:07:23 -050092 if [[ "$os_PACKAGE" = "deb" ]]; then
93 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
Vincent Untz00011c02012-12-06 09:56:32 +010094 elif [[ "$os_PACKAGE" = "rpm" ]]; then
Dean Troyera9e0a482012-07-09 14:07:23 -050095 ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
Vincent Untz00011c02012-12-06 09:56:32 +010096 else
97 exit_distro_not_supported "finding version of a package"
Dean Troyera9e0a482012-07-09 14:07:23 -050098 fi
Dean Troyerdec00f62011-12-30 17:43:20 -060099 echo "pkg|${p}|${ver}"
100done
101
Dean Troyera9e0a482012-07-09 14:07:23 -0500102
Dean Troyerdec00f62011-12-30 17:43:20 -0600103# Pips
104# ----
105
Vincent Untz8ec27222012-11-29 09:25:31 +0100106CMD_PIP=$(get_pip_command)
Dean Troyerdec00f62011-12-30 17:43:20 -0600107
108# Pip tells us what is currently installed
109FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
Dean Troyera9e0a482012-07-09 14:07:23 -0500110$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
Dean Troyerdec00f62011-12-30 17:43:20 -0600111
112# Loop through our requirements and look for matches
Dean Troyera9e0a482012-07-09 14:07:23 -0500113while read line; do
Dean Troyerdec00f62011-12-30 17:43:20 -0600114 if [[ -n "$line" ]]; then
115 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
116 # Handle URLs
117 p=${BASH_REMATCH[1]}
118 ver=${BASH_REMATCH[2]}
119 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
120 # Normal pip packages
121 p=${BASH_REMATCH[1]}
122 ver=${BASH_REMATCH[2]}
123 else
124 # Unhandled format in freeze file
Dean Troyerdec00f62011-12-30 17:43:20 -0600125 continue
126 fi
127 echo "pip|${p}|${ver}"
128 else
129 # No match in freeze file
Dean Troyerdec00f62011-12-30 17:43:20 -0600130 continue
131 fi
Dean Troyera9e0a482012-07-09 14:07:23 -0500132done <$FREEZE_FILE
Dean Troyerdec00f62011-12-30 17:43:20 -0600133
134rm $FREEZE_FILE
135
Dean Troyera9e0a482012-07-09 14:07:23 -0500136
Dean Troyerdec00f62011-12-30 17:43:20 -0600137# localrc
138# -------
139
140# Dump localrc with 'localrc|' prepended and comments and passwords left out
141if [[ -r $TOP_DIR/localrc ]]; then
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600142 RC=$TOP_DIR/localrc
143elif [[ -f $RC_DIR/.localrc.auto ]]; then
144 RC=$TOP_DIR/.localrc.auto
145fi
146if [[ -n $RC ]]; then
Dean Troyerdec00f62011-12-30 17:43:20 -0600147 sed -e '
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600148 /^[ \t]*$/d;
149 /PASSWORD/s/=.*$/=\<password\>/;
Dean Troyerdec00f62011-12-30 17:43:20 -0600150 /^#/d;
151 s/^/localrc\|/;
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600152 ' $RC
Dean Troyerdec00f62011-12-30 17:43:20 -0600153fi