2 # FusionForge Installation Dependency Setup
4 # Copyright 2006 GForge, LLC
5 # Copyright 2011 Christian Bayle <bayle@debian.org>
6 # http://fusionforge.org/
10 # This file is part of GInstaller, it is called by install.sh.
12 # FusionForge is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # FusionForge is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 if [ "$1" = "noreturn" ]
40 echo $extra "$RED $1 $NORMAL"
43 echo $extra "$GREEN $1 $NORMAL"
48 create_db_admin_user(){
51 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)\""
56 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
63 if [ -z "$pgservice" ]
70 # Fedora9 (an maybe newer) requires running initdb
71 if [ "$pgservice" == '/etc/init.d/postgresql' ]
73 if [ -d /var/lib/pgsql/data/base ]
75 service postgresql initdb &>/dev/null
79 # Might fail if it's already running, so we'll ingnore the result
84 if [ ! -d "$fusionforge_src_dir" ]
86 msg red "Error: $fusionforge_src_dir folder doesn't exist. Run install2 first."
91 # Where the pghba config file is
94 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
103 msg red "ERROR: Could not find pg_hba.conf file"
108 # Where the tsearch sql config file is
111 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
113 if [ -f $tsearchfile ]
115 tsearch="$tsearchfile"
120 msg red "ERROR: Could not find tsearch2.sql file"
125 forge_save_db_config(){
127 if [ -z "$FFORGE_DB" ]
129 while test -z "$FFORGE_DB"
131 msg noreturn green "* Enter the Database Name (fusionforge): "
135 gforge_db="$FFORGE_DB"
136 msg green " ...using $gforge_db"
138 if [ -z "$FFORGE_USER" ]
140 while test -z "$FFORGE_USER"
142 msg noreturn green "* Enter the Database Username (gforge): "
146 gforge_user="$FFORGE_USER"
147 msg green " ...using $gforge_user"
149 if [ ! -d "$fusionforge_etc_dir" ]
151 mkdir $fusionforge_etc_dir
153 if [ ! -d "$fusionforge_etc_dir/config.ini.d" ]
155 mkdir $fusionforge_etc_dir/config.ini.d
158 msg green " * Saving database configuration in FForge config file"
159 if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install.ini" ]
161 cat > $fusionforge_etc_dir/config.ini.d/rpm-install.ini <<-EOF
162 ; You can edit the values here or move them to other files.
164 forge_name=FusionForge
165 web_host=`hostname -f`
167 ; This file was generated by the RPM installation system.
171 if [ ! -f "$fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini" ]
173 cat > $fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini <<-EOF
174 ; You can edit the values here or move them to other files.
175 ; These values should not go into world-readable files!
179 database_name=$gforge_db
180 database_user=$gforge_user
182 ; database_password=""
184 ; This file was generated by the RPM installation system.
187 msg green " * Saving installation log in /tmp/gforge-import.log"
194 export PATH=$PATH:/usr/share/gforge/bin/:/usr/share/gforge/utils:/opt/gforge/utils
195 database=`FUSIONFORGE_NO_PLUGINS=true forge_get_config database_name`
199 if [ -z "$database" ]
201 echo "Forge database name not found"
211 echo "Droping database $database"
212 su - postgres -c "dropdb -e $database"
218 # USING $gforge_user, $gforge_db, $pghba, $fusionforge_src_dir, $fusionforge_etc_dir, $tsearch, $pgservice, $STDIN, $STDOUT;
219 msg green " * Modifying DB Access Permissions..."
221 if [ ! -f $pghba.fforge.backup ]
223 cp $pghba $pghba.fforge.backup
229 msg green " * Restarting PostgreSQL..."
233 msg green " * Creating $gforge_user Group..."
234 /usr/sbin/groupadd $gforge_user;
236 msg green " * Creating '$gforge_user' User..."
237 /usr/sbin/useradd -g $gforge_user $gforge_user
239 # Let's give some time for PostgreSQL to start
242 msg green " * Creating Database User $gforge_user..."
243 su - postgres -c "createuser -A -R -d -E $gforge_user"
245 msg green " * Creating Language..."
246 su - postgres -c "createlang plpgsql template1"
248 if [ -d /home/$gforge_user ]
255 msg green " * Creating $gforge_db Database..."
256 su $susufix $gforge_user -c "createdb --encoding UNICODE $gforge_db"
258 # Detect postgresql version, load tsearch2 for pg < 8.3
259 pgv=`postgres --version | cut -d" " -f3`
262 msg green " * Loading tsearch2 Database Into $gforge_db DB"
263 su - postgres -c "psql $gforge_db < $tsearch" >> /tmp/gforge-import.log 2>&1
264 for table in pg_ts_cfg pg_ts_cfgmap pg_ts_dict pg_ts_parser
266 su - postgres -c "psql $gforge_db -c \"GRANT ALL on $table TO $gforge_user\";"
268 su - postgres -c "psql $gforge_db -c \"UPDATE pg_ts_cfg SET locale='en_US.UTF-8' WHERE ts_name='default'\""
272 msg green " * Loading FusionForge DB"
273 su $susufix $gforge_user -c "psql $gforge_db < $fusionforge_src_dir/db/gforge.sql" >> /tmp/gforge-import.log 2>&1
275 msg green " * Running php db/upgrade-db.php"
276 php $fusionforge_src_dir/db/upgrade-db.php >> /tmp/gforge-upgrade.log 2>&1
279 if [ -z "$FFORGE_ADMIN_USER" ]
281 while test -z "$FFORGE_ADMIN_USER"
283 msg noreturn green " * Enter the Admin Username (fforgeadmin): "
284 read FFORGE_ADMIN_USER
287 admin_user=$FFORGE_ADMIN_USER
288 msg green " ...using $admin_user"
290 if [ -z "$FFORGE_ADMIN_PASSWORD" ]
293 while test -z "$FFORGE_ADMIN_PASSWORD" -a $retry -gt 0
295 msg noreturn green " * Enter the Site Admin Password:"
296 read -s FFORGE_ADMIN_PASSWORD1
297 if validatePassword "$FFORGE_ADMIN_PASSWORD1"
299 msg noreturn green " * Please enter it again:"
300 read -s FFORGE_ADMIN_PASSWORD2
301 if [ "$FFORGE_ADMIN_PASSWORD1" == "$FFORGE_ADMIN_PASSWORD2" ]
303 FFORGE_ADMIN_PASSWORD="$FFORGE_ADMIN_PASSWORD1"
305 msg green "Passwords don't match. Please try again."
308 retry=`expr $retry - 1`
310 if [ -z "$FFORGE_ADMIN_PASSWORD" ]
312 msg green "Passwords didn't match! Aborting."
315 create_db_admin_user "$gforge_db" "$admin_user"
316 $fusionforge_src_dir/utils/forge_set_password "$admin_user" "$FFORGE_ADMIN_PASSWORD"
319 create_db_admin_user "$gforge_db" "$admin_user"
320 $fusionforge_src_dir/utils/forge_set_password "$admin_user" "$FFORGE_ADMIN_PASSWORD"
326 strlen=`echo "$1" | wc -m`
329 msg red "Password is too short. Please try again"
332 CHECK=`echo $password | grep -E "[[:alnum:]]*"`
333 if [ "$CHECK" == "" ]
335 msg red "Password contains invalid characters. Please try again."
343 msg green "-=# Welcome to FusionForge DB-Installer #=-"