aegir2-cluster-slave.postinst 3.8 KB
Newer Older
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
#!/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

# Source debconf library.
. /usr/share/debconf/confmodule

if [ "$DPKG_DEBUG" = "developer" ]; then
    set -x
fi

anarcat's avatar
anarcat committed
27
# when changing this, change the regex in the sed replacement below
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
VARLIB="/var/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

        if [ -d /etc/sudoers.d ]; then
44
            ucf --debconf-ok /usr/share/doc/aegir-cluster-slave2/examples/example.sudoers /etc/sudoers.d/aegir
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
            ucfr aegir-provision /etc/sudoers.d/aegir
            chmod 440 /etc/sudoers.d/aegir
        else
            echo "running an older version of sudo"
            echo "copy content of /usr/share/doc/aegir-provision/examples/example.sudoers into /etc/sudoers for aegir to run properly"
        fi

        # fix permissions on installed directories
        chown aegir:aegir "$VARLIB" "$VARLIB/config"
        # make sure we have apache configs settled in, for remote headless aegir servers
        touch $VARLIB/config/apache.conf
        chown aegir:aegir "$VARLIB/config/apache.conf"
        ln -sf $VARLIB/config/apache.conf /etc/apache2/conf.d/aegir.conf
        a2enmod ssl rewrite
        apache2ctl graceful

        db_get "aegir/master_ssh_key"
        SSH_KEY="$RET"
63 64 65 66 67 68 69 70
        if ! [ -z "$SSH_KEY" ]; then
            if ! grep -q "$SSH_KEY" $VARLIB/.ssh/authorized_keys; then
                mkdir -p $VARLIB/.ssh
                echo "$SSH_KEY" >> $VARLIB/.ssh/authorized_keys
                chown aegir:aegir $VARLIB/.ssh $VARLIB/.ssh/authorized_keys
                chmod 700 $VARLIB/.ssh
                chmod 600 $VARLIB/.ssh/authorized_keys
            fi
71 72 73
        fi
        db_get "aegir/master_mountpoint"
        MOUNT="$RET"
74 75 76 77 78 79 80 81 82 83 84
        if ! [ -z "$MOUNT" ]; then
            if grep -q "$VARLIB/platforms" /etc/fstab ; then
                if ! grep -q "$MOUNT.*$VARLIB/platforms" /etc/fstab ; then
                    sed -i.dpkg-orig "/\/var\\/aegir\\/platforms/s#^.*\$#$MOUNT $VARLIB/platforms nfs rw 0 0#" /etc/fstab
                    echo "installed new fstab, original kept in /etc/fstab.dpkg-orig"
                    echo "for the changes to take effect, the $VARLIB/platforms directory need to be remounted"
                    echo "this may require a reboot"
                fi
            else
                cp /etc/fstab /etc/fstab.dpkg-orig
                echo "$MOUNT $VARLIB/platforms nfs rw 0 0" >> /etc/fstab
85 86
                echo "installed new fstab, original kept in /etc/fstab.dpkg-orig"
            fi
anarcat's avatar
anarcat committed
87
            if ! mount | grep -q $VARLIB/platforms; then
88 89
                mount $VARLIB/platforms
            fi
90
        fi
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    ;;

    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