Browse code

Merge pull request #184 from chmouel/install-packages-only-for-services-distros

Install packages only for services distros

Jesse Andrews authored on 2011/11/16 06:17:21
Showing 2 changed files
... ...
@@ -1,5 +1,5 @@
1 1
 dnsmasq-base
2
-dnsmasq-utils # for dhcp_release
2
+dnsmasq-utils # for dhcp_release only available in dist:oneiric
3 3
 kpartx
4 4
 parted
5 5
 arping # used for send_arp_for_ha option in nova-network
... ...
@@ -22,7 +22,9 @@
22 22
 
23 23
 # Warn users who aren't on natty, but allow them to override check and attempt
24 24
 # installation with ``FORCE=yes ./stack``
25
-if ! egrep -q 'natty|oneiric' /etc/lsb-release; then
25
+DISTRO=$(lsb_release -c -s)
26
+
27
+if [[ ! ${DISTRO} =~ (natty|oneiric) ]]; then
26 28
     echo "WARNING: this script has only been tested on natty and oneiric"
27 29
     if [[ "$FORCE" != "yes" ]]; then
28 30
         echo "If you wish to run this script anyway run with FORCE=yes"
... ...
@@ -372,10 +374,65 @@ fi
372 372
 #
373 373
 # Openstack uses a fair number of other projects.
374 374
 
375
+# - We are going to install packages only for the services needed.
376
+# - We are parsing the packages files and detecting metadatas.
377
+#  - If there is a NOPRIME as comment mean we are not doing the install
378
+#    just yet.
379
+#  - If we have the meta-keyword distro:DISTRO or
380
+#    distro:DISTRO1,DISTRO2 it will be installed only for those
381
+#    distros (case insensitive).
382
+function get_packages() {
383
+    local file_to_parse="general"
384
+    local service
385
+    
386
+    for service in ${ENABLED_SERVICES//,/ }; do
387
+        if [[ $service == n-* ]]; then
388
+            if [[ ! $file_to_parse =~ nova ]]; then
389
+                file_to_parse="${file_to_parse} nova"
390
+            fi
391
+        elif [[ $service == g-* ]]; then
392
+            if [[ ! $file_to_parse =~ glance ]]; then
393
+                file_to_parse="${file_to_parse} glance"
394
+            fi
395
+        elif [[ $service == key* ]]; then
396
+            if [[ ! $file_to_parse =~ keystone ]]; then
397
+                file_to_parse="${file_to_parse} keystone"
398
+            fi
399
+        elif [[ -e $FILES/apts/${service} ]]; then
400
+            file_to_parse="${file_to_parse} $service"
401
+        fi
402
+    done
403
+
404
+    for file in ${file_to_parse}; do
405
+        local fname=${FILES}/apts/${file}
406
+        local OIFS line package distros distro
407
+        [[ -e $fname ]] || { echo "missing: $fname"; exit 1 ;}
408
+
409
+        OIFS=$IFS
410
+        IFS=$'\n'
411
+        for line in $(<${fname}); do
412
+            if [[ $line =~ "NOPRIME" ]]; then
413
+                continue
414
+            fi
415
+
416
+            if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then # We are using BASH regexp matching feature.
417
+                        package=${BASH_REMATCH[1]}
418
+                        distros=${BASH_REMATCH[2]}
419
+                        for distro in ${distros//,/ }; do  #In bash ${VAR,,} will lowecase VAR
420
+                            [[ ${distro,,} == ${DISTRO,,} ]] && echo $package
421
+                        done
422
+                        continue
423
+            fi
424
+
425
+            echo ${line%#*}
426
+        done
427
+        IFS=$OIFS
428
+    done
429
+}
375 430
 
376 431
 # install apt requirements
377 432
 apt_get update
378
-apt_get install `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server|memcached"`
433
+apt_get install $(get_packages)
379 434
 
380 435
 # install python requirements
381 436
 sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors `cat $FILES/pips/*`
... ...
@@ -689,7 +746,7 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
689 689
     sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_LOCATION}/drives
690 690
 
691 691
     # We then create a loopback disk and format it to XFS.
692
-    if [[ ! -e ${SWIFT_DATA_LOCATION}/drives/images/swift.img ]];then
692
+    if [[ ! -e ${SWIFT_DATA_LOCATION}/drives/images/swift.img ]]; then
693 693
         mkdir -p  ${SWIFT_DATA_LOCATION}/drives/images
694 694
         sudo touch  ${SWIFT_DATA_LOCATION}/drives/images/swift.img
695 695
         sudo chown $USER: ${SWIFT_DATA_LOCATION}/drives/images/swift.img
... ...
@@ -702,7 +759,7 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
702 702
     # After the drive being created we mount the disk with a few mount
703 703
     # options to make it most efficient as possible for swift.
704 704
     mkdir -p ${SWIFT_DATA_LOCATION}/drives/sdb1
705
-    if ! egrep -q ${SWIFT_DATA_LOCATION}/drives/sdb1 /proc/mounts;then
705
+    if ! egrep -q ${SWIFT_DATA_LOCATION}/drives/sdb1 /proc/mounts; then
706 706
         sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8  \
707 707
             ${SWIFT_DATA_LOCATION}/drives/images/swift.img ${SWIFT_DATA_LOCATION}/drives/sdb1
708 708
     fi
... ...
@@ -716,7 +773,7 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
716 716
     tmpd=""
717 717
     for d in ${SWIFT_DATA_LOCATION}/drives/sdb1/{1..4} \
718 718
         ${SWIFT_CONFIG_LOCATION}/{object,container,account}-server \
719
-        ${SWIFT_DATA_LOCATION}/{1..4}/node/sdb1 /var/run/swift ;do
719
+        ${SWIFT_DATA_LOCATION}/{1..4}/node/sdb1 /var/run/swift; do
720 720
         [[ -d $d ]] && continue
721 721
         sudo install -o ${USER} -g $USER_GROUP -d $d
722 722
     done
... ...
@@ -770,7 +827,7 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
770 770
        local log_facility=$3
771 771
        local node_number
772 772
 
773
-       for node_number in {1..4};do
773
+       for node_number in {1..4}; do
774 774
            node_path=${SWIFT_DATA_LOCATION}/${node_number}
775 775
            sed -e "s,%SWIFT_CONFIG_LOCATION%,${SWIFT_CONFIG_LOCATION},;s,%USER%,$USER,;s,%NODE_PATH%,${node_path},;s,%BIND_PORT%,${bind_port},;s,%LOG_FACILITY%,${log_facility}," \
776 776
                $FILES/swift/${server_type}-server.conf > ${SWIFT_CONFIG_LOCATION}/${server_type}-server/${node_number}.conf