aegir-provision.postinst 4.84 KB
Newer Older
1
#!/bin/sh
anarcat's avatar
anarcat committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

anarcat's avatar
anarcat committed
20
21
22
# Source debconf library.
. /usr/share/debconf/confmodule

anarcat's avatar
anarcat committed
23
VARLIB="/var/aegir"
anarcat's avatar
anarcat committed
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

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
anarcat's avatar
anarcat committed
50
            # this shouldn't happen, but still handle gracefully
anarcat's avatar
anarcat committed
51
52
53
            cp /usr/share/doc/aegir-provision/examples/examples.sudoers $TEMPFILE
        fi
        
anarcat's avatar
anarcat committed
54
        ucf --debconf-ok $TEMPFILE /etc/sudoers.d/aegir
anarcat's avatar
anarcat committed
55
56
        rm -f $TEMPFILE
        ucfr aegir-provision /etc/sudoers.d/aegir
57
        chmod 440 /etc/sudoers.d/aegir
anarcat's avatar
anarcat committed
58
59
60

        # fix permissions on installed directories
        chown aegir:aegir "$VARLIB"
61
        for dir in "$VARLIB"/backups "$VARLIB"/config ; do
anarcat's avatar
anarcat committed
62
63
64
65
            chown aegir:aegir $dir
            chmod 0700 $dir
        done

66
67
68
69
        # fetch the version number from the makefile. the line we're looking for looks like this
        # projects[hostmaster][download][url] = "http://files.aegirproject.org/hostmaster-0.4-beta1.tgz"
        # this obviously doesn't work for git releases
        VERSION=`sed -ne '/hostmaster..download..url/{s/^.*hostmaster-//;s/.tgz"//;p}' /usr/share/drush/commands/provision/aegir.make`
anarcat's avatar
anarcat committed
70
71
72
73

        TEMPFILE=`tempfile`
        su aegir -c 'drush @hostmaster status' >> $TEMPFILE || true
        if grep -q 'Drupal bootstrap.*Successful' $TEMPFILE; then
74
75
            db_fset aegir/db_password "seen" "true" || true

anarcat's avatar
anarcat committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
            # there's already an install
            SITE=`grep URI $TEMPFILE | sed -e 's/^.*://'`
            OLD_PLATFORM=`grep 'Drupal root' $TEMPFILE | sed -e 's/^.*://'`
            NEW_PLATFORM="$VARLIB/hostmaster-$VERSION"
            if [ -d "$NEW_PLATFORM" ]; then
                # this is not an upgrade, do nothing
                db_stop
                echo "this is not an upgrade, just updated the backend"
            else
                # this is an upgrade
                cd "$OLD_PLATFORM"
                su aegir -c "drush hostmaster-migrate '$SITE' '$NEW_PLATFORM'"
            fi
        else
90
            db_fset aegir/db_password "seen" "false" || true
anarcat's avatar
anarcat committed
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
            db_get "aegir/site"
            if [ ! -z "$RET" ]; then
                SITE="$RET"
            fi
            db_get "aegir/db_host"
            AEGIR_DB_HOST="$RET"
            db_get "aegir/db_user"
            AEGIR_DB_USER="$RET"
            db_get "aegir/db_password"
            AEGIR_DB_PASS="$RET"
            db_get "aegir/email"
            EMAIL="$RET"
            db_get "aegir/makefile"
            if [ ! -z "$RET" ]; then
                MAKEFILE="--makefile='$RET'"
            fi
            db_reset aegir/db_password || true
            db_go
            db_stop
            
            if [ -d $VARLIB/.drush/provision ]; then
                echo "existing provision in $VARLIB/.drush/provision detected, move away and try again"
                exit 1
            fi
            su aegir -c "drush hostmaster-install --yes --version='$VERSION' --aegir_db_host='$AEGIR_DB_HOST' --aegir_db_user='$AEGIR_DB_USER' --aegir_db_pass='$AEGIR_DB_PASS' --client_email='$EMAIL' $MAKEFILE $SITE"
            ln -sf $VARLIB/config/apache.conf /etc/apache2/conf.d/aegir.conf
            apache2ctl graceful
        fi
        rm -f $TEMPFILE
anarcat's avatar
anarcat committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    ;;

    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