| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
| Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 2 |  | 
 | 3 | # **info.sh** | 
 | 4 |  | 
 | 5 | # Produce a report on the state of devstack installs | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 6 | # | 
 | 7 | # Output fields are separated with '|' chars | 
 | 8 | # Output types are git,localrc,os,pip,pkg: | 
| Dean Troyer | c5dfecd | 2012-09-08 14:20:43 -0500 | [diff] [blame] | 9 | # | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 10 | #   git|<project>|<branch>[<shaq>] | 
 | 11 | #   localtc|<var>=<value> | 
 | 12 | #   os|<var>=<value> | 
 | 13 | #   pip|<package>|<version> | 
 | 14 | #   pkg|<package>|<version> | 
 | 15 |  | 
 | 16 | function usage { | 
 | 17 |     echo "$0 - Report on the devstack configuration" | 
 | 18 |     echo "" | 
 | 19 |     echo "Usage: $0" | 
 | 20 |     exit 1 | 
 | 21 | } | 
 | 22 |  | 
 | 23 | if [ "$1" = "-h" ]; then | 
 | 24 |     usage | 
 | 25 | fi | 
 | 26 |  | 
 | 27 | # Keep track of the current directory | 
 | 28 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) | 
 | 29 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) | 
 | 30 | cd $TOP_DIR | 
 | 31 |  | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 32 | # Import common functions | 
 | 33 | source $TOP_DIR/functions | 
 | 34 |  | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 35 | # Source params | 
 | 36 | source $TOP_DIR/stackrc | 
 | 37 |  | 
 | 38 | DEST=${DEST:-/opt/stack} | 
 | 39 | FILES=$TOP_DIR/files | 
 | 40 | if [[ ! -d $FILES ]]; then | 
 | 41 |     echo "ERROR: missing devstack/files - did you grab more than just stack.sh?" | 
 | 42 |     exit 1 | 
 | 43 | fi | 
 | 44 |  | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 45 |  | 
 | 46 | # OS | 
 | 47 | # -- | 
 | 48 |  | 
 | 49 | # Determine what OS we're using | 
 | 50 | GetDistro | 
 | 51 |  | 
 | 52 | echo "os|distro=$DISTRO" | 
 | 53 | echo "os|vendor=$os_VENDOR" | 
 | 54 | echo "os|release=$os_RELEASE" | 
 | 55 | if [ -n "$os_UPDATE" ]; then | 
 | 56 |     echo "os|version=$os_UPDATE" | 
 | 57 | fi | 
 | 58 |  | 
 | 59 |  | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 60 | # Repos | 
 | 61 | # ----- | 
 | 62 |  | 
 | 63 | # git_report <dir> | 
 | 64 | function 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 |  | 
 | 78 | for i in $DEST/*; do | 
 | 79 |     if [[ -d $i ]]; then | 
 | 80 |         git_report $i | 
 | 81 |     fi | 
 | 82 | done | 
 | 83 |  | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 84 |  | 
 | 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 Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 90 |  | 
| Isaku Yamahata | 8c43809 | 2013-02-12 22:30:56 +0900 | [diff] [blame] | 91 | for p in $(get_packages $ENABLED_SERVICES); do | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 92 |     if [[ "$os_PACKAGE" = "deb" ]]; then | 
 | 93 |         ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 94 |     elif [[ "$os_PACKAGE" = "rpm" ]]; then | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 95 |         ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p) | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 96 |     else | 
 | 97 |         exit_distro_not_supported "finding version of a package" | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 98 |     fi | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 99 |     echo "pkg|${p}|${ver}" | 
 | 100 | done | 
 | 101 |  | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 102 |  | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 103 | # Pips | 
 | 104 | # ---- | 
 | 105 |  | 
| Vincent Untz | 8ec2722 | 2012-11-29 09:25:31 +0100 | [diff] [blame] | 106 | CMD_PIP=$(get_pip_command) | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 107 |  | 
 | 108 | # Pip tells us what is currently installed | 
 | 109 | FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX) | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 110 | $CMD_PIP freeze >$FREEZE_FILE 2>/dev/null | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 111 |  | 
 | 112 | # Loop through our requirements and look for matches | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 113 | while read line; do | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 114 |     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 | 
 | 125 |             #echo "unknown: $p" | 
 | 126 |             continue | 
 | 127 |         fi | 
 | 128 |         echo "pip|${p}|${ver}" | 
 | 129 |     else | 
 | 130 |         # No match in freeze file | 
 | 131 |         #echo "unknown: $p" | 
 | 132 |         continue | 
 | 133 |     fi | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 134 | done <$FREEZE_FILE | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 135 |  | 
 | 136 | rm $FREEZE_FILE | 
 | 137 |  | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 138 |  | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 139 | # localrc | 
 | 140 | # ------- | 
 | 141 |  | 
 | 142 | # Dump localrc with 'localrc|' prepended and comments and passwords left out | 
 | 143 | if [[ -r $TOP_DIR/localrc ]]; then | 
 | 144 |     sed -e ' | 
 | 145 |         /PASSWORD/d; | 
 | 146 |         /^#/d; | 
 | 147 |         s/^/localrc\|/; | 
| Dean Troyer | a9e0a48 | 2012-07-09 14:07:23 -0500 | [diff] [blame] | 148 |     ' $TOP_DIR/localrc | 
| Dean Troyer | dec00f6 | 2011-12-30 17:43:20 -0600 | [diff] [blame] | 149 | fi |