-#! /bin/sh
+#! /bin/bash
# FusionForge Installation Dependency Setup
#
# Copyright 2006 GForge, LLC
# with FusionForge; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+PG_VERSIONS="8.3 8.4 9.0 9.1"
+
msg(){
GREEN="\e[01;32m"
NORMAL="\e[00m"
}
find_psql_init(){
- initpsql=""
- for initpsql in /etc/init.d/postgresql /etc/init.d/postgresql-8.2 /etc/init.d/postgresql-8.3 /etc/init.d/postgresql-8.4 /etc/init.d/cswpostgres
+ initpsql="/etc/init.d/postgresql"
+ for v in $PG_VERSIONS ; do
+ initpsql="$initpsql postgresql-$v"
+ done
+ initpsql="$initpsql /etc/init.d/cswpostgres"
+ for i in $initpsql
do
- if [ -f $initpsql ]
+ if [ -f $i ]
then
- pgservice=$initpsql
+ pgservice=$i
fi
done
if [ -z "$pgservice" ]
psql_startdb(){
# Fedora9 (an maybe newer) requires running initdb
- if [ "$pgservice" == '/etc/init.d/postgresql' ]
+ if [ "$pgservice" = '/etc/init.d/postgresql' ]
then
- if [ -d /var/lib/pgsql/data/base ]
+ if [ ! -d /var/lib/pgsql/data/base ]
then
service postgresql initdb &>/dev/null
fi
# Where the pghba config file is
find_pghba(){
- pghbafile=""
- for pghbafile in /var/lib/pgsql/data/pg_hba.conf /etc/postgresql/8.2/main/pg_hba.conf /etc/postgresql/8.3/main/pg_hba.conf /etc/postgresql/8.4/main/pg_hba.conf /opt/csw/var/pgdata/pg_hba.conf
+ pghbafile="/var/lib/pgsql/data/pg_hba.conf"
+ for v in $PG_VERSIONS ; do
+ pghbafile="$pghbafile /etc/postgresql/$v/main/pg_hba.conf"
+ done
+ pghbafile="$pghbafile /opt/csw/var/pgdata/pg_hba.conf"
+ for i in $pghbafile
do
- if [ -f $pghbafile ]
+ if [ -f $i ]
then
- pghba="$pghbafile"
+ pghba="$i"
fi
done
if [ -z "$pghba" ]
fi
}
-# Where the tsearch sql config file is
-find_tsearch(){
- tsearchfile=""
- for tsearchfile in /usr/share/pgsql/contrib/tsearch2.sql /usr/share/postgresql/8.2/contrib/tsearch2.sql /usr/share/postgresql/8.3/contrib/tsearch2.sql /usr/share/postgresql/8.4/contrib/tsearch2.sql /opt/csw/postgresql/share/contrib/tsearch2.sql
- do
- if [ -f $tsearchfile ]
- then
- tsearch="$tsearchfile"
- fi
- done
- if [ -z "$tsearch" ]
- then
- msg red "ERROR: Could not find tsearch2.sql file"
- exit 1
- fi
-}
-
forge_save_db_config(){
-
if [ -z "$FFORGE_DB" ]
then
while test -z "$FFORGE_DB"
dropdbifexists()
{
- export PATH=$PATH:/usr/share/gforge/bin/:/usr/share/gforge/utils:/opt/gforge/utils
- database=`FUSIONFORGE_NO_PLUGINS=true forge_get_config database_name`
+ if [ -z "$1" ]
+ then
+ export PATH=$PATH:/usr/share/gforge/bin/:/usr/share/gforge/utils:/opt/gforge/utils
+ database=`FUSIONFORGE_NO_PLUGINS=true forge_get_config database_name`
+ else
+ database=$1
+ fi
if [ -z "$database" ]
then
echo "Forge database name not found"
- exit 1
+ find_psql_init
+ $pgservice stop
+ $pgservice start
else
find_psql_init
$pgservice stop
+ sleep 5
$pgservice start
+ sleep 5
echo "Droping database $database"
su - postgres -c "dropdb -e $database"
fi
then
susufix=''
else
- susufix='-'
+ susufix='- -s /bin/sh'
fi
msg green " * Creating $gforge_db Database..."
- su $susufix $gforge_user -c "createdb --encoding UNICODE $gforge_db"
+ su $susufix $gforge_user -c "createdb $dboption --encoding UNICODE $gforge_db"
- # Detect postgresql version, load tsearch2 for pg < 8.3
- pgv=`postgres --version | cut -d" " -f3`
+ # Enable plpgsql language
+ if [ -f /usr/bin/createlang ]
+ then
+ if [ `su -s /bin/sh postgres -c "/usr/bin/createlang -l $gforge_db | grep plpgsql | wc -l"` != 1 ]
+ then
+ su -s /bin/sh postgres -c "/usr/bin/createlang plpgsql $gforge_db"
+ else
+ echo "Procedural language on $gforge_db already enabled"
+ fi
+ else
+ echo "No way found to enable plpgsql on $gforge_db here"
+ fi
+
+ # Detect postgresql version, require at least 8.3
+ pgv=
+ for i in postgres psql ; do
+ if [ "$(type -p $i)" != '' ] ; then
+ pgv=$($i --version | cut -d" " -f3)
+ fi
+ done
+ if [ "$pgv" = '' ] ; then
+ msg red "Error: Can't find command-line PostgreSQL client."
+ exit 2
+ fi
case $pgv in
7.*|8.1*|8.2*)
- msg green " * Loading tsearch2 Database Into $gforge_db DB"
- su - postgres -c "psql $gforge_db < $tsearch" >> /tmp/gforge-import.log
- for table in pg_ts_cfg pg_ts_cfgmap pg_ts_dict pg_ts_parser
- do
- su - postgres -c "psql $gforge_db -c \"GRANT ALL on $table TO $gforge_user\";"
- done
- su - postgres -c "psql $gforge_db -c \"UPDATE pg_ts_cfg SET locale='en_US.UTF-8' WHERE ts_name='default'\""
+ msg red " * Unsupported PostgreSQL version; 8.3 or later is required"
+ exit 2
;;
esac
then
msg noreturn green " * Please enter it again:"
read -s FFORGE_ADMIN_PASSWORD2
- if [ "$FFORGE_ADMIN_PASSWORD1" == "$FFORGE_ADMIN_PASSWORD2" ]
+ if [ "$FFORGE_ADMIN_PASSWORD1" = "$FFORGE_ADMIN_PASSWORD2" ]
then
FFORGE_ADMIN_PASSWORD="$FFORGE_ADMIN_PASSWORD1"
else
return 1
fi
CHECK=`echo $password | grep -E "[[:alnum:]]*"`
- if [ "$CHECK" == "" ]
+ if [ "$CHECK" = "" ]
then
msg red "Password contains invalid characters. Please try again."
return 2
psql_startdb
get_config
find_pghba
- find_tsearch
forge_save_db_config
installandrundb
msg green "Done."
}
+
+install3_db_redhat()
+{
+ install3_db
+}
+
+install3_db_suse()
+{
+ install3_db
+}
+
+install3_db_debian()
+{
+ export dboption="--template=template0"
+ install3_db
+}
+
+install3_db_ubuntu()
+{
+ export dboption="--template=template0"
+ install3_db
+}
+
+install3_db_unknown()
+{
+ echo "Install 3 db not implemented"
+}