]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
* Now uses pkgos_func functions for debconf and dbconfig-common handling.
authorThomas Goirand <thomas@goirand.fr>
Fri, 26 Oct 2012 11:07:48 +0000 (11:07 +0000)
committerThomas Goirand <thomas@goirand.fr>
Fri, 26 Oct 2012 14:49:46 +0000 (14:49 +0000)
  * Renames /etc/sudoers.d/cinder_sudoers as /etc/sudoers.d/cinder-common.
  * Debconf now users cinder/<debconf-screen-name> and not cinder-common/.
  * Reviewed long and short descriptions in debian/control.
  * Bumped Build-Depends-Indep: python-all to 2.6.6-3~ since we are using dh_python2.
  * Added everyone in the team as Uploaders:.
  * Changed Homepage field to http://cinder.openstack.org/.
  * Dependencies are now by alpha order.
  * Removed useless empty cinder-volume.postrm, cinder-api.postrm,
  cinder-scheduler.postinst, cinder-scheduler.postrm.
  * Pre-Depends: dpkg (>= 1.15.6~) because we use xz compression.

20 files changed:
debian/changelog
debian/cinder-api.postrm [deleted file]
debian/cinder-common.config [deleted file]
debian/cinder-common.config.in [new file with mode: 0644]
debian/cinder-common.install
debian/cinder-common.lintian-overrides [new file with mode: 0644]
debian/cinder-common.postinst [deleted file]
debian/cinder-common.postinst.in [new file with mode: 0644]
debian/cinder-common.postrm
debian/cinder-common.prerm
debian/cinder-common.sudoers [moved from debian/cinder_sudoers with 100% similarity]
debian/cinder-common.templates
debian/cinder-scheduler.postinst [deleted file]
debian/cinder-scheduler.postrm [deleted file]
debian/cinder-volume.postrm [deleted file]
debian/control
debian/copyright
debian/pkgos_func [new file with mode: 0644]
debian/pkgos_insert_include [new file with mode: 0755]
debian/rules

index 8a744ce20ed054e3742e8b45097140db7feea102..4c863ad0174ec7a139bf5b69bc175381e071619d 100644 (file)
@@ -5,6 +5,18 @@ cinder (2012.2-1) experimental; urgency=low
 
   [ Thomas Goirand ]
   * Fixes wrong handling (eg: policy violation) of /etc/cinder/cinder.conf.
+  * Now uses pkgos_func functions for debconf and dbconfig-common handling.
+  * Renames /etc/sudoers.d/cinder_sudoers as /etc/sudoers.d/cinder-common.
+  * Debconf now users cinder/<debconf-screen-name> and not cinder-common/.
+  * Reviewed long and short descriptions in debian/control.
+  * Bumped Build-Depends-Indep: python-all to 2.6.6-3~ since we are using
+  dh_python2.
+  * Added everyone in the team as Uploaders:.
+  * Changed Homepage field to http://cinder.openstack.org/.
+  * Dependencies are now by alpha order.
+  * Removed useless empty cinder-volume.postrm, cinder-api.postrm,
+  cinder-scheduler.postinst, cinder-scheduler.postrm.
+  * Pre-Depends: dpkg (>= 1.15.6~) because we use xz compression.
 
  -- Mehdi Abaakouk <sileht@sileht.net>  Sat, 29 Sep 2012 09:23:22 +0200
 
diff --git a/debian/cinder-api.postrm b/debian/cinder-api.postrm
deleted file mode 100644 (file)
index 07fe0c2..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh -e
-
-#DEBHELPER#
diff --git a/debian/cinder-common.config b/debian/cinder-common.config
deleted file mode 100644 (file)
index 9001254..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-set -e
-
-. /usr/share/debconf/confmodule
-
-CINDER_COM_DEF=/etc/default/cinder-common
-
-# Set the debconf value to whatever is in the config file
-if [ -f ${CINDER_COM_DEF} ] ; then
-    . ${CINDER_COM_DEF}
-fi
-if ! [ "${CINDER_ENABLE}" = "true" ] ; then
-    CINDER_ENABLE=false
-fi
-db_set cinder-common/start_services ${CINDER_ENABLE}
-
-db_input low cinder-common/start_services || true
-db_go
-
-# Write a default config file if it doesn't exist yet
-# note that the value will be overwritten by the postinst
-if ! [ -f ${CINDER_COM_DEF} ] ; then
-    echo "# defaults file for cinder daemons
-
-# start cinder daemons from init.d script?
-#  only allowed values are \"true\" and \"false\"
-CINDER_ENABLE=true" >${CINDER_COM_DEF}
-fi
-
-db_input high cinder-common/configure_db || true
-db_go
-
-db_get cinder-common/configure_db
-if [ "$RET" = "true" ]; then
-    if [ -f /usr/share/dbconfig-common/dpkg/config ]
-    then
-        dbc_dbtypes="sqlite3, mysql, pgsql"
-        dbc_authmethod_user="password"
-        dbc_basepath="/var/lib/cinder"
-        dbc_dbname="cinder"
-        . /usr/share/dbconfig-common/dpkg/config
-        dbc_go cinder-common $@
-    fi
-fi
diff --git a/debian/cinder-common.config.in b/debian/cinder-common.config.in
new file mode 100644 (file)
index 0000000..f8b7570
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+set -e
+
+. /usr/share/debconf/confmodule
+CINDER_COM_DEF=/etc/default/cinder-common
+CINDER_CONF=/etc/cinder/cinder.conf
+
+#PKGOS-INCLUDE#
+
+manage_cinder_enable () {
+       pkgos_read_config -sh ${CINDER_COM_DEF} CINDER_ENABLE cinder/start_services
+       CINDER_ENABLE=${RET}
+       if ! [ "${CINDER_ENABLE}" = "false" ] ; then
+               CINDER_ENABLE=true
+       fi
+       # Write a default config file
+       echo "# defaults file for cinder daemons
+
+# start cinder daemons from init.d script?
+#  only allowed values are \"true\" and \"false\"
+CINDER_ENABLE=${CINDER_ENABLE}" >${CINDER_COM_DEF}     
+}
+
+pkgos_var_user_group cinder
+manage_cinder_enable
+pkgos_dbc_read_conf ${CINDER_CONF} cinder DEFAULT sql_connection $@
+
+exit 0
index 0a443618c7c47b569bbf9ca9d304ecfc070ed1a6..484de9fb73418fc843517517fc762b7214004ed0 100644 (file)
@@ -6,4 +6,3 @@ etc/cinder/rootwrap.d/volume.filters /etc/cinder/rootwrap.d
 etc/cinder/rootwrap.conf etc/cinder
 debian/cinder.conf usr/share/cinder-common
 debian/logging.conf etc/cinder
-debian/cinder_sudoers etc/sudoers.d
diff --git a/debian/cinder-common.lintian-overrides b/debian/cinder-common.lintian-overrides
new file mode 100644 (file)
index 0000000..d0fb1cc
--- /dev/null
@@ -0,0 +1 @@
+cinder-common: unused-debconf-template cinder/start_services
diff --git a/debian/cinder-common.postinst b/debian/cinder-common.postinst
deleted file mode 100644 (file)
index 5b6b51c..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/sh -e
-
-if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then
-    if ! getenv group cinder > /dev/null 2>&1; then
-        addgroup --quiet --system cinder >/dev/null
-    fi
-
-    if ! getenv passwd cinder > /dev/null 2>&1; then
-        adduser --quiet --system --home /var/lib/cinder --ingroup cinder --no-create-home \
-            --shell /bin/false cinder
-    fi
-
-    # Create config files if they don't exist
-    if ! [ -d /etc/cinder ] ; then
-        mkdir -p /etc/cinder
-    fi
-    if ! [ -e /etc/cinder/cinder.conf ] ; then
-        cp /usr/share/cinder-common/cinder.conf /etc/cinder/cinder.conf
-    fi
-
-    chown -R cinder:adm /var/log/cinder
-    chmod 0750 /var/log/cinder
-    chown -R cinder:cinder /var/lib/cinder /etc/cinder
-    chmod 0750 /etc/cinder
-    chmod 0440 /etc/sudoers.d/cinder_sudoers
-
-    . /usr/share/debconf/confmodule
-
-    db_get cinder-common/configure_db
-
-    if [ "$RET" = "true" ]; then
-        . /usr/share/dbconfig-common/dpkg/postinst
-
-        db_get cinder-common/database-type
-        if [ "$RET" = "sqlite3" ]
-        then
-            dbc_name="cinder.sqlite"
-            db_set cinder-common/db/dbname $dbc_name
-        fi
-
-        dbc_dbfile_owner="cinder:cinder"
-        dbc_go cinder-common $@
-
-        if [ "$dbc_install" = "true" ]
-        then
-
-            case "$dbc_dbtype" in
-                mysql)
-                    [ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
-                    SQL_CONNECTION="mysql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
-                    ;;
-                pgsql)
-                    [ -n "$dbc_dbport" ] && dbport=:$dbc_dbport
-                    SQL_CONNECTION="pgsql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
-                    ;;
-                *)
-                    SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname"
-                    ;;
-            esac
-
-            sed -e "s,^[- \t]*sql_connection=.\+,sql_connection=$SQL_CONNECTION," -i /etc/cinder/cinder.conf
-
-        fi
-    fi
-
-    if ! grep -q sql_connection /etc/cinder/cinder.conf
-    then
-        su -s /bin/sh -c 'cinder-manage db sync' cinder
-    fi
-
-    db_get cinder-common/start_services
-    if [ " $RET" = "false" ]; then
-        sed -e "s,^CINDER_ENABLE=.\+,CINDER_ENABLE=false," -i /etc/default/cinder
-    fi
-fi
-
-chmod 0640 /etc/cinder/cinder.conf
-
-#DEBHELPER#
diff --git a/debian/cinder-common.postinst.in b/debian/cinder-common.postinst.in
new file mode 100644 (file)
index 0000000..df75c73
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -e
+
+CINDER_CONF=/etc/cinder/cinder.conf
+
+#PKGOS-INCLUDE#
+
+if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then
+       . /usr/share/debconf/confmodule
+       . /usr/share/dbconfig-common/dpkg/postinst
+
+       pkgos_var_user_group cinder
+       pkgos_write_new_conf cinder cinder.conf
+       pkgos_dbc_postinst ${CINDER_CONF} cinder DEFAULT sql_connection $@
+
+       chmod 0440 /etc/sudoers.d/cinder-common
+       echo "Now calling cinder-manage db sync: this may take a while..."
+       su -s /bin/sh -c 'cinder-manage db sync' cinder
+fi
+
+#DEBHELPER#
+
+exit 0
index b2335705f6b486e376144775205e00aa727d9e9a..365f34c3e659cea4698645bb3f63c483dbdcaec9 100644 (file)
@@ -2,30 +2,29 @@
 
 set -e
 
-if [ -f /usr/share/debconf/confmodule ]; then
-    . /usr/share/debconf/confmodule
-fi
-
-db_get cinder-common/configure_db
-if [ "$RET" = "true" ]; then
+if [ "$1" = "purge" ] && [ -f /usr/share/debconf/confmodule ] ; then
+       if [ -f /usr/share/debconf/confmodule ] ; then
+               . /usr/share/debconf/confmodule
 
-    if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
-        . /usr/share/dbconfig-common/dpkg/postrm
-        dbc_go cinder-common $@
-    else
-        rm -f /etc/dbconfig-common/cinder-common.conf
-        if which ucf >/dev/null 2>&1; then
-            ucf --purge /etc/dbconfig-common/cinder-common.conf
-            ucfr --purge cinder-common /etc/dbconfig-common/cinder-common.conf
-        fi
-    fi
-fi
+               db_get cinder/configure_db
+               if [ "$RET" = "true" ]; then
+                       if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
+                               . /usr/share/dbconfig-common/dpkg/postrm
+                               dbc_go cinder-common $@
+                       else
+                               rm -f /etc/dbconfig-common/cinder-common.conf
+                               if which ucf >/dev/null 2>&1; then
+                                       ucf --purge /etc/dbconfig-common/cinder-common.conf
+                                       ucfr --purge cinder-common /etc/dbconfig-common/cinder-common.conf
+                               fi
+                       fi
+               fi
+       fi
 
-if [ "$1" = "purge" ] ; then
-    rm -f /etc/cinder/cinder.conf
-    rmdir --ignore-fail-on-non-empty /etc/cinder
-    rm -f /etc/default/cinder-common
-    rm -rf /var/lib/cinder
+       rm -f /etc/cinder/cinder.conf
+       rmdir --ignore-fail-on-non-empty /etc/cinder
+       rm -f /etc/default/cinder-common
+       rm -rf /var/lib/cinder /var/log/cinder
 fi
 
 #DEBHELPER#
index 75b6ce159aab18e66cc41d7b0fc9363b9cc5c1d5..8e6f542b81823c35ecd5f64ee4ba660f754165ae 100644 (file)
@@ -4,7 +4,7 @@ set -e
 
 . /usr/share/debconf/confmodule
 
-db_get cinder-common/configure_db
+db_get cinder/configure_db
 if [ "$RET" = "true" ]; then
     . /usr/share/dbconfig-common/dpkg/prerm
     dbc_go cinder-common $@
index f1b7b4baaa7abe42e6ff20ce410a8e701908fcb1..367e7c105ce31358897d51602305d08b47c0e788 100644 (file)
@@ -1,11 +1,11 @@
-Template: cinder-common/start_services
+Template: cinder/start_services
 Type: boolean
 Default: true
 _Description: Start cinder services at boot?
  Please choose whether you want to start Cinder services when the
  machine is booted up.
 
-Template: cinder-common/configure_db
+Template: cinder/configure_db
 Type: boolean
 Default: false
 _Description: Set up a database for Cinder?
diff --git a/debian/cinder-scheduler.postinst b/debian/cinder-scheduler.postinst
deleted file mode 100644 (file)
index 1072f3c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh -e
-
-
-#DEBHELPER#
diff --git a/debian/cinder-scheduler.postrm b/debian/cinder-scheduler.postrm
deleted file mode 100644 (file)
index 07fe0c2..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh -e
-
-#DEBHELPER#
diff --git a/debian/cinder-volume.postrm b/debian/cinder-volume.postrm
deleted file mode 100644 (file)
index 07fe0c2..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh -e
-
-#DEBHELPER#
index cbb8d3a743a289f9637cc984fc813c7db10ca2bd..03a5ec2990552ee5d3782cf7c919f0ed9c045f28 100644 (file)
@@ -2,104 +2,135 @@ Source: cinder
 Section: net
 Priority: extra
 Maintainer: PKG OpenStack <openstack-devel@lists.alioth.debian.org>
-Uploaders: Mehdi Abaakouk <sileht@sileht.net>
+Uploaders: Loic Dachary (OuoU) <loic@debian.org>,
+           Julien Danjou <acid@debian.org>,
+           Thomas Goirand <zigo@debian.org>,
+           Ghe Rivero <ghe.rivero@stackops.com>,
+           Mehdi Abaakouk <sileht@sileht.net>
 Build-Depends: debhelper (>= 8.0.0),
  po-debconf,
- python-all (>= 2.6),
+ python-all (>= 2.6.6-3~),
 Build-Depends-Indep:
- python-sqlalchemy,
- python-setuptools,
- python-cheetah,
+ pep8,
  python-amqplib,
  python-anyjson,
+ python-cheetah,
+ python-coverage,
+ python-daemon,
  python-eventlet,
+ python-glance,
+ python-glanceclient,
+ python-greenlet,
+ python-iso8601,
  python-kombu,
  python-lockfile,
  python-lxml,
- python-daemon,
- python-routes,
- python-webob,
- python-greenlet,
- python-glanceclient,
- python-pastedeploy,
- python-paste,
  python-migrate,
- python-netaddr,
- python-glance,
- python-suds,
- python-paramiko,
- python-iso8601,
- python-coverage,
  python-mox,
- python-nose,
- python-sphinx,
  python-mysqldb,
+ python-netaddr,
+ python-nose,
+ python-paramiko,
+ python-paste,
+ python-pastedeploy,
+ python-routes,
+ python-setuptools,
  python-setuptools-git,
- pep8,
+ python-sphinx,
+ python-sqlalchemy,
+ python-suds,
+ python-webob,
 Standards-Version: 3.9.3
-Homepage: http://launchpad.net/cinder
+Homepage: http://cinder.openstack.org/
 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=openstack/cinder.git;a=summary
 Vcs-Git: git://anonscm.debian.org/openstack/cinder.git
 
 Package: python-cinder
 Section: python
 Architecture: all
-Depends: ${python:Depends}, python-sqlalchemy,
- python-cheetah,
+Pre-Depends: dpkg (>= 1.15.6~)
+Depends: ${python:Depends},
  python-amqplib,
  python-anyjson,
+ python-cheetah, 
+ python-daemon,  
  python-eventlet,
- python-kombu,
+ python-glance,
+ python-glanceclient,
+ python-greenlet,
+ python-iso8601,
+ python-kombu,  
  python-lockfile,
  python-lxml,
- python-daemon,
- python-routes,
- python-webob,
- python-greenlet,
- python-pastedeploy,
- python-paste,
  python-migrate,
- python-netaddr,
- python-glance,
- python-suds,
+ python-netaddr,   
  python-paramiko,
- python-iso8601,
- python-glanceclient,
+ python-paste,
+ python-pastedeploy,
+ python-routes,
+ python-suds,
+ python-sqlalchemy,
+ python-webob,
  ${misc:Depends}
-Description: Cinder python libraries
- Cinder is a storage service for the Openstack project.
+Description: Openstack block storage as a service - Python libraries
+ Cinder is a block storage as service system for the Openstack cloud computing
+ software suite. It is a direct replacement for nova-volume as a separate
+ project. Cinder users LVM partitions of your volume servers in order to
+ provide iSCSI permanent block storage devices for your virtual machines
+ running on Nova.
  .
- This package contains the proython parts of cinder.
+ This package contains the Python libraries that are parts of cinder.
 
 Package: cinder-common
 Architecture: all
+Pre-Depends: dpkg (>= 1.15.6~)
 Depends: python-cinder (= ${binary:Version}), ${python:Depends}, ${misc:Depends}, adduser, debconf, dbconfig-common
 Provides: ${python:Provides}
-Description: Cinder starage service - common files
- Cinder is a storage service for the Openstack project
+Description: Openstack block storage as a service - common files
+ Cinder is a block storage as service system for the Openstack cloud computing
+ software suite. It is a direct replacement for nova-volume as a separate
+ project. Cinder users LVM partitions of your volume servers in order to
+ provide iSCSI permanent block storage devices for your virtual machines
+ running on Nova.
  .
- This package contains things that are needed for all parts of cinder
+ This package contains common files and configuration that are
+ needed by all the daemon packages of Cinder.
 
 Package: cinder-api
 Architecture: all
+Pre-Depends: dpkg (>= 1.15.6~)
 Depends: cinder-common (= ${binary:Version}), ${python:Depends}, ${misc:Depends}
-Description: Cinder storage service - API server
- Cinder is a storage service for the Openstack project
+Description: Openstack block storage as a service - API server
+ Cinder is a block storage as service system for the Openstack cloud computing
+ software suite. It is a direct replacement for nova-volume as a separate
+ project. Cinder users LVM partitions of your volume servers in order to
+ provide iSCSI permanent block storage devices for your virtual machines
+ running on Nova.
  .
- This package contains the API server
+ This package contains the API server on which client will connect.
 
 Package: cinder-volume
 Architecture: all
+Pre-Depends: dpkg (>= 1.15.6~)
 Depends: cinder-common (= ${binary:Version}), ${python:Depends}, ${misc:Depends}
-Description: Cinder storage service - Volume server
- Cinder is a storage service for the Openstack project
+Description: Openstack block storage as a service - Volume server
+ Cinder is a block storage as service system for the Openstack cloud computing
+ software suite. It is a direct replacement for nova-volume as a separate
+ project. Cinder users LVM partitions of your volume servers in order to
+ provide iSCSI permanent block storage devices for your virtual machines
+ running on Nova.
  .
- This package contains the Volume server
+ This package contains the Volume server which will actually do the storage.
 
 Package: cinder-scheduler
 Architecture: all
+Pre-Depends: dpkg (>= 1.15.6~)
 Depends: cinder-common (= ${binary:Version}), ${python:Depends}, ${misc:Depends}
-Description: Cinder storage service - Scheduler server
- Cinder is a storage service for the Openstack project
+Description: Openstack block storage as a service - Scheduler server
+ Cinder is a block storage as service system for the Openstack cloud computing
+ software suite. It is a direct replacement for nova-volume as a separate
+ project. Cinder users LVM partitions of your volume servers in order to
+ provide iSCSI permanent block storage devices for your virtual machines
+ running on Nova.
  .
- This package contains the Scheduler server
+ This package contains the Scheduler server.
index 28c6615b41d61d55e96cd51ed20954fa4d9d5c39..4b57f0805db8eeb645affea0c1b88965e64abf77 100644 (file)
@@ -1,13 +1,13 @@
-Format: http://dep.debian.net/deps/dep5-
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 Upstream-Name: cinder
 Source: https://code.launchpad.net/cinder
 
 Files: *
-Copyright: 2010 United States Government as represented
+Copyright: (c) 2010 United States Government as represented
                 by the Administrator of the National Aeronautics
                 and Space Administration.
-Copyright: 2010 OpenStack LLC
-Copyright: Others (See individual files for more details)
+       (c) 2010 OpenStack LLC
+       (c) Others (See individual files for more details)
 License: Apache-2
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
diff --git a/debian/pkgos_func b/debian/pkgos_func
new file mode 100644 (file)
index 0000000..96ba923
--- /dev/null
@@ -0,0 +1,323 @@
+#!/bin/sh
+
+pkgos_gen_pass () {
+       i=$(dd if=/dev/random bs=64 count=1 2>|/dev/null | md5sum)
+       echo ${i% *}
+}
+
+# Sets a directive in a config file, eventually using a section name
+# Example calls:
+# pkgos_edit_config flavor keystone /etc/glance/glance-api.conf
+# pkgos_edit_config flavor keystone glance-api.conf paste_deploy
+# pkgos_edit_config auth_protocol ssh glance-api.conf keystone_authtoken
+# To be used in: postinst (make sure the file exists before call)
+pkgos_edit_config () {
+       local DIRECTIVE VALUE FILE SECTION TMP_FILE TMP_FILE2 TMP_FILE3 TMP_FILE4 NBR_LINES START_LINE NBR_LINE_SECTION END_FILE_NUM_LINES SHELL_SCRIPT_MODE
+       if [ "${1}" = "-sh" ] ; then
+               SHELL_SCRIPT_MODE="yes"
+               shift
+       fi
+       DIRECTIVE=${1}
+       VALUE=${2}
+       FILE=${3}
+       if [ ! -r "${3}" ] ; then
+               echo "pkgos_edit_config called with non readable file: ${3}"
+               exit 1
+       fi
+       if [ -z "${4}" ] && [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+           sed -i -e 's|^[ \t#]*'${DIRECTIVE}'=.*|'${DIRECTIVE}'='${VALUE}'|' ${FILE}
+           return
+       fi
+       SECTION=${4:-DEFAULT}
+       python -c "import configobj
+config=configobj.ConfigObj('${FILE}')
+config['${SECTION}']['${DIRECTIVE}']='${VALUE}'
+config.write()"
+}
+
+# Read the value of a directive in a config file
+# Example:
+# pkgos_get_config /etc/keystone/keystone.conf admin_token DEFAULT
+pkgos_get_config () {
+       local DIRECTIVE FILE SECTION SHELL_SCRIPT_MODE
+       if [ "${1}" = "-sh" ] ; then
+               SHELL_SCRIPT_MODE="yes"
+               shift
+       fi
+       FILE=${1}
+       DIRECTIVE=${2}
+       if [ ! -r ${FILE} ] ; then
+           RET=""
+           return
+       fi
+       if [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+           RET=`grep -E "^([ \t])*${DIRECTIVE}=" ${FILE} | cut -d"=" -f2`
+           return
+       fi
+       SECTION=${3:-DEFAULT}
+       RET=$(python -c "import configobj
+config=configobj.ConfigObj('${FILE}')
+print config['${SECTION}']['${DIRECTIVE}']")
+}
+
+# Read the value of a directive in a config file,
+# then prompt the user about it.
+# Example (options in this order please...):
+# pkgos_read_config -r -sh /etc/keystone/keystone.conf auth_token keystone/auth-token DEFAULT
+# To be used in: config
+pkgos_read_config () {
+       local DIRECTIVE CONF_PATH DEBCONF_NAME VALUE SECTION FSET_SEEN SHELL_SCRIPT_MODE
+       if [ "${1}" = "-r" ] ; then
+               FSET_SEEN="yes"
+               shift
+       fi
+       if [ "${1}" = "-sh" ] ; then
+               SHELL_SCRIPT_MODE="yes"
+               shift
+       fi
+       CONF_PATH=${1}
+       DIRECTIVE=${2}
+       DEBCONF_NAME=${3}
+       SECTION=${4}
+       if [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+               pkgos_get_config -sh ${CONF_PATH} ${DIRECTIVE}
+       else
+               if [ -n "${4}" ] ; then
+                       pkgos_get_config ${CONF_PATH} ${DIRECTIVE} ${SECTION}
+               else
+                       pkgos_get_config ${CONF_PATH} ${DIRECTIVE}
+               fi
+       fi
+       if [ -n "${RET}" ] ; then
+               db_set ${DEBCONF_NAME} ${RET}
+       fi
+       if [ "${FSET_SEEN}" = "yes" ] ; then
+               db_fset ${DEBCONF_NAME} seen false
+       fi
+       db_input high ${DEBCONF_NAME} || true
+       db_go
+       db_get ${DEBCONF_NAME}
+}
+
+# Read the connection directive from a config file
+# and fills the dbc_* variable accordingly,
+# then call dbconfig to do the actual configuration.
+# To be used in: config
+pkgos_dbc_read_conf () {
+       local ADDR BEFORE_AT AFTER_AT SERVER_PORT CONN_STRING PKG_NAME CONF_PATH PARSED_DB_TYPE PARSED_USER PARSED_PASS PARSED_DB_NAME PARSED_SERVER PARSED_PORT SHELL_SCRIPT_MODE
+       if [ "${1}" = "-sh" ] ; then
+               SHELL_SCRIPT_MODE="yes"
+               shift
+       fi
+       CONF_PATH=${1}
+       PKG_NAME=${2}
+       shift
+       shift
+       if [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+           CONN_DIRECTIVE=${1}
+           shift
+       else
+           CONN_SECTION=${1}
+           CONN_DIRECTIVE=${2}
+           shift
+           shift
+       fi          
+
+       db_fset ${PKG_NAME}/configure_db seen false
+       db_input high ${PKG_NAME}/configure_db || true
+       db_go || true
+       db_get ${PKG_NAME}/configure_db
+       if [ "$RET" = "true" ] && [ -f /usr/share/dbconfig-common/dpkg/config ] ; then
+               . /usr/share/dbconfig-common/dpkg/config
+               if [ -e "${CONF_PATH}" ] ; then
+                   CONN_STRING=$(pkgos_get_config "${CONF_PATH}" "${CONN_DIRECTIVE}" "${CONN_SECTION}")
+               else
+                   CONN_STRING=""
+               fi
+               PARSED_DB_TYPE=${CONN_STRING%%:*}
+               # If we have an undefined SQL type, we go back to a more sane default (eg: SQLite)
+               case "${PARSED_DB_TYPE}" in
+                       sqlite|mysql|pgsql)
+                               ;;
+                       postgresql*)
+                               PARSED_DB_TYPE=pgsql
+                               ;;
+                       *)
+                               CONN_STRING="sqlite:///var/lib/${PKG_NAME}/${PKG_NAME}db"
+                               PARSED_DB_TYPE="sqlite"
+                               ;;
+               esac
+               if [ "${PARSED_DB_TYPE}" = "sqlite" ] ; then
+                       if [ "${CONN_STRING}" = "sqlite:///${PKG_NAME}.db" ] ; then
+                               CONN_STRING="sqlite:///var/lib/${PKG_NAME}/${PKG_NAME}db"
+                       fi
+                       PARSED_DB_PATH=${CONN_STRING#sqlite://}
+                       if [ -z "${PARSED_DB_PATH}" ] ; then
+                               PARSED_DB_PATH=/var/lib/${PKG_NAME}/${PKG_NAME}db
+                       fi
+                       dbc_basepath=`dirname "${PARSED_DB_PATH}"`
+                       dbc_dbname=`basename "${PARSED_DB_PATH}"`
+                       dbc_dbtypes="sqlite3, mysql, pgsql"
+               else
+                       ADDR=${CONN_STRING#*sql://}
+                       BEFORE_AT=${ADDR%%@*}
+                       AFTER_AT=${ADDR#*@}
+                       SERVER_PORT=${AFTER_AT%%/*}
+
+                       PARSED_USER=${BEFORE_AT%%:*}
+                       PARSED_PASS=${BEFORE_AT#*:}
+                       PARSED_DB_NAME=${AFTER_AT#*/}
+                       PARSED_SERVER=${SERVER_PORT%%:*}
+                       case "${SERVER_PORT}" in
+                       *:*)
+                               PARSED_PORT=${SERVER_PORT#*:}
+                               ;;
+                       *)
+                               PARSED_PORT=""
+                               ;;
+                       esac
+                       if [ -n "${PARSED_USER}" ] && [ -n "${PARSED_PASS}" ] && [ -n "${PARSED_SERVER}" ] && [ -n "${PARSED_DB_NAME}" ] ; then
+                               dbc_dbuser=${PARSED_USER}
+                               dbc_dbpass=${PARSED_PASS}
+                               dbc_dbserver=${PARSED_SERVER}
+                               dbc_dbport=${PARSED_PORT}
+                               dbc_dbname=${PARSED_DB_NAME}
+                       fi
+                       if [ "${PARSED_DB_TYPE}" = "mysql" ] ; then
+                               dbc_dbtypes="mysql, pgsql, sqlite3"
+                       else
+                               dbc_dbtypes="pgsql, mysql, sqlite3"
+                       fi
+                       dbc_authmethod_user="password"
+               fi
+               dbc_go "${DPKG_MAINTSCRIPT_PACKAGE}" $@
+       fi
+}
+
+# Read values configured by dbconfig-common,
+# and set a connection directive accordingly
+# in a configuration file
+#
+# Caller should use something like this:
+# pkgos_dbc_postinst /etc/keystone/keystone.conf keystone connection $@
+# since dbc_go expect $@ as well.
+pkgos_dbc_postinst () {
+       local CONF_PATH CONF_DIR CONF_FNAME PKG_NAME SHELL_SCRIPT_MODE
+       if [ "${1}" = "-sh" ] ; then
+               SHELL_SCRIPT_MODE="yes"
+               shift
+       fi
+       CONF_PATH=${1}
+       PKG_NAME=${2}
+       shift
+       shift
+       if [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+           CONN_DIRECTIVE=${1}
+           shift
+       else
+           CONN_SECTION=${1}
+           CONN_DIRECTIVE=${2}
+           shift
+           shift
+       fi          
+
+       CONF_DIR=`dirname ${CONF_PATH}`
+       CONF_FNAME=`basename ${CONF_PATH}`
+
+       # Create config files if they don't exist
+       if [ ! -d ${CONF_DIR} ] ; then
+               mkdir -p ${CONF_DIR}
+       fi
+       chmod 0770 ${CONF_DIR}
+       chown ${PKG_NAME}:${PKG_NAME} ${CONF_DIR}
+       if [ ! -e ${CONF_PATH} ] ; then
+               install -D -m 0660 -o ${PKG_NAME} -g ${PKG_NAME} /usr/share/${DPKG_MAINTSCRIPT_PACKAGE}/${CONF_FNAME} ${CONF_PATH}
+       fi
+       db_get ${PKG_NAME}/configure_db
+       if [ "$RET" = "true" ] && [ -r /usr/share/dbconfig-common/dpkg/postinst ] ; then
+               . /usr/share/dbconfig-common/dpkg/postinst
+               dbc_dbfile_owner="${PKG_NAME}:${PKG_NAME}"
+               dbc_go "${DPKG_MAINTSCRIPT_PACKAGE}" $@
+               if [ "$dbc_install" = "true" ] ; then
+                       case "$dbc_dbtype" in
+                               mysql)
+                                       if [ -n "$dbc_dbport" ] ; then
+                                               dbport=:$dbc_dbport
+                                       fi
+                                       SQL_CONNECTION="mysql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
+                                       ;;
+                               postgresql*|pgsql)
+                                       if [ -n "$dbc_dbport" ] ; then
+                                               dbport=:$dbc_dbport
+                                       fi
+                                       SQL_CONNECTION="postgresql://$dbc_dbuser:$dbc_dbpass@${dbc_dbserver:-localhost}$dbport/$dbc_dbname"
+                                       ;;
+                               *)
+                                       SQL_CONNECTION="sqlite:///$dbc_basepath/$dbc_dbname"
+                                       ;;
+                       esac
+                       if [ "${SHELL_SCRIPT_MODE}" = "yes" ] ; then
+                               pkgos_edit_config -sh "${CONN_DIRECTIVE}" "${SQL_CONNECTION}" "${CONF_PATH}"
+                       else
+                               pkgos_edit_config "${CONN_DIRECTIVE}" "${SQL_CONNECTION}" "${CONF_PATH}" "${CONN_SECTION}"
+                       fi
+               fi
+       fi
+}
+
+pkgos_write_new_conf () {
+       local PKG_NAME
+       PKG_NAME=${1}
+       CONF_FNAME=${2}
+
+       SRC_PATH=/usr/share/${DPKG_MAINTSCRIPT_PACKAGE}/${CONF_FNAME}
+       DST_DIR=/etc/${PKG_NAME}
+       DST_PATH=${DST_DIR}/${CONF_FNAME}
+       if [ ! -d ${DST_DIR} ] ; then
+               mkdir -p ${DST_DIR}
+       fi
+       chmod 0750 ${DST_DIR}
+       chown ${PKG_NAME}:${PKG_NAME} ${DST_DIR}
+       if [ ! -e ${DST_PATH} ] ; then
+               install -D -m 640 -o ${PKG_NAME} -g ${PKG_NAME} ${SRC_PATH} ${DST_PATH}
+       fi
+}
+
+pkgos_var_user_group () {
+       local PKG_NAME
+       PKG_NAME=${1}
+
+       # Create user and groups if they don't exist
+       if ! getent group ${PKG_NAME} > /dev/null 2>&1 ; then
+               addgroup --quiet --system ${PKG_NAME}
+       fi
+       if ! getent passwd ${PKG_NAME} > /dev/null 2>&1 ; then
+               adduser --system \
+                       --home /var/lib/${PKG_NAME} \
+                       --no-create-home \
+                       --quiet \
+                       --disabled-password \
+                       --shell /bin/bash \
+                       --group ${PKG_NAME}
+       fi
+
+       # Create /var/{lib,log}/<package> with that user/group if it doesn't exist
+       if [ ! -d /var/lib/${PKG_NAME} ] ; then
+               mkdir -p /var/lib/${PKG_NAME}/cache
+       fi
+       chown -R ${PKG_NAME}:${PKG_NAME} /var/lib/${PKG_NAME}
+       chmod -R 0750 /var/lib/${PKG_NAME}
+       if [ ! -d /var/log/${PKG_NAME} ] ; then
+               mkdir -p /var/log/${PKG_NAME}
+       fi
+       chown ${PKG_NAME}:${PKG_NAME} /var/log/${PKG_NAME}
+       chmod 0750 /var/log/${PKG_NAME}
+}
+
+pkgos_init () {
+       INIT_SCRIPT_NAME=${1}
+       if [ -x /etc/init.d/${INIT_SCRIPT_NAME} ] ; then
+               update-rc.d ${INIT_SCRIPT_NAME} defaults >/dev/null
+               invoke-rc.d ${INIT_SCRIPT_NAME} start || true
+       fi
+}
diff --git a/debian/pkgos_insert_include b/debian/pkgos_insert_include
new file mode 100755 (executable)
index 0000000..b0e9697
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+set -e
+set -x
+
+# Example call: pkgos_insert_include pkgos_func keystone.config
+INC=debian/${1}
+DST=debian/${2}
+SRC="debian/${2}.in"
+
+LINE_NUM=`grep -n "#PKGOS-INCLUDE#" ${SRC} | tail -n 1 | cut -d":" -f1`
+NBR_LINES=`cat ${SRC} | wc -l`
+cat ${SRC} | head -n $((${LINE_NUM} - 1 )) > ${DST}
+cat ${INC} >> ${DST}
+tail -n $(($NBR_LINES - $LINE_NUM )) ${SRC} >> ${DST}
index 50db4c1003e4d6adde79611d3b2f20af45acaaf4..c5cb20f69f44b290b647e9c5601bdf708b5c3ec1 100755 (executable)
@@ -1,7 +1,10 @@
 #!/usr/bin/make -f
 
 # Find upstream version (to be used later in this file)
-export UPSTR_VER=$(shell dpkg-parsechangelog | grep Version: | cut -d" " -f2 | cut -d"-" -f1)
+DEBVERS := $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
+VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[~-].*//')
+DEBFLAVOR :=$(shell dpkg-parsechangelog | grep -E ^Distribution: | cut -d" " -f2)
+DEBPKGNAME :=$(shell dpkg-parsechangelog | grep -E ^Source: | cut -d" " -f2)
 
 %:
        dh $@  --with python2
@@ -14,6 +17,10 @@ override_dh_auto_test:
        ./run_tests.sh -N -P || true
 endif
 
+override_dh_clean:
+       dh_clean
+       rm -f cinder-common.config cinder-common.postinst
+
 override_dh_installinit:
        if dpkg-vendor --derives-from ubuntu ; then \
                for i in *.upstart.in ; do \
@@ -23,11 +30,19 @@ override_dh_installinit:
        fi
        dh_installinit --error-handler=true
 
+override_dh_install:
+       dh_install
+       install -D -m 0440 debian/cinder-common.sudoers $(CURDIR)/debian/cinder-common/etc/sudoers.d/cinder-common
+
+override_dh_fixperms:
+       dh_fixperms
+       chmod 0440 $(CURDIR)/debian/cinder-common/etc/sudoers.d/cinder-common
+
 # Checkout master repo and create the orig.tar.xz
 get-vcs-source:
-       git remote add upstream git://github.com/openstack/cinder.git || true
+       git remote add upstream git://github.com/openstack/$(DEBPKGNAME).git || true
        git fetch upstream
-       git archive --prefix=cinder-$(UPSTR_VER)/ $(UPSTR_VER) | xz >../cinder_$(UPSTR_VER).orig.tar.xz
+       git archive --prefix=$(DEBPKGNAME)-$(VERSION)/ $(VERSION) | xz >../$(DEBPKGNAME)_$(VERSION).orig.tar.xz
        if ! git checkout master ; then \
                echo "No upstream branch: checking out" ; \
                git checkout -b master upstream/master ; \
@@ -55,3 +70,10 @@ regen-manifest-patch:
 # Enable XZ compression in the .debs
 override_dh_builddeb:
        dh_builddeb -- -Zxz -z9
+
+override_dh_auto_build:
+       dh_auto_build
+
+       chmod +x $(CURDIR)/debian/pkgos_insert_include
+       $(CURDIR)/debian/pkgos_insert_include pkgos_func cinder-common.config
+       $(CURDIR)/debian/pkgos_insert_include pkgos_func cinder-common.postinst