custom-site-mahara-langpacks.postinst 3.42 KB
Newer Older
Richard Hector's avatar
Richard Hector committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/bin/sh
# postinst script for custom-site-mahara-langpacks

set -e

. /usr/share/debconf/confmodule

# 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

case "$1" in
    configure)
22 23 24 25 26 27
        adduser --system --quiet maharabot

        if [ ! -d /home/maharabot/.ssh ] ; then
            mkdir /home/maharabot/.ssh
            ssh-keygen -q -t rsa -N '' -f /home/maharabot/.ssh/id_rsa
            chown -R maharabot /home/maharabot/.ssh
28 29 30 31 32 33 34
            echo "Please add the following public key to Launchpad.net https://launchpad.net/~dev-mahara/+editsshkeys"
            echo "### Begin of the public key###"
            cat /home/maharabot/.ssh/id_rsa.pub
            echo "### End of the public key###"
            sudo -u maharabot -sH ssh-keyscan -H bazaar.launchpad.net > /home/maharabot/.ssh/known_hosts
            chown maharabot /home/maharabot/.ssh/known_hosts
            sudo -u maharabot -sH bzr whoami "Mahara Bot <dev@mahara.org>"
35 36
        fi

Richard Hector's avatar
Richard Hector committed
37 38 39
        if [ ! -d /var/www/mahara-langpacks ]; then
            mkdir /var/www/mahara-langpacks
        fi
40 41 42 43 44

        if [ `stat -c %U /var/www/mahara-langpacks` != 'maharabot' ]; then
            chown -R maharabot /var/www/mahara-langpacks
        fi

Richard Hector's avatar
Richard Hector committed
45 46
        if [ ! -d /var/lib/mahara-langpacks ]; then
            mkdir /var/lib/mahara-langpacks
47 48
        else
            rm -rf /var/lib/mahara-langpacks/*
Richard Hector's avatar
Richard Hector committed
49
        fi
50 51 52 53 54

        if [ `stat -c %U /var/lib/mahara-langpacks` != 'maharabot' ]; then
            chown -R maharabot /var/lib/mahara-langpacks
        fi

55 56
        if [ ! -d /var/log/apache2/mahara-langpacks ]; then
            mkdir /var/log/apache2/mahara-langpacks
Richard Hector's avatar
Richard Hector committed
57 58
        fi

59 60 61 62 63
        if [ ! -d /var/log/mahara-langpacks ]; then
            mkdir /var/log/mahara-langpacks
            chown maharabot /var/log/mahara-langpacks
        fi

Richard Hector's avatar
Richard Hector committed
64 65 66
        echo "DATA=/var/lib/mahara-langpacks" > /etc/mahara-langpacks.conf
        echo "SCRIPTS=/usr/lib/mahara-langpacks" >> /etc/mahara-langpacks.conf
        echo "DOCROOT=/var/www/mahara-langpacks" >> /etc/mahara-langpacks.conf
67
        echo "PROJDIR='https://git.mahara.org/mahara/mahara.git'" >> /etc/mahara-langpacks.conf
68 69 70
        DOMAINNAME="langpacks.mahara.org"
        echo "WWWROOT='http://${DOMAINNAME}'" >> /etc/mahara-langpacks.conf

Richard Hector's avatar
Richard Hector committed
71 72 73
        NVH=`apache2ctl -S 2>&1 |grep "is a NameVirtualHost"|sed 's/ .*//'|head -1`
        cat <<EOF > /etc/apache2/sites-available/mahara-langpacks.conf
<VirtualHost ${NVH}>
74
  ServerName ${DOMAINNAME}
Richard Hector's avatar
Richard Hector committed
75
  DocumentRoot /var/www/mahara-langpacks
76 77
  CustomLog /var/log/apache2/custom-site-mahara-langpacks-access.log combined
  ErrorLog  /var/log/apache2/custom-site-mahara-langpacks-error.log
Richard Hector's avatar
Richard Hector committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
</VirtualHost>
EOF
        a2ensite mahara-langpacks.conf
    ;;

    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