#! /bin/sh # postinst script for monotone-server # # This script attempts to perform any db migrations neccessary during an # upgrade. # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package # # source debconf stuff . /usr/share/debconf/confmodule MTN=/usr/bin/mtn monotone_check_minimum_previous_version () { if dpkg --compare-versions "$MTN_VERSION" lt "0.17"; then # monotone version to old to automatically upgrade echo "Cannot automatically upgrade from monotone version $2." >&2 echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2 echo "information on manually upgrading your database." >&2 /bin/false else /bin/true fi } monotone_migrate () { if dpkg --compare-versions "$MTN_VERSION" lt "0.33-90.1"; then # upgradable version of monotone echo "Attempting to migrate monotone database. This may take a while..." >&2 echo "A backup named '`basename $MTN_DB~`' will be created in $MTN_HOME." >&2 cp $MTN_DB $MTN_DB~ if $MTN --db=$MTN_DB db migrate --rcfile=$MTN_CONFDIR/hooks.lua \ --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then echo "Database successfully migrated." >&2 /bin/true else echo "*** Error migrating database. ***" >&2 echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2 echo "information on manually upgrading your database." >&2 /bin/false fi else /bin/true fi } monotone_rosterify () { if dpkg --compare-versions "$MTN_VERSION" lt "0.26"; then # now we need to rosterify echo "Attempting to rosterify monotone database..." >&2 if $MTN --db=$MTN_DB db rosterify --rcfile=$MTN_CONFDIR/hooks.lua \ --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then echo "Database successfully rosterified." >&2 /bin/true else echo "*** Error rosterifying database. ***" >&2 echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2 echo "information on manually upgrading your database." >&2 /bin/false fi else /bin/true fi } monotone_regenerate_caches () { if dpkg --compare-versions "$MTN_VERSION" lt "0.31-90.1"; then # now we need to regenerate caches echo "Attempting to regenerate caches..." >&2 if $MTN --db=$MTN_DB db regenerate_caches --rcfile=$MTN_CONFDIR/hooks.lua \ --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then echo "Caches successfully regenerated." >&2 /bin/true else echo "*** Error regenerating roster. ***" >&2 echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2 echo "information on manually upgrading your database." >&2 /bin/false fi else /bin/true fi } case "$1" in configure) MTN_HOME=/var/lib/monotone MTN_DB=$MTN_HOME/default.mtn MTN_CONFDIR=/etc/monotone MTN_KEYDIR=$MTN_HOME/keys ucf --debconf-ok /usr/share/doc/monotone-server/examples/write-permissions /etc/monotone/write-permissions ucf --debconf-ok /usr/share/doc/monotone-server/examples/read-permissions /etc/monotone/read-permissions ucf --debconf-ok /usr/share/doc/monotone/contrib/get_passphrase_from_file.lua /etc/monotone/hooks.lua ucfr monotone-server /etc/monotone/write-permissions ucfr monotone-server /etc/monotone/read-permissions ucfr monotone-server /etc/monotone/hooks.lua # if this is our first install give config files correct permissions if [ -z "$2" ]; then # create monotone user and fix permissions of files if [ -z "`id -u monotone 2>/dev/null`" ]; then adduser --system --group --home $MTN_HOME \ --no-create-home --disabled-password --quiet \ --gecos "Monotone" monotone fi chown monotone:monotone $MTN_HOME chown monotone:monotone $MTN_CONFDIR chown monotone:monotone $MTN_KEYDIR chown monotone:monotone /var/log/monotone chown monotone:monotone /var/run/monotone chmod 0750 $MTN_HOME chmod 0750 $MTN_CONFDIR chmod 0750 $MTN_KEYDIR chown monotone:monotone /etc/monotone/write-permissions chown monotone:monotone /etc/monotone/read-permissions chown monotone:monotone /etc/monotone/hooks.lua chmod 0640 /etc/monotone/write-permissions chmod 0640 /etc/monotone/read-permissions chmod 0640 /etc/monotone/hooks.lua fi db_get monotone-server/manage-db if [ "$RET" = "true" ]; then db_get monotone-server/key MTN_KEY=$RET # read our passphrase from a file if [ -e "$MTN_CONFDIR/passphrases" ]; then db_set monotone-server/passphrase "`grep "$MTN_KEY" $MTN_CONFDIR/passphrases | awk -F ' "|" "|" |"' '{print $2}'`" fi db_get monotone-server/passphrase MTN_KEY_PASSWD=$RET MTN_VERSION="$2" # Since we are configuring, we should check if we are upgrading. If we are # upgrading, we should run the proper db migrate commands if necessary. if [ -z "$2" ]; then # not upgrading, fresh install # if there is no database, create one if [ ! -e $MTN_DB ]; then echo "Creating Monotone database..." >&2 $MTN --db=$MTN_DB db init \ --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR chmod 0600 $MTN_DB chown monotone:monotone $MTN_DB echo "Creating Monotone server keypair..." >&2 yes "$MTN_KEY_PASSWD" | $MTN --db=$MTN_DB genkey $MTN_KEY --quiet \ --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR chown monotone:monotone $MTN_HOME/keys/* echo "Monotone database created successfully." >&2 fi else set +e monotone_check_minimum_previous_version && \ monotone_migrate && \ monotone_rosterify && \ monotone_regenerate_caches set -e fi echo "$MTN_KEY \"$MTN_KEY_PASSWD\"" > $MTN_CONFDIR/passphrases chown monotone:monotone $MTN_CONFDIR/passphrases chmod 0400 $MTN_CONFDIR/passphrases db_set monotone-server/passphrase "" fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # stop debconf db_stop # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0