A while back when I was trying to get PostgreSQL installed (and did eventually), I decided to write a script to simplify the process.
I did this script ages ago, but never put the finishing touches on it. To be honest, I havn't run it in a while and can't remember exactly what state its in. Anyway, I came across it the other day after forgetting about it, and thought i would post it on the forums.
Anyone is welcome to modify it and add things to it or improve it. It was my first .sh script so i'm sure there are some things that could be improved.
Have fun, and let me know how it goes if you try it out. Just remember that it is beta:
---script begins below---
#!/bin/sh
#
#
#WARNING: This script is not complete as of 30/03/2005
#It still needs work, and won't necessarily break your
#SME Server, just be aware that it is not finished, and
#has some remaining kinks yet to be ironed out.
#
#
#Tristan Knowles - tristanknowles{at}gmail.com
#(cydonia on the contribs.org forums)
#-----------------------------------------------#
# #
# #
# PostgreSQL 7.4.2 Installation Script #
# #
# #
#-----------------------------------------------#
#
#Run this script in an area where you normally download and install programs to.
#This script will make directories for postgres installer files which it will
#download and run.
#BEGIN VARIABLES
#Add your settings here.
tcp_socket_setting="true"
local_ip="0.0.0.0"
network_ip="0.0.0.0"
network_mask="0.0.0.0"
#END VARIABLES
#EDIT BEYOND THIS POINT AT OWN RISK
mkdir -p postgresql
cd postgresql
rpm -qa > rpmlist
is_pgsql=pic rpmlist | grep -c postgres
if [ $is_pgsql -eq 0 ]
then
wget ftp://ftp.be.postgresql.org/postgresql/binary/v7.4.2/redhat/redhat-7.3/mx-2.0.3-1.i386.rpm
wget ftp://ftp.be.postgresql.org/postgresql/binary/v7.4.2/redhat/redhat-7.3/postgresql-docs-7.4.2-1PGDG.i386.rpm
wget ftp://ftp.be.postgresql.org/postgresql/binary/v7.4.2/redhat/redhat-7.3/postgresql-python-7.4.2-1PGDG.i386.rpm
wget ftp://ftp.be.postgresql.org/postgresql/binary/v7.4.2/redhat/redhat-7.3/postgresql-7.4.2-1PGDG.i386.rpm
wget ftp://ftp.be.postgresql.org/postgresql/binary
else
rpm --nodeps -Uvh *.rpm
fi
mkdir -p /etc/e-smith/templates-custom/var/lib/pgsql/data/postgresql.conf
#Edit postgresql.conf to configure tcpip socket
touch /etc/e-smith/templates-custom/var/lib/pgsql/data/postgresql.conf/20Socket
echo 'tcpip_socket='$tcp_socket_setting'' > /etc/e-smith/templates-custom/var/lib/pgsql/data/postgresql.conf/20Socket
echo " -TcpIp Socket setting updated"
mkdir -p /etc/e-smith/templates-custom/var/lib/pgsql/data/pg_hba.conf
#Edit pg_hba.conf to define allowed networks
touch /etc/e-smith/templates-custom/var/lib/pgsql/data/pg_hba.conf/50AllowHost
echo 'host all all '$local_ip' '$network_mask' trust' > /etc/e-smith/templates-custom/var/lib/pgsql/data/pg_hba.conf/50AllowHost
echo 'host all all '$network_ip' '$network_mask' trust' >> /etc/e-smith/templates-custom/var/lib/pgsql/data/pg_hba.conf/50AllowHost
echo " -Host Allow List Updated"
#Edit php.ini to add pgsql.so extension
mkdir /etc/e-smith/templates-custom/etc/php.ini
touch /etc/e-smith/templates-custom/etc/php.ini/70DynamicExtension90pgsql
echo 'extensions=pgsql.so' > /etc/e-smith/templates-custom/etc/php.ini/70DynamicExtension90pgsql
#Expand the above modified templates
/sbin/e-smith/expand-template /var/lib/pgsql/data/postgresql.conf
/sbin/e-smith/expand-template /var/lib/pgsql/data/pg_hba.conf
/sbin/e-smith/expand-template /etc/php.ini
#Restart Postgresql
/etc/init.d/postgresql stop
/etc/init.d/postgresql start
#Restart Apache
service httpd restart
#Now to check if pgsql is working with php
#clear screen
echo "Checking if PostgreSQL is working...!"
php -m
echo "*-------------------------------------------------------*
* *
* Do you see the word: "pgsql" in the above list? *
* *
* Y/N then press enter *
* *
*-------------------------------------------------------*"
while [ "$got_pgsql" != "y" -a "$got_pgsql" != "n" ] ; do
read got_pgsql
done
if [ "$got_pgsql" = "y" ]; then
echo "
#######################
## Congratulations ##
#######################
PostgreSQL is installed and should work"
else
echo "Getting PostgreSQL's act together..."
cd /usr/lib ln -s libpq.so.3 libpq.so.2
service httpd restart
#After applying the above changes, check if pgsql is now visible
echo "Checking agin if PostgreSQL is working..."
php -m
echo "*-------------------------------------------------------*
* *
* Now do you see the word: "pgsql" in the above list? *
* *
* Y/N then press enter *
* *
*-------------------------------------------------------*"
while [ "$got_pgsq_taketwo" != "y" -a "$got_pgsql_taketwo" != "n" ] ; do
read got_pgsql_taketwo
done
if [ "$got_pgsql_taketwo" = "y" ] ; then
echo "
######################
## Congratulations ##
######################
PostgreSQL is installed and should work"
else
echo "
###########
## Sorry ##
###########
My Bag of tricks is exhausted. Try the Contribs.org Forums"
fi
fi