blob: 282667f9d05f2a849c387f59d67ea52e6250bc08 [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
Dean Troyerdc97cb72015-03-28 08:20:50 -05005# 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>]
Chris Dent85ad1082016-08-22 17:00:50 +000011# localrc|<var>=<value>
Dean Troyerdec00f62011-12-30 17:43:20 -060012# os|<var>=<value>
13# pip|<package>|<version>
14# pkg|<package>|<version>
15
16function usage {
Dean Troyerdc97cb72015-03-28 08:20:50 -050017 echo "$0 - Report on the DevStack configuration"
Dean Troyerdec00f62011-12-30 17:43:20 -060018 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"
Dean Troyera9e0a482012-07-09 14:07:23 -050055
Dean Troyerdec00f62011-12-30 17:43:20 -060056# Repos
57# -----
58
59# git_report <dir>
Ian Wienandaee18c72014-02-21 15:35:08 +110060function git_report {
Dean Troyerdec00f62011-12-30 17:43:20 -060061 local dir=$1
62 local proj ref branch head
63 if [[ -d $dir/.git ]]; then
64 pushd $dir >/dev/null
65 proj=$(basename $dir)
66 ref=$(git symbolic-ref HEAD)
67 branch=${ref##refs/heads/}
68 head=$(git show-branch --sha1-name $branch | cut -d' ' -f1)
69 echo "git|${proj}|${branch}${head}"
70 popd >/dev/null
71 fi
72}
73
74for i in $DEST/*; do
75 if [[ -d $i ]]; then
76 git_report $i
77 fi
78done
79
Dean Troyerdec00f62011-12-30 17:43:20 -060080
81# Packages
82# --------
83
Dean Troyerd2bcbea2014-01-13 11:22:41 -060084# - Only check packages for the services enabled
85# - Parse version info from the package metadata, not the package/file names
Dean Troyerdec00f62011-12-30 17:43:20 -060086
Isaku Yamahata8c438092013-02-12 22:30:56 +090087for p in $(get_packages $ENABLED_SERVICES); do
Dean Troyera9e0a482012-07-09 14:07:23 -050088 if [[ "$os_PACKAGE" = "deb" ]]; then
89 ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
Vincent Untz00011c02012-12-06 09:56:32 +010090 elif [[ "$os_PACKAGE" = "rpm" ]]; then
Dean Troyera9e0a482012-07-09 14:07:23 -050091 ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
Vincent Untz00011c02012-12-06 09:56:32 +010092 else
93 exit_distro_not_supported "finding version of a package"
Dean Troyera9e0a482012-07-09 14:07:23 -050094 fi
Dean Troyerdec00f62011-12-30 17:43:20 -060095 echo "pkg|${p}|${ver}"
96done
97
Dean Troyera9e0a482012-07-09 14:07:23 -050098
Dean Troyerdec00f62011-12-30 17:43:20 -060099# Pips
100# ----
101
Vincent Untz8ec27222012-11-29 09:25:31 +0100102CMD_PIP=$(get_pip_command)
Dean Troyerdec00f62011-12-30 17:43:20 -0600103
104# Pip tells us what is currently installed
105FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
Dean Troyera9e0a482012-07-09 14:07:23 -0500106$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
Dean Troyerdec00f62011-12-30 17:43:20 -0600107
108# Loop through our requirements and look for matches
Dean Troyera9e0a482012-07-09 14:07:23 -0500109while read line; do
Dean Troyerdec00f62011-12-30 17:43:20 -0600110 if [[ -n "$line" ]]; then
111 if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
112 # Handle URLs
113 p=${BASH_REMATCH[1]}
114 ver=${BASH_REMATCH[2]}
115 elif [[ "$line" =~ (.*)[=\<\>]=(.*) ]]; then
116 # Normal pip packages
117 p=${BASH_REMATCH[1]}
118 ver=${BASH_REMATCH[2]}
119 else
120 # Unhandled format in freeze file
Dean Troyerdec00f62011-12-30 17:43:20 -0600121 continue
122 fi
123 echo "pip|${p}|${ver}"
124 else
125 # No match in freeze file
Dean Troyerdec00f62011-12-30 17:43:20 -0600126 continue
127 fi
Dean Troyera9e0a482012-07-09 14:07:23 -0500128done <$FREEZE_FILE
Dean Troyerdec00f62011-12-30 17:43:20 -0600129
130rm $FREEZE_FILE
131
Dean Troyera9e0a482012-07-09 14:07:23 -0500132
Dean Troyerdec00f62011-12-30 17:43:20 -0600133# localrc
134# -------
135
136# Dump localrc with 'localrc|' prepended and comments and passwords left out
137if [[ -r $TOP_DIR/localrc ]]; then
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600138 RC=$TOP_DIR/localrc
139elif [[ -f $RC_DIR/.localrc.auto ]]; then
140 RC=$TOP_DIR/.localrc.auto
141fi
142if [[ -n $RC ]]; then
Dean Troyerdec00f62011-12-30 17:43:20 -0600143 sed -e '
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600144 /^[ \t]*$/d;
145 /PASSWORD/s/=.*$/=\<password\>/;
Dean Troyerdec00f62011-12-30 17:43:20 -0600146 /^#/d;
147 s/^/localrc\|/;
Dean Troyerd2bcbea2014-01-13 11:22:41 -0600148 ' $RC
Dean Troyerdec00f62011-12-30 17:43:20 -0600149fi