Skip to content

Instantly share code, notes, and snippets.

@pratyakshs
Last active October 13, 2015 12:22
Show Gist options
  • Save pratyakshs/79d4c6eb6cd6f49cdd5b to your computer and use it in GitHub Desktop.
Save pratyakshs/79d4c6eb6cd6f49cdd5b to your computer and use it in GitHub Desktop.
#!/bin/bash
CURDIR=`pwd`;
# Add any other dependencies that you may find
sudo apt-get update;
sudo apt-get install -y git eclipse eclipse-cdt flex bison zlib1g-dev libreadline6-dev;
# Change the repository URL to your own
git clone https://github.com/pratyakshs/postgres.git --depth 1;
# Accordingly, change the name of your repository
REPO_NAME=postgres;
mkdir -p $CURDIR/$REPO_NAME/install;
# Potentially dangerous
# Removes all the lines containing POSTGRES_INSTALLDIR or POSTGRES_SRCDIR or PGDATA from ~/.bashrc
grep -v "POSTGRES_INSTALLDIR" ~/.bashrc | grep -v "POSTGRES_SRCDIR" | grep -v "PGDATA" > ~/.bashrc.v01;
mv ~/.bashrc.v01 ~/.bashrc;
# Adds these exports to ~/.bashrc
STR1="export POSTGRES_INSTALLDIR=$CURDIR/$REPO_NAME/install"
STR2="export POSTGRES_SRCDIR=$CURDIR/$REPO_NAME/"
echo $STR1 >> ~/.bashrc;
echo $STR2 >> ~/.bashrc;
# Sets environment variables
${STR1};
${STR2};
cd ${POSTGRES_SRCDIR};
# Installation with debugging enabled
./configure --prefix=${POSTGRES_INSTALLDIR} --enable-debug;
export enable_debug=yes;
make | tee make.out
make install | tee make_install.out
# Adds these exports to ~/.bashrc
STR3="export LD_LIBRARY_PATH=${POSTGRES_INSTALLDIR}/lib:\$LD_LIBRARY_PATH";
STR4="export PATH=${POSTGRES_INSTALLDIR}/bin:\$PATH";
STR5="export PGDATA=${POSTGRES_INSTALLDIR}/data";
echo $STR3 >> ~/.bashrc;
echo $STR4 >> ~/.bashrc;
echo $STR5 >> ~/.bashrc;
# Sets up environment variables
export LD_LIBRARY_PATH=${POSTGRES_INSTALLDIR}/lib:$LD_LIBRARY_PATH;
export PATH=${POSTGRES_INSTALLDIR}/bin:$PATH;
${STR5};
# Creates a new PostgreSQL database cluster
${POSTGRES_INSTALLDIR}/bin/initdb -D ${PGDATA};
# Runs the PostgreSQL server
${POSTGRES_INSTALLDIR}/bin/postmaster -D $PGDATA > logfile 2>&1 &
sleep 2;
# Creates a test database
${POSTGRES_INSTALLDIR}/bin/createdb -p 5432 test;
${POSTGRES_INSTALLDIR}/bin/pg_ctl stop;
# Restores working directory
cd -;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment