#!/bin/sh # postinst script for redmine # # see: dh_installdeb(1) set -e #set -x RAKE_VERBOSE=false . /usr/share/debconf/confmodule # remove and purge old instances each time postinst is called db_get redmine/old-instances || true gOldInstances="${RET}" for lInstance in $gOldInstances; do db_get redmine/instances/$lInstance/dbconfig-install || true if [ "$RET" = "true" ]; then ( . /usr/share/dbconfig-common/dpkg/prerm ; dbc_go redmine/instances/$lInstance remove ) fi done for lInstance in $gOldInstances; do db_get redmine/instances/$lInstance/dbconfig-install || true if [ "$RET" = "true" ]; then ( . /usr/share/dbconfig-common/dpkg/postrm ; dbc_go redmine/instances/$lInstance purge ) fi if which ucf >/dev/null 2>&1; then ucf --purge /etc/redmine/$lInstance/database.yml ucf --purge /etc/redmine/$lInstance/email.yml ucf --purge /etc/redmine/$lInstance/session.yml fi rm -rf /etc/redmine/$lInstance done db_set redmine/old-instances "" fRailsEnv=production fRailsLog=/var/log/redmine fRailsVar=/var/lib/redmine fRailsCache=/var/cache/redmine fRailsRun=/var/run/redmine case "$1" in configure|reconfigure) # passenger runs as the owner of that file, thanks Micah Anderson. chown www-data:root /usr/share/redmine/config/environment.rb mkdir -p $fRailsRun/sockets chown -f www-data:www-data $fRailsRun chown -f www-data:www-data $fRailsRun/sockets chown -f www-data:www-data $fRailsLog chown -f www-data:www-data $fRailsVar chown -f www-data:www-data $fRailsCache savedir="`pwd`" cd /usr/share/redmine if [ -L vendor/railties ]; then # rails 2.2 to 2.3 migration rm -f vendor/actionmailer rm -f vendor/actionpack rm -f vendor/activemodel rm -f vendor/activerecord rm -f vendor/activeresource rm -f vendor/activesupport rm -f vendor/railties rm -f vendor/rails fi if [ ! -L vendor/rails ]; then ln -s /usr/share/rails-ruby1.8 vendor/rails fi if [ ! -e app/views/members ]; then mkdir app/views/members fi if [ ! -e app/sweepers ]; then mkdir app/sweepers fi if [ ! -e lib/plugins ]; then mkdir lib/plugins fi # this directory should never be used: /usr not writable policy if [ -e tmp ]; then rm -rf tmp fi cd $savedir ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac db_get redmine/current-instances || true gInstances="${RET}" for lInstance in $gInstances; do fRailsEtc=/etc/redmine/$lInstance fRailsLog=/var/log/redmine/$lInstance fRailsVar=/var/lib/redmine/$lInstance fRailsCache=/var/cache/redmine/$lInstance # dbconfig needs this folder to ouput database.yml mkdir -p $fRailsEtc chown -f www-data:www-data $fRailsEtc withdb=0 lInstall=0 db_get redmine/instances/$lInstance/dbconfig-install || true if [ "$RET" = "true" ]; then lInstall=1 fCode=0 db_get redmine/instances/$lInstance/dbconfig-reinstall || fCode=$? if [ $fCode -eq 0 ]; then if [ "$RET" = "false" ]; then db_fget redmine/instances/$lInstance/dbconfig-reinstall seen || true if [ "$RET" = "true" ]; then lInstall=0 fi fi fi fi if [ $lInstall -eq 1 ]; then fYml=$fRailsEtc/database.yml.new lTemplate="database.yml.template" # if dbtype=sqlite3, use dbbasepath, else dbname fCode=0 db_get redmine/instances/$lInstance/database-type || fCode=$? lDbType="$RET" if [ $fCode -eq 0 -a "$lDbType" = "sqlite3" ]; then lTemplate="database-sqlite.yml.template" lDbType="sqlite" fi # check if redmine-$lDbType is installed, if not, don't configure and explain what to do hasPack=$(dpkg-query -W -f='${Status}\n' "redmine-$lDbType" |cut -d" " -f3) if [ "$hasPack" != "installed" ]; then # not installed, this cannot be detected in debian/config # since redmine-* packages are not yet installed db_subst redmine/missing-redmine-package dbtype "$lDbType" db_subst redmine/missing-redmine-package instance "$lInstance" db_fset redmine/missing-redmine-package seen "false" db_input high redmine/missing-redmine-package || true db_go || true db_stop || true echo "Skipping $lInstance because of missing dependency." continue fi dbc_generate_include=template:$fYml dbc_generate_include_args="-o template_infile=/usr/share/redmine/templates/${lTemplate}" dbc_generate_include_owner="root:www-data" dbc_generate_include_perms="640" dbc_dbfile_owner="root:www-data" # this is for sqlite3 to be r/w for www-data dbc_dbfile_perms="0660" dbc_dbuser=redmine # make sure mysql or pgsql database charset is UTF8 dbc_mysql_createdb_encoding="UTF8" dbc_pgsql_createdb_encoding="UTF8" # use same dbname if one has been registered in debconf before # this is also needed for migration from version <= 0.9.0~svn2819 fCode=0 db_get redmine/instances/$lInstance/db/dbname || fCode=$? if [ $fCode -eq 0 -a -n "$RET" ]; then dbc_dbname="$RET" else dbc_dbname=redmine_$lInstance fi fCode=0 db_get redmine/instances/$lInstance/db/basepath || fCode=$? if [ $fCode -eq 0 -a -n "$RET" ]; then dbc_basepath="$RET" fi ucf --purge $fYml ( . /usr/share/dbconfig-common/dpkg/postinst ; dbc_go redmine/instances/$lInstance $@ ) ucf --purge $fYml if [ -e $fYml ]; then hasdb=$(grep -m 1 -o -E 'adapter: (mysql|pgsql|sqlite3|postgresql)' $fYml) || true if [ -n "$hasdb" ]; then hasdb=$(echo -n ${hasdb#*:}) withdb=1 case "$hasdb" in mysql|postgresql|pgsql) sed -i -r -e 's/pgsql/postgresql/g' $fYml ;; sqlite3) sed -i -r -e 's/^[^#]+((host|port|username|password): [^:]*)$/# \1/g' $fYml ;; esac fi ucf --debconf-ok $fYml /etc/redmine/$lInstance/database.yml rm -f $fYml fi elif [ -e "$fRailsEtc/database.yml" ]; then # don't reinstall, but upgrade withdb=1 lInstall=0 fi case "$1" in configure|reconfigure) # create directories mkdir -p $fRailsLog mkdir -p $fRailsVar mkdir -p $fRailsVar/files mkdir -p $fRailsCache mkdir -p $fRailsCache/plugin_assets chmod 750 $fRailsLog chmod 750 $fRailsVar chmod 755 $fRailsCache chmod 755 $fRailsCache/plugin_assets chown -f www-data:www-data $fRailsLog chown -f www-data:www-data $fRailsVar chown -f www-data:www-data $fRailsVar/files chown -f www-data:www-data $fRailsCache chown -f www-data:www-data $fRailsCache/plugin_assets mkdir -p /var/run/redmine/sockets/${lInstance} chown -f www-data:www-data /var/run/redmine/sockets/${lInstance} savedir="`pwd`" cd /usr/share/redmine # copy schema.db to its instance directory if [ -f db/schema.db ]; then cp db/schema.db $fRailsCache/schema.db fi # add secret key, set permissions, manage file with ucf if [ ! -f "${fRailsEtc}/session.yml" ]; then rake -s generate_session_store YML_SESSION_FILENAME="session.yml.new" RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" || true chown -f root:www-data ${fRailsEtc}/session.yml.new chmod 640 ${fRailsEtc}/session.yml.new ucf --debconf-ok ${fRailsEtc}/session.yml.new ${fRailsEtc}/session.yml rm ${fRailsEtc}/session.yml.new # move old session_store.rb echo "A new secret session key has been generated in ${fRailsEtc}/session.yml" else fHasOldSessionName=$(fgrep -c session_key "${fRailsEtc}/session.yml" || true) if [ $fHasOldSessionName -gt 0 ]; then # in-place, because ucf might be configured to keep the old version without asking sed -i -r -e 's/session_key/key/g' ${fRailsEtc}/session.yml fi fi if [ -f config/initializers/session_store.rb ]; then mv config/initializers/session_store.rb config/initializers/session_store.rb.dpkg-old echo "The old secret session key can be found in /usr/share/redmine/config/initializers/session_store.rb.dpkg-old" fi if [ $withdb -eq 1 ]; then db_get redmine/instances/${lInstance}/default-language && DEFAULT_LANGUAGE="$RET" # handle rake install echo "Populating database for redmine instance \"${lInstance}\". This may take a while." rake -s db:migrate RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" VERBOSE=$RAKE_VERBOSE || true echo "Done." if [ $lInstall -eq 1 ]; then rake -s redmine:load_default_data RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" REDMINE_LANG=$DEFAULT_LANGUAGE || true # because rake task is executed as root here, and this file is used later by web server, make sure owner is www-data touch ${fRailsLog}/production.log chown -f www-data:www-data ${fRailsLog}/production.log fi # handle plugins migration rake -s db:migrate_plugins RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" VERBOSE=$RAKE_VERBOSE || true else echo "Redmine instance \"${lInstance}\" database must be configured manually." fi cd $savedir || true ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac done #DEBHELPER# exit 0