From a9e0a488cf72431aabc972f7aac76abb56aaba02 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 9 Jul 2012 14:07:23 -0500 Subject: [PATCH] Update info.sh * Works properly on Fedora 17 now, possibly other RPM-based distros * Add GetDistro() function taken from logic in stack.sh * Source functions in tools/info.sh * Use GetDistro() and get_packages() in tools/info.sh * Report all installed pips * Don't sort localrc output as order is important Change-Id: I1b3e48e94786378c7313a0a6bea88d5cf9d0f0c0 --- functions | 18 +++++++ stack.sh | 15 +----- tools/info.sh | 140 +++++++++++++++----------------------------------- 3 files changed, 60 insertions(+), 113 deletions(-) diff --git a/functions b/functions index 8cf7c74b6b..db104633ba 100644 --- a/functions +++ b/functions @@ -223,6 +223,24 @@ GetOSVersion() { } +# Translate the OS version values into common nomenclature +# Sets ``DISTRO`` from the ``os_*`` values +function GetDistro() { + GetOSVersion + if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then + # 'Everyone' refers to Ubuntu releases by the code name adjective + DISTRO=$os_CODENAME + elif [[ "$os_VENDOR" =~ (Fedora) ]]; then + # For Fedora, just use 'f' and the release + DISTRO="f$os_RELEASE" + else + # Catch-all for now is Vendor + Release + Update + DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE" + fi + export DISTRO +} + + # git clone only if directory doesn't exist already. Since ``DEST`` might not # be owned by the installation user, we create the directory and change the # ownership to the proper user. diff --git a/stack.sh b/stack.sh index 513f8be4a1..ebeec52f1e 100755 --- a/stack.sh +++ b/stack.sh @@ -26,19 +26,8 @@ source $TOP_DIR/functions # Determine what system we are running on. This provides ``os_VENDOR``, # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` -GetOSVersion - -# Translate the OS version values into common nomenclature -if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then - # 'Everyone' refers to Ubuntu releases by the code name adjective - DISTRO=$os_CODENAME -elif [[ "$os_VENDOR" =~ (Fedora) ]]; then - # For Fedora, just use 'f' and the release - DISTRO="f$os_RELEASE" -else - # Catch-all for now is Vendor + Release + Update - DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE" -fi +# and ``DISTRO`` +GetDistro # Settings diff --git a/tools/info.sh b/tools/info.sh index bdca06e8a3..bf40e827d5 100755 --- a/tools/info.sh +++ b/tools/info.sh @@ -28,6 +28,9 @@ TOOLS_DIR=$(cd $(dirname "$0") && pwd) TOP_DIR=$(cd $TOOLS_DIR/..; pwd) cd $TOP_DIR +# Import common functions +source $TOP_DIR/functions + # Source params source $TOP_DIR/stackrc @@ -38,6 +41,21 @@ if [[ ! -d $FILES ]]; then exit 1 fi + +# OS +# -- + +# Determine what OS we're using +GetDistro + +echo "os|distro=$DISTRO" +echo "os|vendor=$os_VENDOR" +echo "os|release=$os_RELEASE" +if [ -n "$os_UPDATE" ]; then + echo "os|version=$os_UPDATE" +fi + + # Repos # ----- @@ -62,123 +80,44 @@ for i in $DEST/*; do fi done -# OS -# -- - -GetOSInfo() { - # Figure out which vedor we are - if [ -r /etc/lsb-release ]; then - . /etc/lsb-release - VENDORNAME=$DISTRIB_ID - RELEASE=$DISTRIB_RELEASE - else - for r in RedHat CentOS Fedora; do - VENDORPKG="`echo $r | tr [:upper:] [:lower:]`-release" - VENDORNAME=$r - RELEASE=`rpm -q --queryformat '%{VERSION}' $VENDORPKG` - if [ $? = 0 ]; then - break - fi - VENDORNAME="" - done - # Get update level - if [ -n "`grep Update /etc/redhat-release`" ]; then - # Get update - UPDATE=`cat /etc/redhat-release | sed s/.*Update\ // | sed s/\)$//` - else - # Assume update 0 - UPDATE=0 - fi - fi - - echo "os|vendor=$VENDORNAME" - echo "os|release=$RELEASE" - if [ -n "$UPDATE" ]; then - echo "os|version=$UPDATE" - fi -} - -GetOSInfo # Packages # -------- # - We are going to check packages only for the services needed. # - We are parsing the packages files and detecting metadatas. -# - If we have the meta-keyword dist:DISTRO or -# dist:DISTRO1,DISTRO2 it will be installed only for those -# distros (case insensitive). -function get_packages() { - local file_to_parse="general" - local service - for service in ${ENABLED_SERVICES//,/ }; do - # Allow individual services to specify dependencies - if [[ -e $FILES/apts/${service} ]]; then - file_to_parse="${file_to_parse} $service" - fi - if [[ $service == n-* ]]; then - if [[ ! $file_to_parse =~ nova ]]; then - file_to_parse="${file_to_parse} nova" - fi - elif [[ $service == g-* ]]; then - if [[ ! $file_to_parse =~ glance ]]; then - file_to_parse="${file_to_parse} glance" - fi - elif [[ $service == key* ]]; then - if [[ ! $file_to_parse =~ keystone ]]; then - file_to_parse="${file_to_parse} keystone" - fi - fi - done +if [[ "$os_PACKAGE" = "deb" ]]; then + PKG_DIR=$FILES/apts +else + PKG_DIR=$FILES/rpms +fi - for file in ${file_to_parse}; do - local fname=${FILES}/apts/${file} - local OIFS line package distros distro - [[ -e $fname ]] || { echo "missing: $fname"; exit 1; } - - OIFS=$IFS - IFS=$'\n' - for line in $(<${fname}); do - if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then # We are using BASH regexp matching feature. - package=${BASH_REMATCH[1]} - distros=${BASH_REMATCH[2]} - for distro in ${distros//,/ }; do #In bash ${VAR,,} will lowecase VAR - [[ ${distro,,} == ${DISTRO,,} ]] && echo $package - done - continue - fi - - echo ${line%#*} - done - IFS=$OIFS - done -} - -for p in $(get_packages); do - ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) +for p in $(get_packages $PKG_DIR); do + if [[ "$os_PACKAGE" = "deb" ]]; then + ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) + else + ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p) + fi echo "pkg|${p}|${ver}" done + # Pips # ---- -function get_pips() { - cat $FILES/pips/* | uniq -} +if [[ "$os_PACKAGE" = "deb" ]]; then + CMD_PIP=/usr/bin/pip +else + CMD_PIP=/usr/bin/pip-python +fi # Pip tells us what is currently installed FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX) -pip freeze >$FREEZE_FILE 2>/dev/null +$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null # Loop through our requirements and look for matches -for p in $(get_pips); do - [[ "$p" = "-e" ]] && continue - if [[ "$p" =~ \+?([^#]*)#? ]]; then - # Get the URL from a remote reference - p=${BASH_REMATCH[1]} - fi - line="`grep -i $p $FREEZE_FILE`" +while read line; do if [[ -n "$line" ]]; then if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then # Handle URLs @@ -199,10 +138,11 @@ for p in $(get_pips); do #echo "unknown: $p" continue fi -done +done <$FREEZE_FILE rm $FREEZE_FILE + # localrc # ------- @@ -212,5 +152,5 @@ if [[ -r $TOP_DIR/localrc ]]; then /PASSWORD/d; /^#/d; s/^/localrc\|/; - ' $TOP_DIR/localrc | sort + ' $TOP_DIR/localrc fi