#!/bin/sh # On a clean Debian squeeze or Ubuntu precise installation you should # be able to install FixMyStreet with: # # curl https://raw.github.com/mysociety/fixmystreet/master/bin/pre-install-as-root | \ # sh -s fms whatever.compute.amazonaws.com # # ... where the first argument is the Unix user who will own the code # and the application will run as, and the second argument is the # public hostname for the server, which will be used for creating the # named virtualhost. set -e set -x SITE=fixmystreet DEFAULT_SERVER=false if [ x"$1" = x"--default" ] then DEFAULT_SERVER=true shift fi # Install some packages that we will definitely need: apt-get install -y git-core lockfile-progs rubygems curl dnsutils lsb-release # If we're not running on an EC2 instance, an empty body is returned # by this request: EC2_HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/public-hostname || true` usage_and_exit() { cat >&2 < [HOST] HOST is only optional if you are running this on an EC2 instance. --default means to install as the default site for this server, rather than a virtualhost for HOST. EOUSAGE exit 1 } if [ $# = 1 ] then if [ x = x$EC2_HOSTNAME ] then usage_and_exit else HOST="$EC2_HOSTNAME" fi elif [ $# = 2 ] then HOST="$2" else usage_and_exit fi UNIX_USER="$1" if [ $DEFAULT_SERVER = true ] then DIRECTORY="/var/www/$SITE" else DIRECTORY="/var/www/$HOST" fi REPOSITORY="$DIRECTORY/$SITE" REPOSITORY_URL=git://github.com/mysociety/$SITE.git BRANCH=master DISTRIBUTION="$(lsb_release -i -s | tr A-Z a-z)" VERSION="$(lsb_release -c -s)" IP_ADDRESS_FOR_HOST="$(dig +short $HOST)" if [ x = x"$IP_ADDRESS_FOR_HOST" ] then echo "The hostname $HOST didn't resolve to an IP address" exit 1 fi generate_locales() { # If language-pack-en is present, install that: apt-get install -y language-pack-en || true # We get lots of locale errors if the en_GB.UTF-8 locale isn't # present. (This is from Kagee's script.) if [ "$(locale -a | egrep -i '^en_GB.utf-?8$' | wc -l)" = "1" ] then echo "en_GB.utf8 activated and generated" else echo "en_GB.utf8 not generated" if [ x"$(grep -c '^en_GB.UTF-8 UTF-8' /etc/locale.gen)" = x1 ] then echo "'en_GB.UTF-8 UTF-8' already in /etc/locale.gen we will only generate" else echo "Appending 'en_GB.UTF-8 UTF-8' and 'cy_GB.UTF-8 UTF-8'" echo "to /etc/locale.gen for generation" echo "\nen_GB.UTF-8 UTF-8\ncy_GB.UTF-8 UTF-8" >> /etc/locale.gen fi echo "Generating new locales" locale-gen fi } set_locale() { echo 'LANG="en_GB.UTF-8"' > /etc/default/locale export LANG="en_GB.UTF-8" } add_unix_user() { # Create the required user if it doesn't already exist: if id "$1" 2> /dev/null > /dev/null then echo "The user $1 already exists." else adduser --disabled-password --gecos 'The FixMyStreet User' "$1" fi } add_postgresql_user() { su -l -c "createuser --createdb --no-createrole --no-superuser '$UNIX_USER'" postgres || true } update_apt_sources() { if [ x"$DISTRIBUTION" = x"ubuntu" ] && [ x"$VERSION" = x"precise" ] then cat > /etc/apt/sources.list.d/mysociety-extra.list < /etc/apt/sources.list.d/mysociety-extra.list < /etc/rc.local <