[NUUG fiksgatami] Bootstrapping a fixmystreet installation (script)

Petter Reinholdtsen pere at hungry.com
Sun Feb 6 00:37:39 CET 2011


This is the script I have written to bootstrap and update the
fixmystreet instance running on fiksgatami-dev.nuug.no.  Posting it
here for review and feedback.  Did I forget something?

I have not started on the mapit setup, and do not yet know how to do
it.  Input is most welcome.

I plan to use this script from cron running 'update' regularly, and
'remove' followed by 'bootstrap' if the database change layout.  I
need to get email configured before I start the cron job, thought.

The instance is now running, and the front page is working.  But
visiting the 'list all reports' page produce an error.  Not quite sure
why.

#!/bin/sh
#
# Bootstrap or update a fixmystreet clone.  Either argument
# 'bootstrap', 'update' or 'remove' is used to create, update or
# remove the clone

# Exit on first error
set -e

basedir=/srv/fiksgatami-dev.nuug.no

# Password to use when connecting to the postgresql database.
dbpassword="hidden"

install_debs() {
    apt-get install -y $(cat fixmystreet/conf/packages)
#   libcache-memcached-perl libfile-slurp-perl \
#	libgeography-nationalgrid-perl liberror-perl libwww-perl \
#	libimage-magick-perl libdbd-pg-perl libio-string-perl \
#	libregexp-common-perl libmath-bigint-gmp-perl libdigest-sha1-perl \
#	libxml-rss-perl libfcgi-perl libjson-perl libimage-size-perl \
#	php5-cli postgresql apache2 libtext-template-perl libtext-csv-perl

    # Statistics::Distributions is created locally
    dpkg -i /root/libstatistics-distributions-perl_1.02-1_all.deb
}

pgsql_createuser() {
    dbuser="$1"
    dbpassword="$2"
    dbname="$3"
    su postgres -c "createuser -SDRl $dbuser"
    su postgres -c "createdb --owner $dbuser $dbname; createlang plpgsql $dbname"
    su postgres -c "psql -c \"alter user \\\"$dbuser\\\" with password '$dbpassword';\""
}

pgsql_bootstrap() {
    dbuser="$1"
    dbname="$2"
    su $dbuser -c "psql $dbname -f $basedir/fixmystreet/db/schema.sql"
    su $dbuser -c "psql $dbname -f $basedir/fixmystreet/db/alert_types.sql"
}

pgsql_remove() {
    dbuser="$1"
    dbname="$2"
    su postgres -c "dropdb $dbname"
    su postgres -c "dropuser $dbuser"
}

apache_config() {
    cat > /etc/apache2/sites-available/fixmystreet <<EOF
<VirtualHost *:80>
    ServerName fiksgatami.no
    ServerName fiksgatami.nuug.no
    ServerName fiksgatami-dev.nuug.no
    DocumentRoot $basedir/fixmystreet/web/
    Alias /admin/ $basedir/fixmystreet/web-admin/
    <Directory $basedir/fixmystreet/web>
        Include $basedir/fixmystreet/conf/httpd.conf
        Options +ExecCGI +MultiViews
        MultiviewsMatch Handlers
        AddHandler cgi-script .cgi
    </Directory>
    <Directory $basedir/fixmystreet/web-admin>
        DirectoryIndex index.cgi
        Options +ExecCGI +MultiViews
        MultiviewsMatch Handlers
        AddHandler cgi-script .cgi
    </Directory>
</VirtualHost>
EOF
    a2dissite default
    a2ensite fixmystreet
    a2enmod proxy rewrite
    /etc/init.d/apache2 reload
# Syntax error on line 86 of /srv/fiksgatami-dev.nuug.no/fixmystreet/conf/httpd.conf:
# ProxyPass|ProxyPassMatch can not have a path when defined in a location.
# Action 'configtest' failed.
# The Apache error log may have more information.
#  failed!

# $basedir/fixmystreet/conf/httpd.conf
# http://www.gossamer-threads.com/lists/apache/users/342793
}

apache_remove() {
    a2dissite fixmystreet
    /etc/init.d/apache2 reload
    rm /etc/apache2/sites-available/fixmystreet
}


fetch_git_source() {
    if [ ! -d mapit ] ; then
	git clone https://github.com/mysociety/mapit.git
    else
	(cd mapit && git pull && git diff)
    fi
    if [ ! -d fixmystreet ] ; then
	git clone https://github.com/mysociety/fixmystreet.git
	(cd fixmystreet && git submodule update --init)
    else
	(cd fixmystreet && git pull && git diff)
    fi
}

update_fixmystreet_config() {
    dbuser="$1"
    dbpassword="$2"
    dbname="$3"
    cat >> $basedir/fixmystreet/conf/general <<EOF
<?php
/*
 * general-example:
 * Example values for the "general" config file.
 *
 * Configuration parameters, in PHP syntax. Configuration parameters are set
 * using the PHP define('OPTION_...', '...') function. Both perl and PHP code
 * parse this properly, so you can use comments and conditionals and whatnot,
 * but unless essential it's better to keep it simple....
 *
 * Copy this file to one called "general" in the same directory.  Or
 * have multiple config files and use a symlink to change between them.
 *
 * Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
 * Email: francis at mysociety.org; WWW: http://www.mysociety.org
 *
 * $Id: update-server,v 1.2 2011/02/05 23:25:57 pere Exp $
 *
 */

// PostgreSQL database for BCI
define('OPTION_BCI_DB_HOST', 'localhost');
define('OPTION_BCI_DB_PORT', '5432');
define('OPTION_BCI_DB_NAME', '$dbname');
define('OPTION_BCI_DB_USER', '$dbuser');
define('OPTION_BCI_DB_PASS', '$dbpassword');

define('OPTION_DRESS_DB_HOST', 'localhost');
define('OPTION_DRESS_DB_PORT', '5432');
define('OPTION_DRESS_DB_NAME', 'dress');
define('OPTION_DRESS_DB_USER', 'dress');
define('OPTION_DRESS_DB_PASS', '');

define('OPTION_BASE_URL', 'http://fiksgatami-dev.nuug.no');
define('OPTION_CONTACT_EMAIL', 'fiksgatami at nuug.no');
define('OPTION_CONTACT_NAME', 'FiksGataMi');
define('OPTION_STAGING_SITE', 1);

define('OPTION_UPLOAD_CACHE', '/var/lib/fixmystreet/upload/');
define('OPTION_GEO_CACHE', '/var/lib/fixmystreet/cache/');
define('OPTION_GOOGLE_MAPS_API_KEY', '');

define('OPTION_MAP_TYPE', 'OSM::StreetView');
define('OPTION_MAPIT_URL', 'http://services.fiksgatami.no/mapit');
define('OPTION_TILES_URL', 'http://tilma.mysociety.org/tileserver/10k-full-london');
define('OPTION_EVEL_URL', 'http://services.mysociety.org/evel');
define('OPTION_GAZE_URL', 'http://gaze.mysociety.org/gaze');

// Tracking
define('OPTION_TRACKING', 0);   // off by default
define('OPTION_TRACKING_URL', 'http://path/to/web/bug');
define('OPTION_TRACKING_SECRET', 'really-secret-value');

define('OPTION_AUTH_SHARED_SECRET', '');
define('OPTION_HEARFROMYOURMP_BASE_URL', '');

define('OPTION_SMTP_SMARTHOST', 'localhost');

define('OPTION_FLICKR_API', '');

define('OPTION_IPHONE_URL', '');

define('OPTION_ALLOWED_COBRANDS', '');

?>
EOF
    if [ ! -d /var/lib/fixmystreet ] ; then
	(
	mkdir /var/lib/fixmystreet && \
	    cd /var/lib/fixmystreet && \
	    mkdir cache && \
	    mkdir upload && \
	    chown www-data cache && \
	    chown www-data upload
	)
    fi
}

setup_locale() {
    cat > /etc/locale.gen  <<EOF
en_GB.UTF-8 UTF-8
nb_NO.UTF-8 UTF-8
nb_NO.UTF-8 UTF-8
EOF
    locale-gen
}

cd /srv/fiksgatami-dev.nuug.no/

case "$1" in 
    bootstrap)
	fetch_git_source
	install_debs
	pgsql_createuser www-data $dbpassword fixmystreet
	pgsql_bootstrap www-data fixmystreet
	update_fixmystreet_config www-data $dbpassword fixmystreet
	setup_locale
	apache_config
	;;
    remove)
	pgsql_remove www-data fixmystreet
	apache_remove
	;;
    update)
	fetch_git_source
	update_fixmystreet_config www-data $dbpassword fixmystreet
	apache_config
	;;
esac


More information about the fiksgatami mailing list