source: trunk/scripts/setup-win @ 1184

Revision 907, 6.2 KB checked in by bogdanpasoi@…, 4 years ago (diff)

Cleaned up scripts folder.

  • Property svn:executable set to *
Line 
1<?php
2
3// required by forum-fix
4require_once(dirname($argv[0]) . "/utilities.php");
5
6// Add slashes to a string.
7function slash_string($string, $start, $end)
8{
9    // Strip start/end slash
10    if ($string[0] == '/') {
11        $string = substr($string, 1);
12    }
13    if ($string[strlen($string) - 1] == '/') {
14        $string = substr($string, 0, strlen($string) - 1);
15    }
16
17    // Add start/end slash
18    if ($start) {
19        $string = '/'.$string;
20    }
21    if ($end) {
22        $string = $string.'/';
23    }
24
25    // Tada.
26    return $string;
27}
28
29
30// Replace config values in $srcfile and copy to $dstfile
31function handle_config_file($vars, $srcfile, $dstfile)
32{
33    $contents = file_get_contents($srcfile);
34    foreach ($vars as $k => $v) {
35        $contents = str_replace("--write-me-$k--", $v, $contents);
36    }
37    file_put_contents($dstfile, $contents);
38}
39
40// ---
41// Real code starts here
42// ---
43
44print("\nHello, I am the infoarena setup script and I will try to guide ".
45          "you through setting up an infoarena developement working copy.\n");
46
47print("I'm going to ask you a couple of questions. Just press enter if you like ".
48      "the default value. I'm pretty good at guessing ;).\n\n");
49
50print("Please write all the paths with '/' (Linux like)\n\n");
51
52
53// FIXME: Check dependencies? pecl nonsense is no longer mandatory.
54// It should be done it setup.sh anyway, since we can't relie on php-cli.
55
56// Initialize config vars.
57$config_vars = array();
58$config_vars['IA_ROOT_DIR'] = str_replace('\\', '/', realpath(dirname($argv[0]) . '/../') . '\\');
59$config_vars['IA_URL_HOST'] = 'http://localhost';
60$config_vars['IA_URL_PREFIX'] = '/infoarena2-dev/';
61$config_vars['IA_DB_HOST'] = 'localhost';
62$config_vars['IA_DB_USER'] = 'root';
63$config_vars['IA_DB_PASS'] = '';
64$config_vars['IA_DB_NAME'] = 'infoarena2';
65$config_vars['APACHE_DIR'] = 'c:/Program Files/Apache Group/Apache2';
66
67// Ask user.
68$config_vars['IA_ROOT_DIR'] = read_line("SVN checkout dir?", $config_vars['IA_ROOT_DIR']);
69$config_vars['IA_ROOT_DIR'] = slash_string(
70        str_replace('\\', '/', realpath($config_vars['IA_ROOT_DIR'])), false, true);
71$config_vars['IA_URL_HOST'] = read_line("Host part of url (with http)?",
72        $config_vars['IA_URL_HOST']);
73$config_vars['IA_URL_HOST'] = slash_string(
74        $config_vars['IA_URL_HOST'], false, false);
75$config_vars['IA_URL_PREFIX'] = read_line("Prefix part of url?",
76        $config_vars['IA_URL_PREFIX']);
77$config_vars['IA_URL_PREFIX'] = slash_string(
78        $config_vars['IA_URL_PREFIX'], true, true);
79
80// Database configuration here.
81while (true) {
82    $config_vars['IA_DB_HOST'] = read_line("Database host?",
83            $config_vars['IA_DB_HOST']);
84    $config_vars['IA_DB_USER'] = read_line("Database connection username?",
85            $config_vars['IA_DB_USER']);
86    $config_vars['IA_DB_PASS'] = read_line("Database password?",
87            $config_vars['IA_DB_PASS']);
88    $config_vars['IA_DB_NAME'] = read_line("Database name?",
89            $config_vars['IA_DB_NAME']);
90    // FIXME: check database connection.
91
92    $dblink = mysql_connect(
93            $config_vars['IA_DB_HOST'],
94            $config_vars['IA_DB_USER'],
95            $config_vars['IA_DB_PASS']);
96
97    if (!$dblink) {
98        print("Can't connect to database, something must be wrong.\n");
99        if (read_bool("Try again or ignore (CTRL-C to abort)?", true)) {
100            continue;
101        } else {
102            break;
103        }
104    }
105
106    if (!mysql_select_db($config_vars['IA_DB_NAME'], $dblink)) {
107        print("Can't select database.\n");
108        if (read_bool("Should I try to create the database?", true)) {
109            if (!mysql_query("CREATE DATABASE {$config_vars['IA_DB_NAME']}")) {
110                die("Failed creating database, sorry.");
111            }
112            if (!mysql_select_db($config_vars['IA_DB_NAME'], $dblink)) {
113                die("Still can't select database.\n");
114            }
115        }
116    }
117    break;
118}
119
120// Do the config monkey.
121$ia_root = $config_vars['IA_ROOT_DIR'];
122$ia_url = $config_vars['IA_URL_HOST'] . $config_vars['IA_URL_PREFIX'];
123handle_config_file($config_vars,
124        $ia_root.'config.php.sample', $ia_root.'config.php');
125handle_config_file($config_vars,
126        $ia_root.'www/htaccess.sample', $ia_root.'www/.htaccess');
127handle_config_file($config_vars,
128        $ia_root.'eval/config.php.sample', $ia_root.'eval/config.php');
129handle_config_file($config_vars,
130        $ia_root.'apache.conf.sample', $ia_root.'apache.conf');
131
132if ($dblink && read_bool("Should I try to import the sample database?", true)) {
133    $cmd = sprintf("mysql --user=%s --password=%s --host=%s %s < %s",
134            $config_vars['IA_DB_USER'],
135            $config_vars['IA_DB_PASS'],
136            $config_vars['IA_DB_HOST'],
137            $config_vars['IA_DB_NAME'],
138            '"' . $config_vars['IA_ROOT_DIR'] . "db.sql" . '"');
139    print("Running $cmd\n");
140    system($cmd);
141}
142
143// Configure apache
144if (read_bool("Should I try to configure apache for you?", true)) {
145    $sitename = slash_string($config_vars['IA_URL_PREFIX'], false, false);
146    $sitename = read_line("Site name?", $sitename);
147
148    // edit httpd.conf
149    while (true) {
150        $config_vars['APACHE_DIR'] = read_line("Apache install dir?", $config_vars['APACHE_DIR']);
151        $config_vars['APACHE_DIR'] = slash_string(
152            realpath($config_vars['APACHE_DIR']), false, true);
153        if (!($apachef = fopen($config_vars['APACHE_DIR'] . "conf/httpd.conf", "a"))) {
154            print("Invalid apache install dir\n");
155            if (read_bool("Try again or ignore (CTRL-C to abort)?", true)) {
156                continue;
157            } else {
158                break;
159            }
160        } else {
161            fprintf($apachef, "\n%s\n", file_get_contents($ia_root. 'apache.conf'));
162            fclose($apachef);
163            print("httpd.conf file written\n");
164            print("Please restart apache after this in order for changes to take effect\n");
165            break;
166        }
167    }
168}
169
170// FIXME: configure forum
171if (read_bool("Should I try to configure the forum (ugly db stuff)?", true)) {
172    include("forum-fix-win");
173}
174printf("---\n");
175
176print("FIXME: forum is not completely functional\n");
177print("FIXME: eval won't work, but it doesn't matter.\n");
178
179print("\nDone. Please read coding standards. Happy coding!\n");
Note: See TracBrowser for help on using the repository browser.