From 676980a4a24913a9f4c8f0801cc4e4b6e4a0d8e5 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Fri, 26 Oct 2012 11:07:48 +0000 Subject: [PATCH] * 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/ 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. Rewritten-From: d239a41dc96d1b9bd509ef602f7843fe246423cb --- xenial/debian/changelog | 12 + xenial/debian/cinder-api.postrm | 3 - xenial/debian/cinder-common.config | 44 --- xenial/debian/cinder-common.config.in | 29 ++ xenial/debian/cinder-common.install | 1 - xenial/debian/cinder-common.lintian-overrides | 1 + xenial/debian/cinder-common.postinst | 79 ----- xenial/debian/cinder-common.postinst.in | 24 ++ xenial/debian/cinder-common.postrm | 43 ++- xenial/debian/cinder-common.prerm | 2 +- .../{cinder_sudoers => cinder-common.sudoers} | 0 xenial/debian/cinder-common.templates | 4 +- xenial/debian/cinder-scheduler.postinst | 4 - xenial/debian/cinder-scheduler.postrm | 3 - xenial/debian/cinder-volume.postrm | 3 - xenial/debian/control | 133 +++++--- xenial/debian/copyright | 8 +- xenial/debian/pkgos_func | 323 ++++++++++++++++++ xenial/debian/pkgos_insert_include | 15 + xenial/debian/rules | 28 +- 20 files changed, 539 insertions(+), 220 deletions(-) delete mode 100644 xenial/debian/cinder-api.postrm delete mode 100644 xenial/debian/cinder-common.config create mode 100644 xenial/debian/cinder-common.config.in create mode 100644 xenial/debian/cinder-common.lintian-overrides delete mode 100644 xenial/debian/cinder-common.postinst create mode 100644 xenial/debian/cinder-common.postinst.in rename xenial/debian/{cinder_sudoers => cinder-common.sudoers} (100%) delete mode 100644 xenial/debian/cinder-scheduler.postinst delete mode 100644 xenial/debian/cinder-scheduler.postrm delete mode 100644 xenial/debian/cinder-volume.postrm create mode 100644 xenial/debian/pkgos_func create mode 100755 xenial/debian/pkgos_insert_include diff --git a/xenial/debian/changelog b/xenial/debian/changelog index 8a744ce20..4c863ad01 100644 --- a/xenial/debian/changelog +++ b/xenial/debian/changelog @@ -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/ 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 Sat, 29 Sep 2012 09:23:22 +0200 diff --git a/xenial/debian/cinder-api.postrm b/xenial/debian/cinder-api.postrm deleted file mode 100644 index 07fe0c204..000000000 --- a/xenial/debian/cinder-api.postrm +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e - -#DEBHELPER# diff --git a/xenial/debian/cinder-common.config b/xenial/debian/cinder-common.config deleted file mode 100644 index 900125405..000000000 --- a/xenial/debian/cinder-common.config +++ /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/xenial/debian/cinder-common.config.in b/xenial/debian/cinder-common.config.in new file mode 100644 index 000000000..f8b7570e6 --- /dev/null +++ b/xenial/debian/cinder-common.config.in @@ -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 diff --git a/xenial/debian/cinder-common.install b/xenial/debian/cinder-common.install index 0a443618c..484de9fb7 100644 --- a/xenial/debian/cinder-common.install +++ b/xenial/debian/cinder-common.install @@ -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/xenial/debian/cinder-common.lintian-overrides b/xenial/debian/cinder-common.lintian-overrides new file mode 100644 index 000000000..d0fb1cc18 --- /dev/null +++ b/xenial/debian/cinder-common.lintian-overrides @@ -0,0 +1 @@ +cinder-common: unused-debconf-template cinder/start_services diff --git a/xenial/debian/cinder-common.postinst b/xenial/debian/cinder-common.postinst deleted file mode 100644 index 5b6b51ca8..000000000 --- a/xenial/debian/cinder-common.postinst +++ /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/xenial/debian/cinder-common.postinst.in b/xenial/debian/cinder-common.postinst.in new file mode 100644 index 000000000..df75c7391 --- /dev/null +++ b/xenial/debian/cinder-common.postinst.in @@ -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 diff --git a/xenial/debian/cinder-common.postrm b/xenial/debian/cinder-common.postrm index b2335705f..365f34c3e 100644 --- a/xenial/debian/cinder-common.postrm +++ b/xenial/debian/cinder-common.postrm @@ -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# diff --git a/xenial/debian/cinder-common.prerm b/xenial/debian/cinder-common.prerm index 75b6ce159..8e6f542b8 100644 --- a/xenial/debian/cinder-common.prerm +++ b/xenial/debian/cinder-common.prerm @@ -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 $@ diff --git a/xenial/debian/cinder_sudoers b/xenial/debian/cinder-common.sudoers similarity index 100% rename from xenial/debian/cinder_sudoers rename to xenial/debian/cinder-common.sudoers diff --git a/xenial/debian/cinder-common.templates b/xenial/debian/cinder-common.templates index f1b7b4baa..367e7c105 100644 --- a/xenial/debian/cinder-common.templates +++ b/xenial/debian/cinder-common.templates @@ -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/xenial/debian/cinder-scheduler.postinst b/xenial/debian/cinder-scheduler.postinst deleted file mode 100644 index 1072f3c36..000000000 --- a/xenial/debian/cinder-scheduler.postinst +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -e - - -#DEBHELPER# diff --git a/xenial/debian/cinder-scheduler.postrm b/xenial/debian/cinder-scheduler.postrm deleted file mode 100644 index 07fe0c204..000000000 --- a/xenial/debian/cinder-scheduler.postrm +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e - -#DEBHELPER# diff --git a/xenial/debian/cinder-volume.postrm b/xenial/debian/cinder-volume.postrm deleted file mode 100644 index 07fe0c204..000000000 --- a/xenial/debian/cinder-volume.postrm +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e - -#DEBHELPER# diff --git a/xenial/debian/control b/xenial/debian/control index cbb8d3a74..03a5ec299 100644 --- a/xenial/debian/control +++ b/xenial/debian/control @@ -2,104 +2,135 @@ Source: cinder Section: net Priority: extra Maintainer: PKG OpenStack -Uploaders: Mehdi Abaakouk +Uploaders: Loic Dachary (OuoU) , + Julien Danjou , + Thomas Goirand , + Ghe Rivero , + Mehdi Abaakouk 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. diff --git a/xenial/debian/copyright b/xenial/debian/copyright index 28c6615b4..4b57f0805 100644 --- a/xenial/debian/copyright +++ b/xenial/debian/copyright @@ -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/xenial/debian/pkgos_func b/xenial/debian/pkgos_func new file mode 100644 index 000000000..96ba923a6 --- /dev/null +++ b/xenial/debian/pkgos_func @@ -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}/ 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/xenial/debian/pkgos_insert_include b/xenial/debian/pkgos_insert_include new file mode 100755 index 000000000..b0e9697a9 --- /dev/null +++ b/xenial/debian/pkgos_insert_include @@ -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} diff --git a/xenial/debian/rules b/xenial/debian/rules index 50db4c100..c5cb20f69 100755 --- a/xenial/debian/rules +++ b/xenial/debian/rules @@ -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 -- 2.45.2