#!/bin/bash
# Run as:
#  curl -s "<url to this>" | sudo time bash

# As root...
apt-get -y install postgresql-9.4-postgis-2.1
service postgresql stop

chmod 777 /var/log/postgresql
pg_dropcluster --stop 9.4 main

# This first attempt fails on 2-aws-syd copy, but this may be due to the snapshot being inconsistent?
# If it works skip step below...
pg_upgradecluster -k -v 9.4 -m upgrade 9.3 main /mnt/db/1/main.9.4

# Skip if previous step works
rm /mnt/db/1/main/*.conf && pg_upgradecluster -k -v 9.4 -m upgrade 9.3 main /mnt/db/1/main.9.4

chmod 775 /var/log/postgresql

#pg_ctlcluster 9.4 main stop

pg_dropcluster 9.3 main

# Check /etc/postgresql config - to see if dropcluser will run

# mv /mnt/db/1/main /mnt/db/1/main.9.3
#mv /mnt/db/1/main.9.4 /mnt/db/1/main

echo "Now run chef"