4 * FusionForge Installation Dependency Setup
6 * Copyright 2006 GForge, LLC
7 * http://fusionforge.org/
11 * This file is part of GInstaller, it is called by install.sh.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 require_once 'install-common.inc' ;
30 show("\n-=# Welcome to FusionForge DB-Installer #=-");
32 //TO DO: add dependency check
33 //if (!run("php check-deps.php", true)) {
34 // echo RED.'Not all the necessary dependencies were found. aborting.'.NORMAL."\n";
38 // Make sure the DB is initialized by starting postgresql service
39 if (is_file('/etc/init.d/postgresql'))
41 $pgservice='/etc/init.d/postgresql';
43 elseif (is_file('/etc/init.d/postgresql-8.2'))
45 $pgservice='/etc/init.d/postgresql-8.2';
47 elseif (is_file('/etc/init.d/postgresql-8.3'))
49 $pgservice='/etc/init.d/postgresql-8.3';
51 elseif (is_file('/etc/init.d/postgresql-8.4'))
53 $pgservice='/etc/init.d/postgresql-8.4';
55 elseif (is_file('/etc/init.d/cswpostgres'))
57 $pgservice='/etc/init.d/cswpostgres';
61 die("ERROR: Could not find Postgresql init script\n");
64 # Fedora9 (an maybe newer) requires running initdb
65 if ($pgservice == '/etc/init.d/postgresql') {
66 if (!is_dir("/var/lib/pgsql/data/base")) {
67 run("service postgresql initdb &>/dev/null", true);
71 // Might fail if it's already running, so we'll ingnore the result
72 run("$pgservice start", true);
74 if (!is_dir($fusionforge_src_dir))
76 die("Error: GForge folder doesn't exist. Run fusionforge-install-2.php first.");
79 // Where the PGHBA config file is
80 if (is_file("/var/lib/pgsql/data/pg_hba.conf"))
83 $PGHBA='/var/lib/pgsql/data/pg_hba.conf';
85 elseif (is_file('/etc/postgresql/8.2/main/pg_hba.conf'))
87 $PGHBA='/etc/postgresql/8.2/main/pg_hba.conf';
89 elseif (is_file('/etc/postgresql/8.4/main/pg_hba.conf'))
91 $PGHBA='/etc/postgresql/8.4/main/pg_hba.conf';
93 elseif (is_file('/opt/csw/var/pgdata/pg_hba.conf'))
95 $PGHBA='/opt/csw/var/pgdata/pg_hba.conf';
99 die("ERROR: Could not find pg_hba.conf file\n");
103 if (is_file('/usr/share/pgsql/contrib/tsearch2.sql'))
106 $tsearch2_sql='/usr/share/pgsql/contrib/tsearch2.sql';
108 elseif (is_file('/usr/share/postgresql/contrib/tsearch2.sql'))
111 $tsearch2_sql='/usr/share/postgresql/contrib/tsearch2.sql';
113 elseif (is_file('/usr/share/postgresql/8.2/contrib/tsearch2.sql'))
115 $tsearch2_sql='/usr/share/postgresql/8.2/contrib/tsearch2.sql';
117 elseif (is_file('/usr/share/postgresql/8.3/contrib/tsearch2.sql'))
119 $tsearch2_sql='/usr/share/postgresql/8.3/contrib/tsearch2.sql';
121 elseif (is_file('/usr/share/postgresql/8.4/contrib/tsearch2.sql'))
123 $tsearch2_sql='/usr/share/postgresql/8.4/contrib/tsearch2.sql';
125 elseif (is_file('/opt/csw/postgresql/share/contrib/tsearch2.sql'))
128 $tsearch2_sql='/opt/csw/postgresql/share/contrib/tsearch2.sql';
132 die("ERROR: Could not find tsearch2.sql file\n");
138 global $PGHBA, $fusionforge_src_dir, $fusionforge_etc_dir, $tsearch2_sql, $pgservice, $STDIN, $STDOUT;
140 show("\n * Enter the Database Name (gforge): ");
142 if (getenv('FFORGE_DB')) {
143 $gforge_db = getenv('FFORGE_DB');
145 $gforge_db = trim(fgets($STDIN));
146 if (strlen($gforge_db) == 0) {
147 $gforge_db = 'gforge';
150 show(" ...using '$gforge_db'");
152 show(' * Enter the Database Username (gforge): ');
154 if (getenv('FFORGE_USER')) {
155 $gforge_user = getenv('FFORGE_USER');
157 $gforge_user = trim(fgets($STDIN));
158 if (strlen($gforge_user) == 0) {
159 $gforge_user = 'gforge';
162 show(" ...using '$gforge_user'");
164 show(' * Saving database configuration in FForge config file');
165 if (!is_file("$fusionforge_etc_dir/config.ini.d/rpm-install.ini")){
166 if ($fp = fopen("$fusionforge_etc_dir/config.ini.d/rpm-install.ini", "w")) {
167 $config='; This file was generated by the RPM installation system.
168 ; You can edit the values here or move them to other files.
170 forge_name=FusionForge
171 web_host='.system("hostname -f").'
173 fwrite ($fp, $config);
177 if (!is_file("$fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini")){
178 if ($fp = fopen("$fusionforge_etc_dir/config.ini.d/rpm-install-secrets.ini", "w")) {
179 $config='; This file was generated by the RPM installation system.
180 ; You can edit the values here or move them to other files.
181 ; These values should not go into world-readable files!
185 database_name='.$gforge_db.'
186 database_user='.$gforge_user.'
188 ; database_password=$pw
190 fwrite ($fp, $config);
195 show(" * Modifying DB Access Permissions...");
196 if (!file_exists("$PGHBA.fforge.backup")) {
197 run("cp $PGHBA $PGHBA.fforge.backup", true);
199 run("echo \"# GFORGE\nlocal all all trust\" > $PGHBA");
200 show(' * Restarting PostgreSQL...');
201 run("$pgservice stop", true);
202 run("$pgservice start");
205 show(" * Creating '$gforge_user' Group...");
206 run("/usr/sbin/groupadd $gforge_user", true);
208 show(" * Creating '$gforge_user' User...");
209 run("/usr/sbin/useradd -g $gforge_user $gforge_user", true);
211 // Let's give some time for PostgreSQL to start
214 show(" * Creating Database User '$gforge_user'...");
215 run("su - postgres -c \"createuser -A -R -d -E $gforge_user\"", true);
217 show(' * Creating Language...');
218 run("su - postgres -c \"createlang plpgsql template1\"", true);
220 if (!is_dir("/home/$gforge_user")) {
226 show(" * Creating '$gforge_db' Database...");
227 run("su $susufix $gforge_user -c \"createdb --encoding UNICODE $gforge_db\"", true);
229 # Detect postgresql version, load tsearch2 for pg < 8.3
230 $pg_version = explode(' ', shell_exec("postgres --version"));
231 $pgv = $pg_version[2];
233 if (preg_match('/^(7\.|8\.1|8\.2)/', $pgv)) {
234 show(" * Dumping tsearch2 Database Into '$gforge_db' DB");
235 run("su - postgres -c \"psql $gforge_db < $tsearch2_sql\" >> /tmp/gforge-import.log");
237 $tables = array('pg_ts_cfg', 'pg_ts_cfgmap', 'pg_ts_dict', 'pg_ts_parser');
238 foreach ($tables as $table) {
239 run('su - postgres -c "psql '.$gforge_db.' -c \\"GRANT ALL on '.$table.' TO '.$gforge_user.';\\""');
241 run("su - postgres -c \"psql $gforge_db -c \\\"UPDATE pg_ts_cfg SET locale='en_US.UTF-8' WHERE ts_name='default'\\\"\"");
243 // show(" * Creating FTS default configuation (Full Text Search)");
244 // run("su - postgres -c \"psql $gforge_db < $fusionforge_src_dir/db/FTS-20081108.sql\" >> /tmp/gforge-import.log");
248 show(' * Dumping FusionForge DB');
249 run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/gforge.sql\" >> /tmp/gforge-import.log");
251 // show(' * Dumping FusionForge FTI DB');
252 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI.sql\" >> /tmp/gforge-import.log");
253 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI-20050315.sql\" >> /tmp/gforge-import.log");
254 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI-20050401.sql\" >> /tmp/gforge-import.log");
255 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI-20050530.sql\" >> /tmp/gforge-import.log");
256 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI-20060130.sql\" >> /tmp/gforge-import.log");
257 // run("su $susufix $gforge_user -c \"psql $gforge_db < $fusionforge_src_dir/db/FTI-20061025.sql\" >> /tmp/gforge-import.log");
259 if (!is_dir($fusionforge_etc_dir)) {
260 mkdir($fusionforge_etc_dir);
262 if (!is_dir($fusionforge_etc_dir.'/config.ini.d')) {
263 mkdir($fusionforge_etc_dir.'/config.ini.d');
266 #$data = file_get_contents("$fusionforge_etc_dir/local.inc");
267 #$lines = explode("\n",$data);
269 #foreach ($lines as $l) {
270 # $l = preg_replace("/^.sys_dbname\s*=\s*'(.*)'/", "\$sys_dbname='$gforge_db'", $l);
271 # $l = preg_replace("/^.sys_dbuser\s*=\s*'(.*)'/", "\$sys_dbuser='$gforge_user'", $l);
272 # $config .= $l."\n";
275 #if ($fp = fopen("$fusionforge_etc_dir/local.inc", "w")) {
276 # fwrite ($fp, $config);
280 show(' * Saving installation log in /tmp/gforge-import.log');
283 function uninstall() {
284 global $PGHBA, $fusionforge_src_dir, $gforge_var_dir, $fusionforge_etc_dir, $gforge_db, $gforge_user, $tsearch2_sql;
286 show(" * Removing DATABASE \n";
287 system("su - $gforge_user -c \"dropdb $gforge_db\"", $ret );
288 show(" done . ($ret)\n";
290 show(" * Removing Language \n";
291 system("su - postgres -c \"droplang plpgsql template1\"", $ret );
292 show(" done. ($ret)\n";
294 show(" * Removing GForge DATABASE User: \n";
295 system("su - postgres -c \"dropuser $gforge_user\"", $ret );
296 show(" done.($ret)");
298 show(" * Removing GForge User: \n";
299 system("userdel $gforge_user");
302 show(" * Restoring $PGHBA file: ... ";
303 system("cp $PGHBA.gforge.backup $PGHBA");
306 show(" * Restarting PostgreSQL: ...\n";
307 system("/etc/init.d/postgresql restart");
313 show(NORMAL."Done.\nYou are ready to run install-gforge-3.php");