#!/bin/sh
set -e

cat >> /etc/apache2/apache2.conf <<EOT
<Directory /var/www/html/python/>
  SetHandler mod_python
  PythonHandler mod_python.publisher
</Directory>
EOT

mkdir /var/www/html/python
cat > /var/www/html/python/hello.py <<EOT
#!/usr/bin/python3

def index():
    return "Hello, world!\n"
EOT

echo "INFO: enable apache2 python module"
a2enmod python

echo "INFO: reloading apache2 service"
service apache2 reload

output=`wget -O- http://localhost/python/hello.py 2>/dev/null`
expect="Hello, world!"

if test "$output" != "$expect"; then
  echo "ERROR: The output of the hello script does not match the expected value!"
  echo "- expected: '$expect'"
  echo "- received: '$output'"
fi
