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
This commit is contained in:
Dean Troyer 2012-07-09 14:07:23 -05:00
parent 08bc3048b1
commit a9e0a488cf
3 changed files with 60 additions and 113 deletions

View File

@ -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 # 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 # be owned by the installation user, we create the directory and change the
# ownership to the proper user. # ownership to the proper user.

View File

@ -26,19 +26,8 @@ source $TOP_DIR/functions
# Determine what system we are running on. This provides ``os_VENDOR``, # Determine what system we are running on. This provides ``os_VENDOR``,
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
GetOSVersion # and ``DISTRO``
GetDistro
# 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
# Settings # Settings

View File

@ -28,6 +28,9 @@ TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $TOOLS_DIR/..; pwd) TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
cd $TOP_DIR cd $TOP_DIR
# Import common functions
source $TOP_DIR/functions
# Source params # Source params
source $TOP_DIR/stackrc source $TOP_DIR/stackrc
@ -38,6 +41,21 @@ if [[ ! -d $FILES ]]; then
exit 1 exit 1
fi 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 # Repos
# ----- # -----
@ -62,123 +80,44 @@ for i in $DEST/*; do
fi fi
done 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 # Packages
# -------- # --------
# - We are going to check packages only for the services needed. # - We are going to check packages only for the services needed.
# - We are parsing the packages files and detecting metadatas. # - 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 if [[ "$os_PACKAGE" = "deb" ]]; then
# Allow individual services to specify dependencies PKG_DIR=$FILES/apts
if [[ -e $FILES/apts/${service} ]]; then else
file_to_parse="${file_to_parse} $service" PKG_DIR=$FILES/rpms
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
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 fi
echo ${line%#*} for p in $(get_packages $PKG_DIR); do
done if [[ "$os_PACKAGE" = "deb" ]]; then
IFS=$OIFS
done
}
for p in $(get_packages); do
ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2) 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}" echo "pkg|${p}|${ver}"
done done
# Pips # Pips
# ---- # ----
function get_pips() { if [[ "$os_PACKAGE" = "deb" ]]; then
cat $FILES/pips/* | uniq CMD_PIP=/usr/bin/pip
} else
CMD_PIP=/usr/bin/pip-python
fi
# Pip tells us what is currently installed # Pip tells us what is currently installed
FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX) 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 # Loop through our requirements and look for matches
for p in $(get_pips); do while read line; 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`"
if [[ -n "$line" ]]; then if [[ -n "$line" ]]; then
if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
# Handle URLs # Handle URLs
@ -199,10 +138,11 @@ for p in $(get_pips); do
#echo "unknown: $p" #echo "unknown: $p"
continue continue
fi fi
done done <$FREEZE_FILE
rm $FREEZE_FILE rm $FREEZE_FILE
# localrc # localrc
# ------- # -------
@ -212,5 +152,5 @@ if [[ -r $TOP_DIR/localrc ]]; then
/PASSWORD/d; /PASSWORD/d;
/^#/d; /^#/d;
s/^/localrc\|/; s/^/localrc\|/;
' $TOP_DIR/localrc | sort ' $TOP_DIR/localrc
fi fi