PostgreSQL 9.2

by weddingtype
7 deployments · 4 still active · last rev. 4 years ago

Installs PostgreSQL 9.2 (and dependencies). As of 10/2/2012 PostgreSQL 9.2 is only available through apt-get (aptitude package not available yet).

I then successfully installed PostGIS 2.0 using instructions: http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204src (will update this script later for complete PostgreSQL 9.2 + PostGIS 2.0 install).

Compatible with: No distros currently supported
						#!/bin/bash
# PostgreSQL 9.2
# Written by Julia Grace (julia@juliahgrace.com) but heavily based on http://www.linode.com/stackscripts/view/?StackScriptID=3249 written by Andrey Petrov (andrey.petrov@shazow.net)
#
# <UDF name="hostname" default="Mynode" label="Server Hostname">
#
# <UDF name="username" label="Your Login Username" example="Your personal login account for the server." default=""/>
#
# <UDF name="password" Label="Your Login Password" example="Also used for the Deploy user."/>
# <UDF name="ssh_key" label="Your SSH Public Key" example="Also used for the Deploy user."/>
#
# <UDF name="do_postgresql" label="Include PostgreSQL 9.2?" oneof="Yes,No", default="Yes"/>
# <UDF name="postgresql_database" Label="PostgreSQL Database" default="" />
# <UDF name="postgresql_user" Label="PostgreSQL Username" default="" />
# <UDF name="postgresql_password" Label="PostgreSQL Password" default="" />
#
# <UDF name="notify_email" Label="Email to notify when ready" default="" />

# FIXME: Make sure all input variables are contained in "$FOO"

source <ssinclude StackScriptID="1"> ## StackScript Bash Library {
    system_update
    postfix_install_loopback_only
## }


source <ssinclude StackScriptID="123"> ## lib-system-ubuntu {
    # Set hostname
    if [ "$HOSTNAME" ]; then
        system_update_hostname "$HOSTNAME"
    fi

    # Add users
    if [ "$USERNAME" ]; then
        system_add_user "$USERNAME" "$PASSWORD" "sudo"
        system_user_add_ssh_key "$USERNAME" "$SSH_KEY"
    fi

    if [ "$DO_DEPLOY" == "Yes" ]; then
        system_add_user "$DEPLOY_USERNAME" "$PASSWORD" "sudo"
        system_user_add_ssh_key "$DEPLOY_USERNAME" "$SSH_KEY"
    fi

    # SSH
    system_sshd_passwordauthentication "no"
    system_sshd_permitrootlogin "no"
    system_sshd_pubkeyauthentication "yes"
## }

# Essentials
aptitude -y install python-software-properties
aptitude -y install build-essential python-dev git-core mailutils

# Install PostgreSQL 9.2?
if [ "$DO_POSTGRESQL" == "Yes" ]; then
    add-apt-repository ppa:pitti/postgresql -y
    apt-get update
    apt-get install postgresql-9.2 postgresql-common postgresql-server-dev-9.2

    #prereqs for postgis
    apt-get install libxml2-dev proj libjson0-dev xsltproc docbook-xsl docbook-mathml
    

    if [ "$POSTGRESQL_USER" -a "$POSTGRESQL_DATABASE" ]; then
        # Create postgres user
        echo "CREATE ROLE $POSTGRESQL_USER WITH LOGIN ENCRYPTED PASSWORD '$POSTGRESQL_PASSWORD';" | sudo -u postgres psql

        # Create postgres database
        sudo -u postgres createdb --owner "$POSTGRESQL_USER" "$POSTGRESQL_DATABASE"
    fi
fi

# Notify email
if [ "$NOTIFY_EMAIL" ]; then
    IP_ADDRESS="$(system_primary_ip)"
    mail -s "Linode Stackscript Deployed" $NOTIFY_EMAIL << EOF
Your server is deployed at $IP_ADDRESS.

Happy querying!
EOF
fi;