#!/bin/sh

set -e

cat > /etc/apache2/conf-enabled/passenger-wsgi.conf <<EOT
Alias /testwsgi /var/www/testwsgi/public
<Location /testwsgi>
  PassengerBaseURI /testwsgi
  PassengerAppRoot /var/www/testwsgi
</Location>
EOT

mkdir /var/www/testwsgi
mkdir /var/www/testwsgi/public
mkdir /var/www/testwsgi/tmp
cat > /var/www/testwsgi/passenger_wsgi.py <<EOT
def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b"hello world\n"]
EOT
chown -R www-data:www-data /var/www/testwsgi

a2enmod passenger
service apache2 reload

output=`wget -O- http://localhost/testwsgi/ 2>/dev/null`
test "$output" = "hello world"
