-#! /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="\033[01;32m"
- NORMAL="\033[00m"
- RED="\033[01;31m"
- case $1 in
+ GREEN="\e[01;32m"
+ NORMAL="\e[00m"
+ RED="\e[01;31m"
+ if [ "$1" = "noreturn" ]
+ then
+ extra="-n"
+ shift
+ else
+ extra=""
+ fi
+ color=$1 ; shift
+ case $color in
red)
- echo "$RED $2 $NORMAL"
+ echo $extra "$RED $1 $NORMAL"
;;
green)
- echo "$GREEN $2 $NORMAL"
+ echo $extra "$GREEN $1 $NORMAL"
;;
esac
}
create_db_admin_user(){
gforge_db="$1"
admin_user="$2"
- su - postgres -c "psql $gforge_db -c \"INSERT INTO users (user_name, realname, firstname, lastname, email, user_pw, unix_pw, status, theme_id) VALUES ('$admin_user', 'Forge Admin', 'Forge', 'Admin', 'root@localhost.localdomain', 'INVALID', 'INVALID', 'A', 1); INSERT INTO user_group (user_id, group_id, admin_flags) VALUES (currval('users_pk_seq'), 1, 'A'); INSERT INTO pfo_user_role (user_id, role_id) VALUES (currval('users_pk_seq'), 3)\""
+ su - postgres -c "psql $gforge_db -c \"INSERT INTO users (user_name, realname, firstname, lastname, email, user_pw, unix_pw, status, theme_id) VALUES ('$admin_user', 'Forge Admin', 'Forge', 'Admin', 'root@localhost.localdomain', 'INVALID', 'INVALID', 'A', 1); INSERT INTO user_group (user_id, group_id, admin_flags, role_id) VALUES (currval('users_pk_seq'), 1, 'A',17); INSERT INTO pfo_user_role (user_id, role_id) VALUES (currval('users_pk_seq'), 3)\""
}
-msg green "-=# Welcome to FusionForge DB-Installer #=-"
-
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
}
get_config(){
- insscriptdir=`cd \`dirname $0\`; pwd`
- . $insscriptdir/config
-
if [ ! -d "$fusionforge_src_dir" ]
then
- msg red "Error: GForge folder doesn't exist. Run fusionforge-install-2.php first."
+ msg red "Error: $fusionforge_src_dir folder doesn't exist. Run install2 first."
exit 2
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
-}
-
-installandrundb()
-{
- # USING $pghba, $fusionforge_src_dir, $fusionforge_etc_dir, $tsearch, $pgservice, $STDIN, $STDOUT;
-
+forge_save_db_config(){
if [ -z "$FFORGE_DB" ]
then
while test -z "$FFORGE_DB"
do
- msg green "* Enter the Database Name (fusionforge): "
+ msg noreturn green "* Enter the Database Name (fusionforge): "
read FFORGE_DB
done
fi
then
while test -z "$FFORGE_USER"
do
- msg green "* Enter the Database Username (gforge): "
+ msg noreturn green "* Enter the Database Username (gforge): "
read FFORGE_USER
done
fi
gforge_user="$FFORGE_USER"
msg green " ...using $gforge_user"
+ if [ ! -d "$fusionforge_etc_dir" ]
+ then
+ mkdir $fusionforge_etc_dir
+ fi
+ if [ ! -d "$fusionforge_etc_dir/config.ini.d" ]
+ then
+ mkdir $fusionforge_etc_dir/config.ini.d
+ fi
+
+ msg green " * Saving database configuration in FForge config file"
+ if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install.ini" ]
+ then
+ cat > $fusionforge_etc_dir/config.ini.d/rpm-install.ini <<-EOF
+; You can edit the values here or move them to other files.
+[core]
+forge_name=FusionForge
+web_host=`hostname -f`
+
+; This file was generated by the RPM installation system.
+EOF
+ fi
+
+ if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini" ]
+ then
+ cat > $fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini <<-EOF
+; You can edit the values here or move them to other files.
+; These values should not go into world-readable files!
+
+[core]
+database_host=""
+database_name=$gforge_db
+database_user=$gforge_user
+database_port=5432
+; database_password=""
+
+; This file was generated by the RPM installation system.
+EOF
+ fi
+ msg green " * Saving installation log in /tmp/gforge-import.log"
+}
+
+dropdbifexists()
+{
+ 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"
+ 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
+}
+
+installandrundb()
+{
+ # USING $gforge_user, $gforge_db, $pghba, $fusionforge_src_dir, $fusionforge_etc_dir, $tsearch, $pgservice, $STDIN, $STDOUT;
msg green " * Modifying DB Access Permissions..."
if [ ! -f $pghba.fforge.backup ]
if [ -d /home/$gforge_user ]
then
- $susufix = ''
+ 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 " * Dumping 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
- msg green " * Dumping FusionForge DB"
+ msg green " * Loading FusionForge DB"
su $susufix $gforge_user -c "psql $gforge_db < $fusionforge_src_dir/db/gforge.sql" >> /tmp/gforge-import.log
+ msg green " * Running php db/upgrade-db.php"
+ php $fusionforge_src_dir/db/upgrade-db.php >> /tmp/gforge-upgrade.log
+
+
if [ -z "$FFORGE_ADMIN_USER" ]
then
while test -z "$FFORGE_ADMIN_USER"
do
- msg green " * Enter the Admin Username (fforgeadmin): "
+ msg noreturn green " * Enter the Admin Username (fforgeadmin): "
read FFORGE_ADMIN_USER
done
fi
retry=5
while test -z "$FFORGE_ADMIN_PASSWORD" -a $retry -gt 0
do
- msg green " * Enter the Site Admin Password:"
+ msg noreturn green " * Enter the Site Admin Password:"
read -s FFORGE_ADMIN_PASSWORD1
if validatePassword "$FFORGE_ADMIN_PASSWORD1"
then
- msg green " * Please enter it again:"
+ 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
+ FFORGE_ADMIN_PASSWORD="$FFORGE_ADMIN_PASSWORD1"
else
msg green "Passwords don't match. Please try again."
fi
exit 1
else
create_db_admin_user "$gforge_db" "$admin_user"
- forge_set_password "$admin_user" "$FFORGE_ADMIN_PASSWORD"
+ $fusionforge_src_dir/utils/forge_set_password "$admin_user" "$FFORGE_ADMIN_PASSWORD"
fi
+ else
+ create_db_admin_user "$gforge_db" "$admin_user"
+ $fusionforge_src_dir/utils/forge_set_password "$admin_user" "$FFORGE_ADMIN_PASSWORD"
fi
}
-forge_save_db_config(){
- if [ ! -f "$fusionforge_etc_dir" ]
- then
- mkdir $fusionforge_etc_dir
- fi
- if [ ! -f "$fusionforge_etc_dir/config.ini.d" ]
- then
- mkdir $fusionforge_etc_dir/config.ini.d
- fi
-
- msg green " * Saving database configuration in FForge config file"
- if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install.ini" ]
- then
- cat > $fusionforge_etc_dir/config.ini.d/rpm-install.ini <<-EOF
-; You can edit the values here or move them to other files.
-[core]
-forge_name=FusionForge
-web_host=`hostname -f`
-
-; This file was generated by the RPM installation system.
-EOF
- fi
-
- if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini" ]
- then
- cat > $fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini <<-EOF
-; You can edit the values here or move them to other files.
-; These values should not go into world-readable files!
-
-[core]
-database_host=""
-database_name=$gforge_db
-database_user=$gforge_user
-database_port=5432
-; database_password=$pw
-
-; This file was generated by the RPM installation system.
-EOF
- fi
- msg green " * Saving installation log in /tmp/gforge-import.log"
-}
-
validatePassword() {
password="$1"
strlen=`echo "$1" | wc -m`
return 1
fi
CHECK=`echo $password | grep -E "[[:alnum:]]*"`
- if [ "$CHECK" == "" ] ; then
+ if [ "$CHECK" = "" ]
then
msg red "Password contains invalid characters. Please try again."
return 2
fi
}
-install3(){
+install3_db(){
+ msg green "-=# Welcome to FusionForge DB-Installer #=-"
find_psql_init
psql_startdb
get_config
find_pghba
- find_tsearch
- installandrundb
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"
+}