aegir-provision.postinst 4.93 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
61

        # fix permissions on installed directories
        chown aegir:aegir "$VARLIB"

62
63
64
65
        # 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
66
67
68
69

        TEMPFILE=`tempfile`
        su aegir -c 'drush @hostmaster status' >> $TEMPFILE || true
        if grep -q 'Drupal bootstrap.*Successful' $TEMPFILE; then
70
71
            db_stop
            echo "Aegir frontend (@hostmaster) site detected"
anarcat's avatar
anarcat committed
72
            SITE=`grep URI $TEMPFILE | sed -e 's/^.*://'`
anarcat's avatar
anarcat committed
73
            OLD_PLATFORM=`grep 'Drupal root' $TEMPFILE | sed -e 's/^.*:[[:space:]]*//;s/[[:space:]]*$//'`
anarcat's avatar
anarcat committed
74
75
            NEW_PLATFORM="$VARLIB/hostmaster-$VERSION"
            if [ -d "$NEW_PLATFORM" ]; then
76
                echo "it seems to be the same version as the one we're trying to install, not upgrading"
anarcat's avatar
anarcat committed
77
            else
78
                echo "upgrading the frontend from $OLD_PLATFORM to $NEW_PLATFORM"
anarcat's avatar
anarcat committed
79
                cd "$OLD_PLATFORM"
anarcat's avatar
anarcat committed
80
                su aegir -c "drush hostmaster-migrate --yes '$SITE' '$NEW_PLATFORM'"
anarcat's avatar
anarcat committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
            fi
        else
            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
100
101
            db_fset aegir/db_password "seen" "true" || true

anarcat's avatar
anarcat committed
102
103
104
105
106
107
108
            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
109
            echo "installing the Aegir frontend (Drupal with the hostmaster profile), please wait..."
110
111
112
113
114
115
116
117
118
119
            # pass data through JSON 
            su aegir -c "drush hostmaster-install --backend $MAKEFILE $SITE | drush backend-parse" <<EOF
{ "yes": 1,
  "version": "$VERSION",
  "aegir_db_host": "$AEGIR_DB_HOST",
  "aegir_db_user": "$AEGIR_DB_USER",
  "aegir_db_pass": "$AEGIR_DB_PASS",
  "client_email": "$EMAIL"
}
EOF
anarcat's avatar
anarcat committed
120
121
122
123
            ln -sf $VARLIB/config/apache.conf /etc/apache2/conf.d/aegir.conf
            apache2ctl graceful
        fi
        rm -f $TEMPFILE
anarcat's avatar
anarcat committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    ;;

    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