Skip to content

Instantly share code, notes, and snippets.

@nudded
Created January 18, 2018 09:57
Show Gist options
  • Save nudded/a5ccc3279e0138ba5c7173912e58ba00 to your computer and use it in GitHub Desktop.
Save nudded/a5ccc3279e0138ba5c7173912e58ba00 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
###
# Usage:
# Add the following set of commands to the setup of a build in the Project Settings
#
# sudo apt-get purge -y postgresql-client-* postgresql-* postgresql-contrib-* postgresql-server-dev-* libpq-dev
# sudo apt-get update
# wget https://gist.githubusercontent.com/mimimalizam/b9ee28d74e1a59d58719916f42c18226/raw/pg_semaphore.sh && bash pg_semaphore.sh
#
# First command will remove current PG version and its configuration.
# Last command will install PG 10 using this script and it will use the default port.
# Also, script is using our install-package tool for caching APT get packages.
#
# If you'd like to install PG 9.6 instead modify the second command to
#
# wget https://gist.githubusercontent.com/mimimalizam/b9ee28d74e1a59d58719916f42c18226/raw/pg_semaphore.sh && bash pg_semaphore.sh 9.6
#
# Note: reset your dependency cache in Project Settings > Admin, before running this script
###
set -e
pg_version=${1:-'10'}
echo "Installing PostgreSQL version: $pg_version"
install-package libpq5 postgresql-client-$pg_version postgresql-$pg_version postgresql-contrib-$pg_version postgresql-server-dev-$pg_version libpq-dev postgresql-$pg_version-postgis-2.2
sudo su postgres <<CMD
psql -c "ALTER USER postgres" -d template1;
psql -c "CREATE USER runner WITH PASSWORD 'semaphoredb';" -d template1;
psql -c "ALTER USER runner CREATEDB" -d template1;
psql -c "ALTER USER runner SUPERUSER" -d template1;
psql -c "CREATE EXTENSION hstore WITH SCHEMA pg_catalog;" -d template1;
CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment