Browse code

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

Dean Troyer authored on 2012/07/10 04:07:23
Showing 3 changed files
... ...
@@ -223,6 +223,24 @@ GetOSVersion() {
223 223
 }
224 224
 
225 225
 
226
+# Translate the OS version values into common nomenclature
227
+# Sets ``DISTRO`` from the ``os_*`` values
228
+function GetDistro() {
229
+    GetOSVersion
230
+    if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then
231
+        # 'Everyone' refers to Ubuntu releases by the code name adjective
232
+        DISTRO=$os_CODENAME
233
+    elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
234
+        # For Fedora, just use 'f' and the release
235
+        DISTRO="f$os_RELEASE"
236
+    else
237
+        # Catch-all for now is Vendor + Release + Update
238
+        DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
239
+    fi
240
+    export DISTRO
241
+}
242
+
243
+
226 244
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
227 245
 # be owned by the installation user, we create the directory and change the
228 246
 # ownership to the proper user.
... ...
@@ -26,19 +26,8 @@ source $TOP_DIR/functions
26 26
 
27 27
 # Determine what system we are running on.  This provides ``os_VENDOR``,
28 28
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
29
-GetOSVersion
30
-
31
-# Translate the OS version values into common nomenclature
32
-if [[ "$os_VENDOR" =~ (Ubuntu) ]]; then
33
-    # 'Everyone' refers to Ubuntu releases by the code name adjective
34
-    DISTRO=$os_CODENAME
35
-elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
36
-    # For Fedora, just use 'f' and the release
37
-    DISTRO="f$os_RELEASE"
38
-else
39
-    # Catch-all for now is Vendor + Release + Update
40
-    DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
41
-fi
29
+# and ``DISTRO``
30
+GetDistro
42 31
 
43 32
 
44 33
 # Settings
... ...
@@ -28,6 +28,9 @@ TOOLS_DIR=$(cd $(dirname "$0") && pwd)
28 28
 TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
29 29
 cd $TOP_DIR
30 30
 
31
+# Import common functions
32
+source $TOP_DIR/functions
33
+
31 34
 # Source params
32 35
 source $TOP_DIR/stackrc
33 36
 
... ...
@@ -38,6 +41,21 @@ if [[ ! -d $FILES ]]; then
38 38
     exit 1
39 39
 fi
40 40
 
41
+
42
+# OS
43
+# --
44
+
45
+# Determine what OS we're using
46
+GetDistro
47
+
48
+echo "os|distro=$DISTRO"
49
+echo "os|vendor=$os_VENDOR"
50
+echo "os|release=$os_RELEASE"
51
+if [ -n "$os_UPDATE" ]; then
52
+    echo "os|version=$os_UPDATE"
53
+fi
54
+
55
+
41 56
 # Repos
42 57
 # -----
43 58
 
... ...
@@ -62,123 +80,44 @@ for i in $DEST/*; do
62 62
     fi
63 63
 done
64 64
 
65
-# OS
66
-# --
67
-
68
-GetOSInfo() {
69
-    # Figure out which vedor we are
70
-    if [ -r /etc/lsb-release ]; then
71
-        . /etc/lsb-release
72
-        VENDORNAME=$DISTRIB_ID
73
-        RELEASE=$DISTRIB_RELEASE
74
-    else
75
-        for r in RedHat CentOS Fedora; do
76
-            VENDORPKG="`echo $r | tr [:upper:] [:lower:]`-release"
77
-            VENDORNAME=$r
78
-            RELEASE=`rpm -q --queryformat '%{VERSION}' $VENDORPKG`
79
-            if [ $? = 0 ]; then
80
-                break
81
-            fi
82
-            VENDORNAME=""
83
-        done
84
-        # Get update level
85
-        if [ -n "`grep Update /etc/redhat-release`" ]; then
86
-            # Get update
87
-            UPDATE=`cat /etc/redhat-release | sed s/.*Update\ // | sed s/\)$//`
88
-        else
89
-            # Assume update 0
90
-            UPDATE=0
91
-        fi
92
-    fi
93
-
94
-    echo "os|vendor=$VENDORNAME"
95
-    echo "os|release=$RELEASE"
96
-    if [ -n "$UPDATE" ]; then
97
-        echo "os|version=$UPDATE"
98
-    fi
99
-}
100
-
101
-GetOSInfo
102 65
 
103 66
 # Packages
104 67
 # --------
105 68
 
106 69
 # - We are going to check packages only for the services needed.
107 70
 # - We are parsing the packages files and detecting metadatas.
108
-#  - If we have the meta-keyword dist:DISTRO or
109
-#    dist:DISTRO1,DISTRO2 it will be installed only for those
110
-#    distros (case insensitive).
111
-function get_packages() {
112
-    local file_to_parse="general"
113
-    local service
114
-
115
-    for service in ${ENABLED_SERVICES//,/ }; do
116
-        # Allow individual services to specify dependencies
117
-        if [[ -e $FILES/apts/${service} ]]; then
118
-            file_to_parse="${file_to_parse} $service"
119
-        fi
120
-        if [[ $service == n-* ]]; then
121
-            if [[ ! $file_to_parse =~ nova ]]; then
122
-                file_to_parse="${file_to_parse} nova"
123
-            fi
124
-        elif [[ $service == g-* ]]; then
125
-            if [[ ! $file_to_parse =~ glance ]]; then
126
-                file_to_parse="${file_to_parse} glance"
127
-            fi
128
-        elif [[ $service == key* ]]; then
129
-            if [[ ! $file_to_parse =~ keystone ]]; then
130
-                file_to_parse="${file_to_parse} keystone"
131
-            fi
132
-        fi
133
-    done
134
-
135
-    for file in ${file_to_parse}; do
136
-        local fname=${FILES}/apts/${file}
137
-        local OIFS line package distros distro
138
-        [[ -e $fname ]] || { echo "missing: $fname"; exit 1; }
139
-
140
-        OIFS=$IFS
141
-        IFS=$'\n'
142
-        for line in $(<${fname}); do
143
-            if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then # We are using BASH regexp matching feature.
144
-                        package=${BASH_REMATCH[1]}
145
-                        distros=${BASH_REMATCH[2]}
146
-                        for distro in ${distros//,/ }; do  #In bash ${VAR,,} will lowecase VAR
147
-                            [[ ${distro,,} == ${DISTRO,,} ]] && echo $package
148
-                        done
149
-                        continue
150
-            fi
151
-
152
-            echo ${line%#*}
153
-        done
154
-        IFS=$OIFS
155
-    done
156
-}
157 71
 
158
-for p in $(get_packages); do
159
-    ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
72
+if [[ "$os_PACKAGE" = "deb" ]]; then
73
+    PKG_DIR=$FILES/apts
74
+else
75
+    PKG_DIR=$FILES/rpms
76
+fi
77
+
78
+for p in $(get_packages $PKG_DIR); do
79
+    if [[ "$os_PACKAGE" = "deb" ]]; then
80
+        ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
81
+    else
82
+        ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
83
+    fi
160 84
     echo "pkg|${p}|${ver}"
161 85
 done
162 86
 
87
+
163 88
 # Pips
164 89
 # ----
165 90
 
166
-function get_pips() {
167
-    cat $FILES/pips/* | uniq
168
-}
91
+if [[ "$os_PACKAGE" = "deb" ]]; then
92
+    CMD_PIP=/usr/bin/pip
93
+else
94
+    CMD_PIP=/usr/bin/pip-python
95
+fi
169 96
 
170 97
 # Pip tells us what is currently installed
171 98
 FREEZE_FILE=$(mktemp --tmpdir freeze.XXXXXX)
172
-pip freeze >$FREEZE_FILE 2>/dev/null
99
+$CMD_PIP freeze >$FREEZE_FILE 2>/dev/null
173 100
 
174 101
 # Loop through our requirements and look for matches
175
-for p in $(get_pips); do
176
-    [[ "$p" = "-e" ]] && continue
177
-    if [[ "$p" =~ \+?([^#]*)#? ]]; then
178
-         # Get the URL from a remote reference
179
-         p=${BASH_REMATCH[1]}
180
-    fi
181
-    line="`grep -i $p $FREEZE_FILE`"
102
+while read line; do
182 103
     if [[ -n "$line" ]]; then
183 104
         if [[ "$line" =~ \+(.*)@(.*)#egg=(.*) ]]; then
184 105
             # Handle URLs
... ...
@@ -199,10 +138,11 @@ for p in $(get_pips); do
199 199
         #echo "unknown: $p"
200 200
         continue
201 201
     fi
202
-done
202
+done <$FREEZE_FILE
203 203
 
204 204
 rm $FREEZE_FILE
205 205
 
206
+
206 207
 # localrc
207 208
 # -------
208 209
 
... ...
@@ -212,5 +152,5 @@ if [[ -r $TOP_DIR/localrc ]]; then
212 212
         /PASSWORD/d;
213 213
         /^#/d;
214 214
         s/^/localrc\|/;
215
-    ' $TOP_DIR/localrc | sort
215
+    ' $TOP_DIR/localrc
216 216
 fi