aegir-provision.postinst 3.89 KB
Newer Older
anarcat's avatar
anarcat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#!/bin/sh
# postinst script for provision
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

VARLIB="/var/lib/aegir"

case "$1" in
    configure)
        # add a aegir user if one does not already exist
        if ! getent passwd aegir >/dev/null ; then
            echo "adding aegir user..."
            adduser --quiet --system --no-create-home --group \
                --home "$VARLIB" \
                --shell '/bin/bash' \
                --gecos 'Aegir user,,,' \
                aegir
        fi
        adduser --quiet aegir www-data

        TEMPFILE=`tempfile`
        sedscript=""
        for binary in /usr/sbin/apachectl /usr/sbin/apache2ctl ; do
            if [ -x $binary ] ; then
                sedscript=$sedscript';s#^\#\?\(.*'$binary'.*\)$#\1#'
            else
                sedscript=$sedscript';s#^\#\?\(.*'$binary'.*\)$#\#\1#'
            fi
        done
        if ! [ -z "$sedscript" ]; then
            sed -e "$sedscript" /usr/share/doc/aegir-provision/examples/example.sudoers >> $TEMPFILE
        else
            # this should happend, but still handle gracefully
            cp /usr/share/doc/aegir-provision/examples/examples.sudoers $TEMPFILE
        fi
        
        ucf $TEMPFILE /etc/sudoers.d/aegir
        rm -f $TEMPFILE
        ucfr aegir-provision /etc/sudoers.d/aegir

        # create apache configuration for aegir
        if [ -x /usr/sbin/apache2ctl ] ; then
            ln -sf /etc/aegir/apache.conf /etc/apache2/conf.d/aegir.conf
            invoke-rc.d apache2 force-reload
        elif [ -x /usr/sbin/apachectl ] ; then
            ln -sf /etc/aegir/apache.conf /etc/apache/conf.d/aegir.conf
            invoke-rc.d apache force-reload
        fi

        # fix permissions on installed directories
        chown aegir:aegir "$VARLIB"
        for dir in /etc/drush /etc/aegir /var/backups/aegir ; do
            chown aegir:aegir $dir
            chmod 0700 $dir
        done

        # old 0.3-2 cruft, we now write directly to /etc/drush
        if [ -e /etc/aegir/drushrc.php ]; then
            ucf /etc/aegir/drushrc.php /etc/drush/drushrc.php
            ucf --purge /etc/aegir/drushrc.php
            rm -f /etc/aegir/drushrc.php
        fi

        TEMPFILE=`tempfile`
        # fix the apache restart command if we're running apache2
        if [ -x /usr/sbin/apache2ctl ] ; then
            command='/usr/sbin/apache2ctl'
        else
            command='/usr/sbin/apachectl'
        fi

        cat >> $TEMPFILE <<EOF
<?php
# this file is automatically regenerated by aegir-provision postinst scripts
# modify at your own risks
\$options['web_group'] = 'www-data';
\$options['script_user'] = 'aegir';
\$options['backup_path'] = '/var/backups/aegir';
\$options['config_path'] = '/etc/aegir';
\$options['restart_cmd'] = 'sudo $command graceful';
EOF
        # note that aegir-provision is the owner of the drushrc.php
        # configuration file, not drush.
        ucf $TEMPFILE /etc/drush/drushrc.php
        rm -f $TEMPFILE
        ucfr aegir-provision /etc/drush/drushrc.php
        chown aegir:aegir /etc/drush/drushrc.php
        chown 640 /etc/drush/drushrc.php

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0