Browse code

Merge "Add is_fedora and exit_distro_not_supported functions"

Jenkins authored on 2012/12/12 08:15:15
Showing 9 changed files
... ...
@@ -354,6 +354,18 @@ function is_ubuntu {
354 354
 }
355 355
 
356 356
 
357
+# Determine if current distribution is a Fedora-based distribution
358
+# (Fedora, RHEL, CentOS).
359
+# is_fedora
360
+function is_fedora {
361
+    if [[ -z "$os_VENDOR" ]]; then
362
+        GetOSVersion
363
+    fi
364
+
365
+    [ "$os_VENDOR" = "Fedora" ] || [ "$os_VENDOR" = "Red Hat" ] || [ "$os_VENDOR" = "CentOS" ]
366
+}
367
+
368
+
357 369
 # Determine if current distribution is a SUSE-based distribution
358 370
 # (openSUSE, SLE).
359 371
 # is_suse
... ...
@@ -366,6 +378,23 @@ function is_suse {
366 366
 }
367 367
 
368 368
 
369
+# Exit after outputting a message about the distribution not being supported.
370
+# exit_distro_not_supported [optional-string-telling-what-is-missing]
371
+function exit_distro_not_supported {
372
+    if [[ -z "$DISTRO" ]]; then
373
+        GetDistro
374
+    fi
375
+
376
+    if [ $# -gt 0 ]; then
377
+        echo "Support for $DISTRO is incomplete: no support for $@"
378
+    else
379
+        echo "Support for $DISTRO is incomplete."
380
+    fi
381
+
382
+    exit 1
383
+}
384
+
385
+
369 386
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
370 387
 # be owned by the installation user, we create the directory and change the
371 388
 # ownership to the proper user.
... ...
@@ -598,12 +627,12 @@ function install_package() {
598 598
         NO_UPDATE_REPOS=True
599 599
 
600 600
         apt_get install "$@"
601
+    elif is_fedora; then
602
+        yum_install "$@"
603
+    elif is_suse; then
604
+        zypper_install "$@"
601 605
     else
602
-        if is_suse; then
603
-            zypper_install "$@"
604
-        else
605
-            yum_install "$@"
606
-        fi
606
+        exit_distro_not_supported "installing packages"
607 607
     fi
608 608
 }
609 609
 
... ...
@@ -622,9 +651,11 @@ function is_package_installed() {
622 622
     if [[ "$os_PACKAGE" = "deb" ]]; then
623 623
         dpkg -l "$@" > /dev/null
624 624
         return $?
625
-    else
625
+    elif [[ "$os_PACKAGE" = "rpm" ]]; then
626 626
         rpm --quiet -q "$@"
627 627
         return $?
628
+    else
629
+        exit_distro_not_supported "finding if a package is installed"
628 630
     fi
629 631
 }
630 632
 
... ...
@@ -1032,20 +1063,20 @@ function add_user_to_group() {
1032 1032
 function get_rootwrap_location() {
1033 1033
     local module=$1
1034 1034
 
1035
-    if is_ubuntu || is_suse; then
1036
-        echo "/usr/local/bin/$module-rootwrap"
1037
-    else
1035
+    if is_fedora; then
1038 1036
         echo "/usr/bin/$module-rootwrap"
1037
+    else
1038
+        echo "/usr/local/bin/$module-rootwrap"
1039 1039
     fi
1040 1040
 }
1041 1041
 
1042 1042
 # Get the path to the pip command.
1043 1043
 # get_pip_command
1044 1044
 function get_pip_command() {
1045
-    if is_ubuntu || is_suse; then
1046
-        echo "/usr/bin/pip"
1047
-    else
1045
+    if is_fedora; then
1048 1046
         echo "/usr/bin/pip-python"
1047
+    else
1048
+        echo "/usr/bin/pip"
1049 1049
     fi
1050 1050
 }
1051 1051
 
... ...
@@ -195,8 +195,8 @@ function init_cinder() {
195 195
         mkdir -p $CINDER_STATE_PATH/volumes
196 196
 
197 197
         if sudo vgs $VOLUME_GROUP; then
198
-            if [[ "$os_PACKAGE" = "rpm" ]]; then
199
-                # RPM doesn't start the service
198
+            if is_fedora || is_suse; then
199
+                # service is not started by default
200 200
                 start_service tgtd
201 201
             fi
202 202
 
... ...
@@ -245,9 +245,15 @@ function start_cinder() {
245 245
             # do it in two steps
246 246
             sudo stop tgt || true
247 247
             sudo start tgt
248
-        else
248
+        elif is_fedora; then
249 249
             # bypass redirection to systemctl during restart
250 250
             sudo /sbin/service --skip-redirect tgtd restart
251
+        elif is_suse; then
252
+            restart_service tgtd
253
+        else
254
+            # note for other distros: unstack.sh also uses the tgt/tgtd service
255
+            # name, and would need to be adjusted too
256
+            exit_distro_not_supported "restarting tgt"
251 257
         fi
252 258
     fi
253 259
 
... ...
@@ -23,22 +23,28 @@ function configure_database_mysql {
23 23
     if is_ubuntu; then
24 24
         MY_CONF=/etc/mysql/my.cnf
25 25
         MYSQL=mysql
26
-    else
26
+    elif is_fedora; then
27
+        MY_CONF=/etc/my.cnf
28
+        MYSQL=mysqld
29
+    elif is_suse; then
27 30
         MY_CONF=/etc/my.cnf
28
-        if is_suse; then
29
-            MYSQL=mysql
30
-        else
31
-            MYSQL=mysqld
32
-        fi
31
+        MYSQL=mysql
32
+    else
33
+        exit_distro_not_supported "mysql configuration"
33 34
     fi
34 35
 
35 36
     # Start mysql-server
36
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
37
-        # RPM doesn't start the service
37
+    if is_fedora || is_suse; then
38
+        # service is not started by default
38 39
         start_service $MYSQL
39
-        # Set the root password - only works the first time
40
+    fi
41
+
42
+    # Set the root password - only works the first time. For Ubuntu, we already
43
+    # did that with debconf before installing the package.
44
+    if ! is_ubuntu; then
40 45
         sudo mysqladmin -u root password $DATABASE_PASSWORD || true
41 46
     fi
47
+
42 48
     # Update the DB to give user ‘$DATABASE_USER’@’%’ full control of the all databases:
43 49
     sudo mysql -uroot -p$DATABASE_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';"
44 50
 
... ...
@@ -84,10 +90,12 @@ EOF
84 84
         chmod 0600 $HOME/.my.cnf
85 85
     fi
86 86
     # Install mysql-server
87
-    if is_suse; then
87
+    if is_ubuntu || is_fedora; then
88
+        install_package mysql-server
89
+    elif is_suse; then
88 90
         install_package mysql-community-server
89 91
     else
90
-        install_package mysql-server
92
+        exit_distro_not_supported "mysql installation"
91 93
     fi
92 94
 }
93 95
 
... ...
@@ -20,7 +20,7 @@ function recreate_database_postgresql {
20 20
 
21 21
 function configure_database_postgresql {
22 22
     echo_summary "Configuring and starting PostgreSQL"
23
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
23
+    if is_fedora || is_suse; then
24 24
         PG_HBA=/var/lib/pgsql/data/pg_hba.conf
25 25
         PG_CONF=/var/lib/pgsql/data/postgresql.conf
26 26
         sudo [ -e $PG_HBA ] || sudo postgresql-setup initdb
... ...
@@ -53,10 +53,12 @@ EOF
53 53
     else
54 54
         sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS
55 55
     fi
56
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
56
+    if is_ubuntu; then
57
+        install_package postgresql
58
+    elif is_fedora || is_suse; then
57 59
         install_package postgresql-server
58 60
     else
59
-        install_package postgresql
61
+        exit_distro_not_supported "postgresql installation"
60 62
     fi
61 63
 }
62 64
 
... ...
@@ -81,19 +81,18 @@ function init_horizon() {
81 81
         sudo a2ensite horizon
82 82
         # WSGI doesn't enable by default, enable it
83 83
         sudo a2enmod wsgi
84
+    elif is_fedora; then
85
+        APACHE_NAME=httpd
86
+        APACHE_CONF=conf.d/horizon.conf
87
+        sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
88
+    elif is_suse; then
89
+        APACHE_NAME=apache2
90
+        APACHE_CONF=vhosts.d/horizon.conf
91
+        # Append wsgi to the list of modules to load
92
+        grep -q "^APACHE_MODULES=.*wsgi" /etc/sysconfig/apache2 ||
93
+            sudo sed '/^APACHE_MODULES=/s/^\(.*\)"$/\1 wsgi"/' -i /etc/sysconfig/apache2
84 94
     else
85
-        # Install httpd, which is NOPRIME'd
86
-        if is_suse; then
87
-            APACHE_NAME=apache2
88
-            APACHE_CONF=vhosts.d/horizon.conf
89
-            # Append wsgi to the list of modules to load
90
-            grep -q "^APACHE_MODULES=.*wsgi" /etc/sysconfig/apache2 ||
91
-                sudo sed '/^APACHE_MODULES=/s/^\(.*\)"$/\1 wsgi"/' -i /etc/sysconfig/apache2
92
-        else
93
-            APACHE_NAME=httpd
94
-            APACHE_CONF=conf.d/horizon.conf
95
-            sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
96
-        fi
95
+        exit_distro_not_supported "apache configuration"
97 96
     fi
98 97
 
99 98
     # Configure apache to run horizon
... ...
@@ -113,11 +112,13 @@ function install_horizon() {
113 113
     if is_ubuntu; then
114 114
         # Install apache2, which is NOPRIME'd
115 115
         install_package apache2 libapache2-mod-wsgi
116
+    elif is_fedora; then
117
+        sudo rm -f /etc/httpd/conf.d/000-*
118
+        install_package httpd mod_wsgi
116 119
     elif is_suse; then
117 120
         install_package apache2 apache2-mod_wsgi
118 121
     else
119
-        sudo rm -f /etc/httpd/conf.d/000-*
120
-        install_package httpd mod_wsgi
122
+        exit_distro_not_supported "apache installation"
121 123
     fi
122 124
 
123 125
     # NOTE(sdague) quantal changed the name of the node binary
... ...
@@ -394,11 +394,13 @@ function install_novaclient() {
394 394
 function install_nova() {
395 395
     if is_service_enabled n-cpu; then
396 396
         if is_ubuntu; then
397
-            LIBVIRT_PKG_NAME=libvirt-bin
397
+            install_package libvirt-bin
398
+        elif is_fedora || is_suse; then
399
+            install_package libvirt
398 400
         else
399
-            LIBVIRT_PKG_NAME=libvirt
401
+            exit_distro_not_supported "libvirt installation"
400 402
         fi
401
-        install_package $LIBVIRT_PKG_NAME
403
+
402 404
         # Install and configure **LXC** if specified.  LXC is another approach to
403 405
         # splitting a system into many smaller parts.  LXC uses cgroups and chroot
404 406
         # to simulate multiple systems.
... ...
@@ -646,17 +646,21 @@ set -o xtrace
646 646
 echo_summary "Installing package prerequisites"
647 647
 if is_ubuntu; then
648 648
     install_package $(get_packages $FILES/apts)
649
+elif is_fedora; then
650
+    install_package $(get_packages $FILES/rpms)
649 651
 elif is_suse; then
650 652
     install_package $(get_packages $FILES/rpms-suse)
651 653
 else
652
-    install_package $(get_packages $FILES/rpms)
654
+    exit_distro_not_supported "list of packages"
653 655
 fi
654 656
 
655 657
 if [[ $SYSLOG != "False" ]]; then
656
-    if is_suse; then
658
+    if is_ubuntu || is_fedora; then
659
+        install_package rsyslog-relp
660
+    elif is_suse; then
657 661
         install_package rsyslog-module-relp
658 662
     else
659
-        install_package rsyslog-relp
663
+        exit_distro_not_supported "rsyslog-relp installation"
660 664
     fi
661 665
 fi
662 666
 
... ...
@@ -668,20 +672,22 @@ if is_service_enabled rabbit; then
668 668
     cat "$tfile"
669 669
     rm -f "$tfile"
670 670
 elif is_service_enabled qpid; then
671
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
671
+    if is_fedora; then
672 672
         install_package qpid-cpp-server-daemon
673
-    else
673
+    elif is_ubuntu; then
674 674
         install_package qpidd
675
+    else
676
+        exit_distro_not_supported "qpid installation"
675 677
     fi
676 678
 elif is_service_enabled zeromq; then
677
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
678
-        if is_suse; then
679
-            install_package libzmq1 python-pyzmq
680
-        else
681
-            install_package zeromq python-zmq
682
-        fi
683
-    else
679
+    if is_fedora; then
680
+        install_package zeromq python-zmq
681
+    elif is_ubuntu; then
684 682
         install_package libzmq1 python-zmq
683
+    elif is_suse; then
684
+        install_package libzmq1 python-pyzmq
685
+    else
686
+        exit_distro_not_supported "zeromq installation"
685 687
     fi
686 688
 fi
687 689
 
... ...
@@ -877,8 +883,8 @@ fi
877 877
 if is_service_enabled rabbit; then
878 878
     # Start rabbitmq-server
879 879
     echo_summary "Starting RabbitMQ"
880
-    if [[ "$os_PACKAGE" = "rpm" ]]; then
881
-        # RPM doesn't start the service
880
+    if is_fedora || is_suse; then
881
+        # service is not started by default
882 882
         restart_service rabbitmq-server
883 883
     fi
884 884
     # change the rabbit password since the default is "guest"
... ...
@@ -260,9 +260,11 @@ fi
260 260
 if [[ "$os_PACKAGE" = "deb" ]]; then
261 261
     is_package_installed dpkg
262 262
     VAL=$?
263
-else
263
+elif [[ "$os_PACKAGE" = "rpm" ]]; then
264 264
     is_package_installed rpm
265 265
     VAL=$?
266
+else
267
+    VAL=1
266 268
 fi
267 269
 if [[ "$VAL" -eq 0 ]]; then
268 270
     echo "OK"
... ...
@@ -273,9 +275,11 @@ fi
273 273
 if [[ "$os_PACKAGE" = "deb" ]]; then
274 274
     is_package_installed dpkg bash
275 275
     VAL=$?
276
-else
276
+elif [[ "$os_PACKAGE" = "rpm" ]]; then
277 277
     is_package_installed rpm bash
278 278
     VAL=$?
279
+else
280
+    VAL=1
279 281
 fi
280 282
 if [[ "$VAL" -eq 0 ]]; then
281 283
     echo "OK"
... ...
@@ -90,15 +90,19 @@ done
90 90
 
91 91
 if is_ubuntu; then
92 92
     PKG_DIR=$FILES/apts
93
-else
93
+elif is_fedora; then
94 94
     PKG_DIR=$FILES/rpms
95
+else
96
+    exit_distro_not_supported "list of packages"
95 97
 fi
96 98
 
97 99
 for p in $(get_packages $PKG_DIR); do
98 100
     if [[ "$os_PACKAGE" = "deb" ]]; then
99 101
         ver=$(dpkg -s $p 2>/dev/null | grep '^Version: ' | cut -d' ' -f2)
100
-    else
102
+    elif [[ "$os_PACKAGE" = "rpm" ]]; then
101 103
         ver=$(rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $p)
104
+    else
105
+        exit_distro_not_supported "finding version of a package"
102 106
     fi
103 107
     echo "pkg|${p}|${ver}"
104 108
 done