[DRE-commits] [redmine] 24/39: initial rewrite of maintainer scripts
Antonio Terceiro
terceiro at moszumanska.debian.org
Tue Dec 8 12:56:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to branch master
in repository redmine.
commit 31a348711957b9d2102aad84f8ba076f63c59d94
Author: Antonio Terceiro <terceiro at debian.org>
Date: Mon Sep 28 18:03:10 2015 -0300
initial rewrite of maintainer scripts
---
...se.yml.template => database-mysql.yml.template} | 2 +-
...se.yml.template => database-pgsql.yml.template} | 2 +-
debian/config | 37 ++++++++++++-
debian/postinst | 60 +++++++++++++++-------
debian/postrm | 21 +++++++-
debian/prerm | 10 +++-
debian/templates | 7 ---
7 files changed, 107 insertions(+), 32 deletions(-)
diff --git a/debian/conf/database.yml.template b/debian/conf/database-mysql.yml.template
similarity index 86%
copy from debian/conf/database.yml.template
copy to debian/conf/database-mysql.yml.template
index a85338a..277aede 100644
--- a/debian/conf/database.yml.template
+++ b/debian/conf/database-mysql.yml.template
@@ -1,5 +1,5 @@
production:
- adapter: _DBC_DBTYPE_
+ adapter: mysql2
database: _DBC_DBNAME_
host: _DBC_DBSERVER_
port: _DBC_DBPORT_
diff --git a/debian/conf/database.yml.template b/debian/conf/database-pgsql.yml.template
similarity index 86%
rename from debian/conf/database.yml.template
rename to debian/conf/database-pgsql.yml.template
index a85338a..8cccfc5 100644
--- a/debian/conf/database.yml.template
+++ b/debian/conf/database-pgsql.yml.template
@@ -1,5 +1,5 @@
production:
- adapter: _DBC_DBTYPE_
+ adapter: postgresql
database: _DBC_DBNAME_
host: _DBC_DBSERVER_
port: _DBC_DBPORT_
diff --git a/debian/config b/debian/config
index bed4075..fad70ce 100644
--- a/debian/config
+++ b/debian/config
@@ -7,5 +7,40 @@ set -e
if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
dbc_dbtypes="sqlite3, pgsql, mysql"
. /usr/share/dbconfig-common/dpkg/config
- dbc_go redmine "$@"
+
+ db_set redmine/old-instances ""
+ db_get redmine/current-instances || true
+ original_instances="$RET"
+
+ db_input medium redmine/current-instances || true
+ db_go
+ current_instances="$RET"
+ if [ -z "$current_instances" ]; then
+ current_instances='default'
+ fi
+
+ for inst in $current_instances; do
+ dbc_go redmine/instances/$inst "$@"
+
+ # TODO handle language for initial db data
+ done
+
+ # determine which instances were removed and store in redmine/old-instances
+ removed_instances=""
+ separator=""
+ for orig in $original_instances; do
+ removed='true'
+ for curr in $current_instances; do
+ if [ "$orig" = "$curr" ]; then
+ removed='false'
+ break
+ fi
+ done
+ if [ "$removed" = 'true' ]; then
+ removed_instances="${separator}$removed_instances"
+ separator=" "
+ fi
+ done
+ db_set redmine/old-instances "$removed_instances"
+
fi
diff --git a/debian/postinst b/debian/postinst
index 22c7152..f141c96 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -12,27 +12,51 @@ rm -f /var/lib/redmine/Gemfile.lock
chown www-data:www-data /var/lib/redmine/Gemfile.lock
#######################################################################
-# manage database
+# manage instances
#######################################################################
. /usr/share/dbconfig-common/dpkg/postinst
-dbc_generate_include=template:/etc/redmine/database.yml # FIXME
-dbc_generate_include_args="-o template_infile=/usr/share/redmine/templates/database-sqlite.yml.template" # FIXME
-dbc_generate_include_owner="root:www-data"
-dbc_generate_include_perms="640"
-dbc_dbfile_owner="root:www-data"
-dbc_dbuser=redmine # FIXME
-# this is for sqlite3 to be r/w for www-data
-dbc_dbfile_perms="0660"
-dbc_mysql_createdb_encoding="UTF8"
-dbc_pgsql_createdb_encoding="UTF8"
-dbc_dbname=redmine # FIXME
-
-dbc_go redmine "$@"
-if [ -f /etc/redmine/database.yml ]; then
- sed -i -i 's/mysql/mysql2/g; s/pgsql/postgresql/g' /etc/redmine/database.yml # FIXME
-fi
-
+manage_instance() {
+ local instance="$1"
+
+ db_get redmine/instances/$instance/database-type || true
+ local dbtype="$RET"
+
+ dbc_generate_include=template:/etc/redmine/$instance/database.yml
+ dbc_generate_include_args="-o template_infile=/usr/share/redmine/templates/database-${dbtype}.yml.template"
+ dbc_generate_include_owner="root:www-data"
+ dbc_generate_include_perms="640"
+ dbc_dbfile_owner="root:www-data"
+ dbc_dbuser=redmine_$instance
+ # this is for sqlite3 to be r/w for www-data
+ dbc_dbfile_perms="0660"
+ dbc_mysql_createdb_encoding="UTF8"
+ dbc_pgsql_createdb_encoding="UTF8"
+ dbc_dbname=redmine_$instance
+
+ dbc_go redmine/instances/$instance "$@"
+
+ cd /usr/share/redmine
+ su redmine -c "bundle exec rake db:migrate REDMINE_INSTANCE=$instance SCHEMA=/dev/null"
+}
+
+remove_instance() {
+ local instance="$1"
+ # TODO
+ echo "Removing instance $instance ..."
+}
+
+db_get redmine/current-instances || true
+instances="$RET"
+for inst in $instances; do
+ manage_instance "$inst"
+done
+
+db_get redmine/old-instances || true
+removed_instances="$RET"
+for inst in $removed_instances; do
+ remove_instance "$inst"
+done
##DEBHELPER##
diff --git a/debian/postrm b/debian/postrm
index 82fa12f..6f23a00 100644
--- a/debian/postrm
+++ b/debian/postrm
@@ -3,10 +3,27 @@
set -e
. /usr/share/debconf/confmodule
-
if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
. /usr/share/dbconfig-common/dpkg/postrm
- dbc_go
+
+ db_get redmine/current-instances || true
+ instances="$RET"
+
+ # remove all instances
+ for inst in "$instances"; do
+ dbc_go redmine/instances/$inst "$@"
+ done
fi
+case "$1" in
+ purge)
+ rm -f /var/lib/redmine/Gemfile.lock
+ rm -rf /etc/redmine
+ ;;
+ *)
+ echo "postrm called with invalid argument: $1" >&2
+ exit 1
+ ;;
+esac
+
##DEBHELPER##
diff --git a/debian/prerm b/debian/prerm
index 4013b6a..cc39863 100644
--- a/debian/prerm
+++ b/debian/prerm
@@ -3,10 +3,16 @@
set -e
. /usr/share/debconf/confmodule
-
if [ -f /usr/share/dbconfig-common/dpkg/prerm ]; then
. /usr/share/dbconfig-common/dpkg/prerm
- dbc_go
+
+ db_get redmine/current-instances || true
+ instances="$RET"
+
+ # remove all instances
+ for inst in "$instances"; do
+ dbc_go redmine/instances/$inst "$@"
+ done
fi
##DEBHELPER##
diff --git a/debian/templates b/debian/templates
index 8a71f18..a66a359 100644
--- a/debian/templates
+++ b/debian/templates
@@ -1,10 +1,3 @@
-Template: redmine/notify-migration
-Type: note
-_Description: Redmine package now supports multiple instances
- You are migrating from an unsupported version.
- The current instance will be now called the "default" instance.
- Please check your web server configuration files, see README.Debian.
-
Template: redmine/old-instances
Type: string
_Description: Redmine instances to be deconfigured:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/redmine.git
More information about the Pkg-ruby-extras-commits
mailing list