maharadocs.postinst 4.89 KB
Newer Older
Melissa Draper's avatar
Melissa Draper committed
1 2 3 4 5 6 7 8 9
#!/bin/bash
set -e
. /usr/share/debconf/confmodule
PACKAGE=`basename $0 .postinst`
bold=`tput bold`
normal=`tput sgr0`

# Get the user input
case "$1" in
10 11 12 13 14 15 16 17 18 19
    configure)
            db_get maharadocs/installdir
        DIRNAME=$RET
            db_get maharadocs/giturl
        GITURL=$RET
            db_get maharadocs/logdir
        LOGDIR=$RET
            db_get maharadocs/overwrite
        OVERWRITEDIR=$RET
    ;;
Melissa Draper's avatar
Melissa Draper committed
20

21 22 23 24
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
Melissa Draper's avatar
Melissa Draper committed
25 26 27 28 29
esac


# Check if we seem to have the correct git contents, not very trustworthy
# but better than no check :D
Melissa Draper's avatar
Melissa Draper committed
30
if [ -d $DIRNAME ]
Melissa Draper's avatar
Melissa Draper committed
31
then
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    if  grep -Fxq $GITURL $DIRNAME/.git/config
    then
        # If we have what appears to be the correct git contents,
        # just quit the script cleanly and let the rest of the
        # packaging do its thing.
        echo "Data already exists pulling from the correct source."
        echo "Not doing any alteration of $DIRNAME."
        exit
    else
        # However if it looks wrong, check if its a-ok to overwrite
        if [ "$OVERWRITEDIR" == "ok" ]
        then
            # Buhbye!
            rm -rf $DIRNAME
        else
            # Throw an error stating that we don't feel right about
            # nuking the data we can see.
            echo "${bold}The directory '$DIRNAME' already exists."
            echo "We were not told to overwrite, so we will not."
            echo "Exiting now. Retry with the overwrite option.${normal}"
            exit
        fi
    fi
Melissa Draper's avatar
Melissa Draper committed
55 56 57
fi

# Make our lovely new install from the git address.
Melissa Draper's avatar
Melissa Draper committed
58
# Despite all our checking, this can fail horribly after a long wait;
Melissa Draper's avatar
Melissa Draper committed
59
# there's not really much we can do about that now.
Melissa Draper's avatar
Melissa Draper committed
60
echo "Downloading the manual into $DIRNAME from gitorious.org:"
Melissa Draper's avatar
Melissa Draper committed
61 62 63 64 65
echo "$GITURL"
echo "This may take a while..."
git clone $GITURL $DIRNAME

# Did we succeed?
Melissa Draper's avatar
Melissa Draper committed
66
if [ -d $DIRNAME ]
Melissa Draper's avatar
Melissa Draper committed
67
then
68 69
    # Yay!
    echo "Manual successfully downloaded into '$DIRNAME'."
Melissa Draper's avatar
Melissa Draper committed
70
else
71 72 73 74 75 76 77 78 79 80
    # In theory, we should not be here. Throw an error if we did, guessing what might
    # have happened. Git _should_ have reported all failures to download, but if the
    # directory is missing, then _something_ went wrong.
    echo "${bold}The installation failed; the manual directory could not be found.${normal}"
    echo "Please check that:"
    echo "* The directory is indeed missing. If not, it is a packaging error."
    echo "* $GITURL is accessible and downloadable on your network. Find a friendly sysadmin."
    echo "If this appears to be a packaging error, report it to info@mahara.org with all"
    echo "the text output since you tried to install this. "
    exit -1
Melissa Draper's avatar
Melissa Draper committed
81
fi
Melissa Draper's avatar
Melissa Draper committed
82 83 84 85 86 87 88 89

# Make the sitelogs directory...
mkdir -p /var/log/sitelogs/mahara-manual-sphinx

echo "${bold}Setting up Apache configuration...${normal}"

cat > /etc/apache2/sites-available/mahara-manual-sphinx.conf << EOF
<VirtualHost *:80>
90
        ServerAdmin maharahost@catalyst.net.nz
Melissa Draper's avatar
Melissa Draper 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
        ServerName manual.mahara.org

        DocumentRoot ${DIRNAME}/build/html
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory ${DIRNAME}/build/html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${LOGDIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${LOGDIR}/access.log combined

    # Convert wild existing links from before we vacated readthedocs.
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteRule ^(.*)/1.4_STABLE/(.*)$ $1/1.4/$2
        RewriteRule ^(.*)/1.5_STABLE/(.*)$ $1/1.5/$2
118
        RewriteRule   ^/$  /en/1.8/  [R]
Melissa Draper's avatar
Melissa Draper committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    </IfModule>

</VirtualHost>
EOF

# Enable the site
a2ensite mahara-manual-sphinx.conf
# Restart apache
# Nicked from http://www.ilestis.ch/2011/03/03/apache-auto-restart-if-config-check/
# Check current apachectl status
# - configtest sends to str.err, so map it back to str.out
CHECKCONF=`/usr/sbin/apachectl -t 2>&1`

# httpd service
HTTPDS='httpd'

# Is Syntax OK: restart
echo "Check syntax files..."
if [ "$CHECKCONF" = "Syntax OK" ]
then
        echo "- Config seems OK."
        echo "Restarting apache..."
        RESTARTCTL=`/usr/sbin/apachectl restart 2>&1 | grep -v "httpd not running, trying to start"`

        # If restart isn't empty, an error occured
        if [ "$RESTARTCTL" != "" ]
        then
                echo "Error on restart: $RESTARTCTL"
                echo ""
        fi

        # Check if apache is running successfully
        echo "Check if httpd is running...."
        if ps ax | grep -v grep | grep $HTTPDS > /dev/null
        then
                echo "- HTTPD is running"
        else
                echo "- Error: HTTPD isn't running!"
        fi
else
        echo "Configcheck error: $CHECKCONF"
        echo ""
fi