source: trunk/_InstallationResources/build.php @ 1778

Revision 1778, 34.2 KB checked in by admin, 21 months ago (diff)

Merge omcollabu_ui back into trunk

Line 
1<?php
2/**
3* --------------------------------------------------------------
4* omCollab Build Script
5* -----------------------------
6* Version    : 1.1
7* Description: For developers ONLY! Builds the omCollab application suite
8*              (MediaWiki, WordPress, omBookmarks, omExplore)
9*              in one directory, using source file from a differrent directory.
10* Purpose    : Gets around the problem created when app is installed over itself
11*              which corrupts the developer's version of the files (which should
12*              aways be the install-ABLE files, not the install-ED files!
13* Usage      : Example:
14*              Place this script into your htdocs folder. DO NOT INVOKE THIS SCRIPT DIRECTLY
15*              Place build.bat into your htdocs folder.
16*              Configure the four variables in the bat file.
17*              Invoke the bat file, in the dir you want to install into:
18*              eg build <developer_username>
19* Authors     : Pete Dakin <petedakin@gmail.com> for BearingPoint, Andreas Rindler <andreas.rindler@bearingpoint.com>
20*                               Dave Wiggins <dave.wiggins@bearingpoint.com>
21* Changelog       : Add DocConvert switch parameter.
22*                               Xiping Wang<kevin.wang@bearingpoint.com 20090312
23*                               
24*                               When red skin is selected in the installation process, new data file will be used instead of blue one
25*                               Xiping Wang<kevin.wang@bearingpoint.com 20090313
26*                               
27*                               1)Add home.php and home module to setup and teardown part
28*                               2)Add omCollab Application Name used as the home page title, which can be provided by build.sh/bat
29*                               3)Make /index.php point to home.php
30*                               Xiping Wang<kevin.wang@bearingpoint.com 20090522
31*
32*                               Preserve forum file upload directory
33*                               Xiping Wang<kevin.wang@bearingpoint.com 20090617
34* --------------------------------------------------------------
35*/
36
37echo "\nomCollab developer's build script:\n\n";
38
39if( phpversion() < 5 ) die( 'You need PHP 5 to build omCollab' );
40
41$aErrors = array();
42
43#utility function for recursive dir removal
44function RemoveDirRecursively( $dir ) {
45    global $preserve_dirs, $preserve_data, $source_dir;
46        if(!$dh = @opendir($dir)) return;
47    while (false !== ($obj = readdir($dh))) {
48        if( $obj == '.' || $obj == '..' ||
49            (
50              is_array( $preserve_dirs )
51              && in_array( realpath( $dir ), $preserve_dirs )
52              && $preserve_data === true
53             )
54           ) continue;
55        if( !@unlink( $dir.'/'.$obj ) ) RemoveDirRecursively( $dir.'/'.$obj );
56    }
57    closedir( $dh );
58    if( ( ! in_array( realpath( $dir ), $preserve_dirs ) && $preserve_data === true )
59      || $preserve_data === false ){
60//uncomment the next line to see every directory deleted
61//echo "    - removing " . realpath( $dir ) . "\n";
62      @rmdir( $dir );
63    }
64}
65
66#utility function for recursive dir copying
67function CopyDirRecursively( $source, $target ){
68  global $preserve_dirs, $preserve_data, $source_dir, $overwrite_build_script;
69        if( !$preserve_data || ( $preserve_data === true && ! in_array( realpath( $source_dir . $source ), $preserve_dirs ) ) ){
70        if ( is_dir( $source ) && basename($source) != '.svn' ) {
71                @mkdir( $target );
72                $d = dir( $source );
73                while ( FALSE !== ( $entry = $d->read() ) ){
74                    if ( $entry == '.' || $entry == '..' || $entry == '.svn' ){
75                        continue;
76                    }
77                    $SourceEntry = $source . '/' . $entry;           
78                    if ( is_dir( $SourceEntry ) ){
79                        CopyDirRecursively( $SourceEntry, $target . '/' . $entry );
80                        continue;
81                    }
82                        if( $overwrite_build_script ){
83                                if( realpath($SourceEntry) == realpath("{$source_dir}_InstallationResources/build.php" ) ){
84                                        echo " * You have chosen to overwrite '$entry' in target directory " . realpath(dirname(dirname( $target ) ) ) . "\n";                 
85                                copy( $SourceEntry, realpath(dirname( $target ) ) . "/$entry" );
86                                        }else if( realpath($SourceEntry) == realpath("{$source_dir}_InstallationResources/build.bat" ) ){
87                                                echo " * Skipping " . realpath($SourceEntry) . "\n    - this file will not be copied from source because it could corrupt future builds\n";
88                                        }else{
89                                                copy( $SourceEntry, $target . '/' . $entry );
90                                        }
91                        }else{
92                                        if( realpath($SourceEntry) == realpath("{$source_dir}_InstallationResources/build.bat" )
93                                         || realpath($SourceEntry) == realpath("{$source_dir}_InstallationResources/build.php" ) ){
94                                        echo " * Skipping " . realpath($SourceEntry) . " - not needed in this context\n";                       
95                                        }else{
96                                copy( $SourceEntry, $target . '/' . $entry );
97                                }
98                        }
99                }
100                $d->close();
101            }else{
102                copy( $source, $target );
103            }
104        }
105}
106
107#platform
108$is_windows  = isset( $_SERVER['WINDIR'] ) || isset( $_SERVER['windir'] ) ;
109
110#files and dirs to 1) teardown and 2) setup
111$resources = array(
112                    'teardown' => array(
113                                         'Directory'  => array( '_InstallationResources'
114                                                              , '__InstallationResources'
115                                                              , 'blogs'
116                                                              , 'bookmarks'
117                                                              , 'common'
118                                                              , 'explore'
119                                                              , 'w'
120                                                              , 'forum'
121                                                              , 'home')
122                                       , 'File'       => array( 'index.php'
123                                                              , 'install.php'
124                                                              , 'favicon.ico'
125                                                              , 'install.completed.php'
126                                                              , '_install.completed.php'
127                                                              , '.htaccess'
128                                                              , 'Readme.txt'
129                                                              , 'home_loggedin.php'
130                                                              , 'home_public.php'
131                                                               )
132                                        )
133                  , 'setup'    => array(
134                                         'Directory'  => array( '_InstallationResources'
135                                                              , 'blogs'
136                                                              , 'bookmarks'
137                                                              , 'common'
138                                                              , 'explore'
139                                                              , 'forum'
140                                                              , 'home')
141                                       , 'File'       => array( 'index.php'
142                                                              , 'install.php'
143                                                              , 'favicon.ico'
144                                                              , 'Readme.txt'
145                                                              , 'home_loggedin.php'
146                                                              , 'home_public.php'
147                                                               )
148                                        )
149                   );
150
151#these are the expected arguments
152$expected_args = array( 'scriptname'       => $argv[0]
153                      , 'dev_id'           => $argv[1]
154                      , 'source_dir'       => $argv[2]
155                      , 'dest_dir'         => $argv[3]
156                      , 'http_host'        => $argv[4]
157                      , 'preserve'         => $argv[5]
158                      , 'mysql_path'       => $argv[6]
159                      , 'overwrite'        => $argv[7]
160                      , 'mike2skin'        => $argv[8]
161                      , 'google_analytics' => $argv[9]
162                      , 'google_cse_code'  => $argv[10]
163                      , 'google_cse_forid' => $argv[11]
164                      , 'google_blog_key'  => $argv[12]
165                      , 'enable_docconvert' => $argv[13]
166                      , 'openoffice_path'  => $argv[14]  );
167                     
168
169#all parameters must be provided
170if( $argc < count( $expected_args ) ) $aErrors[] = "Incorrect number of arguments";
171
172#developer id must be specified (eg, omcdev1)
173if( ! ctype_alnum( $expected_args['dev_id'] ) ) $aErrors[] = "Argument 1 (developer id) must be alphanumeric [A-Za-z0-9]";
174$dev_id = $expected_args['dev_id'];
175
176#source dir must be specified and must exist
177if( !$expected_args['source_dir'] ) $aErrors[] = "Source directory must be specified";
178if( !file_exists( $expected_args['source_dir'] ) || ! is_dir( $expected_args['source_dir'] )  )  "Source directory must exist";
179$source_dir = $expected_args['source_dir'];
180
181#installation dir cannot be inferred, it has to be either / or . or /path/to/use/ (will be used in placeholder replacement later)
182$omcollab_installation_dir = str_replace( '\\', '/', $expected_args['dest_dir'] );     
183if( $omcollab_installation_dir == '.' ) {
184    $omcollab_installation_dir = '/' . basename( dirname(__file__) ) . '/';
185}
186
187if( empty($omcollab_installation_dir) ){
188    $aErrors[] = "The installation directory must be / or . or /path/to/use/ with leading and trailing slashes";
189}
190
191#the http hostname - without the http part
192$omcollab_http_hostname = $expected_args['http_host'];
193
194#should we use short urls for the wiki?
195$use_short_urls = true;
196
197#skip database rebuild and preserve the wiki images and blogs upload dirs?
198if( strtolower( $expected_args['preserve'] ) != 'y' && strtolower( $expected_args['preserve'] ) != 'n' ) {
199        $aErrors[] = "Specify Y or N for 'Preserve Data', after the developer_id parameter";
200}
201function AddDirectoryToPreserveDirsArray( $dir ){
202 global $preserve_dirs;
203 if( file_exists( $dir ) && is_dir( $dir ) )$preserve_dirs[] = $dir;
204}
205$preserve_data = ( strtolower( $expected_args['preserve'] ) == 'y' ? true : false );
206$preserve_dirs = array();
207AddDirectoryToPreserveDirsArray( realpath( './' . ( $use_short_urls ? 'w' : 'wiki' ) . '/images' ) );
208AddDirectoryToPreserveDirsArray( realpath( "./blogs/wp-content/uploads" ) );
209AddDirectoryToPreserveDirsArray( realpath( "./forum/files" ) );
210AddDirectoryToPreserveDirsArray( realpath( "./home/omcache" ) );
211AddDirectoryToPreserveDirsArray( realpath( './' . ( $use_short_urls ? 'w' : 'wiki' ) . '/extensions/WikiSubscription/tmp' ) );
212
213
214#path to mysql binary ('nix) or exe (win)
215$path_to_mysql    = $expected_args['mysql_path'];
216$sMySqlExecutable = "{$path_to_mysql}mysql" . ( $is_windows ? '.exe' : '' );
217if( ! $preserve_data ){
218    #verify location of mysql executable
219    if( ! file_exists( $sMySqlExecutable ) || is_dir( $sMySqlExecutable ) ){
220        $aErrors[] = "Path to MySql is incorrect (tried '$sMySqlExecutable')";
221    }
222}
223
224#overwrite destination build.php with the source version?
225$overwrite_build_script = strtolower( $expected_args['overwrite'] );
226if( $overwrite_build_script != 'n' && $overwrite_build_script != 'y' ){
227        $aErrors[] = "Specify Y or N for 'Overwrite Build Script', after the 'Preserve Data' parameter";
228}else{
229        $overwrite_build_script = ( $overwrite_build_script == 'y' ? true : false );
230}
231
232if( $overwrite_build_script ){
233        $resources['teardown']['File'][] = 'build.php';
234}
235
236$mike2skin = $expected_args['mike2skin'];
237if( $mike2skin != 'blue' && $mike2skin != 'red' && $mike2skin !='green' ){
238    $aErrors[] = 'Skin parameter must be "blue" or "red" or "green"';
239}
240if( $mike2skin == 'blue' ){
241        $mike2skin = '';
242}
243
244$google_analytics = trim( $expected_args['google_analytics'] );
245if( empty( $google_analytics ) ){
246        $aErrors[] = 'GoogleAnaltyicsCode value must not be empty';
247}
248
249$google_cse_code  = $expected_args['google_cse_code'];
250$google_cse_forid = $expected_args['google_cse_forid'];
251$google_blog_key  = $expected_args['google_blog_key'];
252$enable_docconvert = $expected_args['enable_docconvert'];
253$openoffice_path = $expected_args['openoffice_path'];
254
255#die if any errors so far
256if( ! empty( $aErrors ) ){
257  die( "\n\nMissing required parameter(s):\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
258}
259
260#source files and dirs must be present
261foreach( $resources['setup'] as $resource_type => $resource_items ){
262    foreach( $resource_items as $resource_name ){
263        $resource_name = "$source_dir/$resource_name";
264        if( ! file_exists( "$resource_name" ) || ( $resource_type == 'Directory' && ! is_dir( "$resource_name" ) ) ) {
265            $aErrors[] = "$resource_type $resource_name not found";
266        }
267    }
268}
269
270#die if any errors so far
271if( ! empty( $aErrors ) ){
272  die( "\n\nProblem(s) occurred during resource checking:\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
273}
274
275#you cannot build from source code that exists in the directory as the build script
276$this_dir = realpath(dirname(__file__));
277$src_dir  = realpath($argv[2]);
278
279if(substr($this_dir,strlen($src_dir),0) == $src_dir) $aErrors[] = "The build script will not run if the source files are in the same dir as the build script. Move the build script away, or point to a source dir that is in some other place.";
280
281#die if any errors so far
282if( ! empty( $aErrors ) ){
283  die( "\n\nProblem(s) occurred during path checking:\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
284}
285
286
287
288echo " * Resource checking complete. Ready to tear down\n";
289
290      ######################################
291      #                                    #
292      #       sanity checks complete       #
293      #                                    #
294      ######################################
295
296#loop thru teardown files and dirs
297if( $preserve_data ){
298  echo " * Preserve Data is set to 'Y'... wiki and blog images are being preserved\n";
299}else{
300  echo " * Preserve Data is set to 'N'... wiki and blog images are being torn down and replaced\n";
301}
302
303foreach( $resources['teardown'] as $resource_type => $resource_items ){
304    foreach( $resource_items as $resource_name ){
305        if( $resource_type == 'Directory' ){
306            if( realpath( dirname(__file__) . "/$resource_name" ) ){
307                echo "    - removing " . realpath( dirname(__file__) . "/$resource_name" ) . " (directory)\n";
308            }
309            RemoveDirRecursively( realpath( dirname(__file__) . "/$resource_name" ) );
310        }else{
311            echo "    - removing $resource_name\n";
312            @unlink( $resource_name );
313        }
314        if( ( ! $preserve_data && file_exists( $resource_name ) )
315            || (   $preserve_data === true
316                && file_exists( $resource_name )
317                && $resource_name != ( $use_short_urls ? 'w' : 'wiki' )
318                && $resource_name != 'blogs' 
319                && $resource_name != 'forum'
320                && $resource_name != 'home')
321           ) $aErrors[] = "$resource_type $resource_name was not deleted";
322    }
323}
324
325#die if any errors so far
326if( ! empty( $aErrors ) ){
327  die( "\n\nProblem(s) occurred during teardown:\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
328}
329
330
331
332echo " * Tear down complete. Copying resources from source (takes a while)...!\n";
333
334#copying resources from source
335
336$resources['setup']['Directory'][] = ( $use_short_urls ? 'w' : 'wiki' );
337foreach( $resources['setup'] as $resource_type => $resource_items ){
338    foreach( $resource_items as $dest_name ){
339        if( $resource_type == 'File' ){
340                copy( "$source_dir/$dest_name", $dest_name );
341            echo "    - copied $resource_type " . realpath( "$source_dir/$dest_name" ) . " to " . realpath( $dest_name ) . "\n";
342        }else{
343                $source_name = "$source_dir/$dest_name";
344                /*
345                if( $use_short_urls && $dest_name == 'w' ){
346                        $source_name = "$source_dir/wiki";
347                }
348                */
349            CopyDirRecursively( $source_name, $dest_name );
350            echo "    - copied $resource_type " . realpath( $source_name ) . " to " . realpath( $dest_name ) . " \n";
351        }
352        if( ! file_exists( $dest_name ) || ( $resource_type == 'Directory' && ! is_dir( $dest_name ) ) ) {
353            $aErrors[] = "$resource_type " . realpath( $dest_name ) . " not copied from " . realpath( $source_name );
354        }
355    }
356}
357
358#die if any errors so far
359if( ! empty( $aErrors ) ){
360  die( "\n\nProblem(s) occurred during resource copying:\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
361}
362
363
364
365
366echo " * Resource copying complete\n";
367
368
369
370
371$build = array(); #container for build variables
372
373$build['omcollab_installation_dir']    = $omcollab_installation_dir;
374$build['omcollab_http_hostname']       = $omcollab_http_hostname;
375$build['omcollab_admin_email']         = 'webmaster@localhost';
376$build['omcollab_db_hostname']         = 'localhost';
377$build['omcollab_db_table_prefix']     = 'om';
378$build['omwiki_database_name']         = "{$dev_id}_omwiki";
379$build['omwiki_db_username']           = "{$dev_id}";
380$build['omwiki_db_password']           = "{$dev_id}";
381$build['omblogs_database_name']        = "{$dev_id}_omblogs";
382$build['omblogs_db_username']          = "{$dev_id}";
383$build['omblogs_db_password']          = "{$dev_id}";
384$build['ombookmarks_database_name']    = "{$dev_id}_ombookmarks";
385$build['ombookmarks_db_username']      = "{$dev_id}";
386$build['ombookmarks_db_password']      = "{$dev_id}";
387$build['omforum_database_name']            = "{$dev_id}_omforum";
388$build['omforum_db_username']              = "{$dev_id}";
389$build['omforum_db_password']              = "{$dev_id}";
390$build['omcollab_application_name']    = "{$dev_id} portal";
391$build['omwiki_application_name']      = "{$dev_id} wiki";
392$build['omblog_application_name']      = "{$dev_id} blogs";
393$build['ombookmarks_application_name'] = "{$dev_id} bookmarks";
394$build['omexplore_application_name']   = "{$dev_id} explore";
395$build['omforum_application_name']         = "{$dev_id} forum";
396$build['omcollab_initial_skin']        = $mike2skin;
397$build['omwiki_use_short_urls']        = $use_short_urls;
398$build['omcollab_google_analytics']    = $google_analytics;
399$build['omcollab_google_cse_code']     = $google_cse_code;
400$build['omcollab_google_cse_forid']    = $google_cse_forid;
401$build['omcollab_google_blog_key']     = $google_blog_key ;
402
403//Xiping.Wang , default option result is "off"
404if( $enable_docconvert == "on" ) {
405        $build[ 'omwiki_enable_docconvert' ] = "on";
406} else {
407        $build['omwiki_enable_docconvert']   = "off";
408}
409$build['omwiki_docconvert_oo_path']    = $openoffice_path;
410                             
411if( empty( $build['omcollab_admin_email']          ) ) $aErrors[] = 'Admin email';       
412if( empty( $build['omcollab_db_hostname']          ) ) $aErrors[] = 'Database hostname (eg localhost)';
413if( empty( $build['omcollab_db_table_prefix']      ) ) $aErrors[] = 'Database table prefix (eg "om")';
414if( empty( $build['omwiki_database_name']          ) ) $aErrors[] = 'Wiki database name';
415if( empty( $build['omwiki_db_username']            ) ) $aErrors[] = 'Wiki database username';
416if( empty( $build['omwiki_db_password']            ) ) $aErrors[] = 'Wiki database password';
417if( empty( $build['omblogs_database_name']         ) ) $aErrors[] = 'Blogs database name';
418if( empty( $build['omblogs_db_username']           ) ) $aErrors[] = 'Blogs database username';
419if( empty( $build['omblogs_db_password']           ) ) $aErrors[] = 'Blogs database password';
420if( empty( $build['ombookmarks_database_name']     ) ) $aErrors[] = 'Bookmarks database name';
421if( empty( $build['ombookmarks_db_username']       ) ) $aErrors[] = 'Bookmarks database username';
422if( empty( $build['ombookmarks_db_password']       ) ) $aErrors[] = 'Bookmarks database password';
423if( empty( $build['omforum_database_name']         ) ) $aErrors[] = 'Forum database name';
424if( empty( $build['omforum_db_username']           ) ) $aErrors[] = 'Forum database username';
425if( empty( $build['omforum_db_password']           ) ) $aErrors[] = 'Forum database password';
426if( empty( $build['omcollab_application_name']     ) ) $aErrors[] = 'omCollab application name (eg "omCollab Portal")';
427if( empty( $build['omwiki_application_name']       ) ) $aErrors[] = 'Wiki application name (eg "omCollab Wiki")';
428if( empty( $build['omblog_application_name']       ) ) $aErrors[] = 'Blog application name (eg "omCollab Blogs")';
429if( empty( $build['ombookmarks_application_name']  ) ) $aErrors[] = 'Bookmarks application name (eg "omBookmarks")';
430if( empty( $build['omforum_application_name']      ) ) $aErrors[] = 'Forum application name (eg "omForum")';
431if( empty( $build['omexplore_application_name']    ) ) $aErrors[] = 'Explore application name (eg "omCollab Explore")';
432
433#make sure last character of table prefix is an underscore
434if( substr( $build['omcollab_db_table_prefix'], -1 ) != '_' ){
435  $build['omcollab_db_table_prefix'] .= '_';
436}
437
438#die if any errors so far
439if( ! empty( $aErrors ) ){
440  die( "\n\nERROR: Missing or invalid...\n\n" . implode( "\n", $aErrors ) . "\n\nPlease try again.\n\n" );
441}
442
443$build[ 'default_style_num' ] = 2;
444if( $mike2skin == "red" ) {
445        $build[ 'default_style_num' ] = 3;
446}
447if( $mike2skin == "green" ) {
448        $build[ 'default_style_num' ] = 4;
449}
450#replace within sql dumps (these will be saved as temp files)
451if( ! $preserve_data ){
452  echo " * Preserve Data is set to 'N'... databases are being rebuilt\n * Copying SQL resources\n";
453  $aAppPlaceholders = array( 'wiki'      => array( 'omwiki_database_name'
454                                                 , 'omcollab_db_table_prefix' )
455                                                 
456                           , 'blogs'     => array( 'omblogs_database_name'
457                                                 , 'omcollab_db_table_prefix'
458                                                 , 'omcollab_http_hostname'
459                                                 , 'omcollab_installation_dir'
460                                                 , 'omblog_application_name'
461                                                 , 'omcollab_admin_email' )
462                                                 
463                           , 'bookmarks' => array( 'ombookmarks_database_name'
464                                                 , 'omcollab_db_table_prefix' )
465                           , 'forum'     => array( 'omforum_database_name'
466                                                                         , 'omcollab_db_table_prefix'
467                                                                         , 'omcollab_admin_email'
468                                                                         , 'omcollab_installation_dir'
469                                                                         , 'omforum_application_name'
470                                                                         , 'default_style_num' )
471                           );
472
473  foreach( $aAppPlaceholders as $sApp => $aPlaceholders ){
474        if ($sApp == 'wiki' && $mike2skin == 'red')
475                $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}_red.sql" );
476         else if ($sApp == 'wiki' && $mike2skin == 'green')
477                $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}_green.sql" );
478        else
479                $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}.sql" );
480               
481    foreach( $aPlaceholders as $sPlaceholder ){
482      $sSqlConfigure = str_replace( '{' . $sPlaceholder . '}', $build[ $sPlaceholder ], $sSqlConfigure );
483      echo "    - SQL Dump: $sApp -- {{$sPlaceholder}} > {$build[ $sPlaceholder ]}\n";
484    }
485    $aAppPlaceholders[ $sApp ][ 'sql' ] = $sSqlConfigure;
486    $sTmpFilename =  "_InstallationResources/om{$sApp}_temp.sql";
487    file_put_contents( $sTmpFilename, $sSqlConfigure );
488  }
489}else{
490  echo " * Preserve Data is set to 'Y'... databases are not being touched\n * Copying remaining resources\n";
491}
492
493#set up wiki for short urls if the web server is Apache and the user checked the box
494if( $build['omwiki_use_short_urls'] ){
495  $build['omwiki_script_path']  = "{$omcollab_installation_dir}w";
496  $build['omwiki_article_path'] = "{$omcollab_installation_dir}wiki/$1";
497}else{
498  $build['omwiki_script_path']  = "{$omcollab_installation_dir}wiki";
499  $build['omwiki_article_path'] = "{$omcollab_installation_dir}wiki/index.php/$1";
500}
501
502#replace within css files
503        /*$aMiscResources = array(
504                                 //common css for the blue skin
505                                 'common-blue.css' => array( 'destination'  => "common/skins/mike2/common.css"
506                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2" ) )
507                                 //common css for the green skin
508                               ,  'common-green.css' => array( 'destination'  => "common/skins/mike2green/common.css"
509                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2green" ) )
510                                 
511                                 //common css for the red skin
512                               , 'common-red.css'  => array( 'destination'  => "common/skins/mike2red/common.css"
513                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2red" ) )
514                                 
515                                 //wiki css for the blue skin
516                               , 'main-blue.css'   => array( 'destination'  => ($use_short_urls ? 'w' : 'wiki' ) . "/skins/mike2/main.css"
517                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2" ) )
518                               
519                                 //wiki css for the green skin
520                               , 'main-green.css'   => array( 'destination'  => ($use_short_urls ? 'w' : 'wiki' ) . "/skins/mike2green/main.css"
521                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2green" ) )
522
523                                 //wiki css for the red skin
524                               , 'main-red.css'    => array( 'destination'  => ($use_short_urls ? 'w' : 'wiki' ) . "/skins/mike2red/main.css"
525                                                           , 'placeholders' => array( 'rr_common_skin_directory' => "{$omcollab_installation_dir}common/skins/mike2red" ) )
526
527                                 //javascript file for the common jquery php api
528                               , 'common-jquery-extensions.js' => array( 'destination'  => "common/ajax/jquery/javascript/extensions.js"
529                                                                       , 'placeholders' => array( 'omcollab_http_hostname'    => $omcollab_http_hostname
530                                                                                                , 'omcollab_installation_dir' => $omcollab_installation_dir ) )
531                             
532                                 //javascript file for the wiki's SocialProfile extension
533                               , 'UserProfilePage.js' => array( 'destination'  => ($use_short_urls ? 'w' : 'wiki' ) . "/extensions/SocialProfile/UserProfile/UserProfilePage.js"
534                                                              , 'placeholders' => array( 'omcollab_http_hostname' => $omcollab_http_hostname
535                                                                                       , 'omwiki_script_path'     => $build['omwiki_script_path'] ) )
536                               
537                                 //javascript file for the wiki's SocialProfile extension
538                               , 'UserRelationship.js' => array( 'destination'  => ($use_short_urls ? 'w' : 'wiki' ) . "/extensions/SocialProfile/UserRelationship/UserRelationship.js"
539                                                              , 'placeholders' => array( 'omwiki_script_path'     => $build['omwiki_script_path'] ) )
540                                 //configuration file for the forum
541                               , 'config.php' => array( 'destination' => "forum/config.php"
542                                                                          , 'placeholders' => array( 'omforum_db_host' => $build['omcollab_db_hostname']
543                                                                                                                           , 'omforum_db_name' => $build['omforum_database_name']
544                                                                                                                           , 'omforum_db_user' => $build['omforum_db_username']
545                                                                                                                           , 'omforum_db_pwd' => $build['omforum_db_password']
546                                                                                                                           , 'omforum_tbl_prefix' => $build['omcollab_db_table_prefix'] ) )
547                               );
548                             
549        foreach( $aMiscResources as $sSource => $aMiscData ){
550                $sMiscOutput = file_get_contents( "_InstallationResources/$sSource" );
551                echo " * Setting up {$aMiscData['destination']}\n";
552                foreach( $aMiscData['placeholders'] as $sPlaceholder => $sValue ){
553                        $sMiscOutput = str_replace( '{' . $sPlaceholder . '}'
554                                          , $sValue
555                                          , $sMiscOutput );
556            echo "    - $sSource --> \n      {{$sPlaceholder}} > {$sValue}\n";
557                }
558                file_put_contents( $aMiscData['destination'], $sMiscOutput );
559        } */
560
561#if required, shell to mysql and build the databases from the dumpfiles
562if( ! $preserve_data ){
563  $DbIni = array();
564
565  $DbIni ['wiki'] ['Database'] = $build['omwiki_database_name'];
566  $DbIni ['wiki'] ['Username'] = $build['omwiki_db_username'];
567  $DbIni ['wiki'] ['Password'] = $build['omwiki_db_password'];
568
569  $DbIni ['blogs'] ['Database'] = $build['omblogs_database_name'];
570  $DbIni ['blogs'] ['Username'] = $build['omblogs_db_username'];
571  $DbIni ['blogs'] ['Password'] = $build['omblogs_db_password'];
572
573  $DbIni ['bookmarks'] ['Database'] = $build['ombookmarks_database_name'];
574  $DbIni ['bookmarks'] ['Username'] = $build['ombookmarks_db_username'];
575  $DbIni ['bookmarks'] ['Password'] = $build['ombookmarks_db_password'];
576
577  $DbIni ['forum'] ['Database'] = $build['omforum_database_name'];
578  $DbIni ['forum'] ['Username'] = $build['omforum_db_username'];
579  $DbIni ['forum'] ['Password'] = $build['omforum_db_password'];
580 
581  $aDbs         = array( 'wiki', 'blogs', 'bookmarks', 'forum' );
582  $aExecResults = array();
583  foreach( $aDbs as $sDb ){
584    $sCommand = "$sMySqlExecutable "
585              . "-h {$build['omcollab_db_hostname']} "
586              . "-u {$DbIni[$sDb]['Username']} "
587              . "-p{$DbIni[$sDb]['Password']} "
588              . "{$DbIni[$sDb]['Database']} < "
589              . realpath("_InstallationResources/om{$sDb}_temp.sql");
590    echo " * Building $sDb database {$DbIni[$sDb]['Database']} for {$DbIni[$sDb]['Username']}/{$DbIni[$sDb]['Password']}\n";
591    exec( $sCommand, $aOutput );
592    $aExecResults[$sCommand][] = $aOutput;
593  }
594}
595
596#set up wiki for short urls if the web server is Apache and the user checked the box
597#NB the folowing may unset the preserve_dirs array and set $preserve_data to false, so
598#do not try and use these values below this point. Nasssty!
599if( $build['omwiki_use_short_urls'] ){
600  copy( '_InstallationResources/.htaccess', './.htaccess' );
601  echo " * copied .htaccess into web root (for short url support)\n";
602}
603
604#replace within omconfig.php and rewrite
605$aPlaceholders = array( 'omcollab_installation_dir'
606                      , 'omcollab_admin_email'
607                      , 'omcollab_db_hostname'
608                      , 'omwiki_database_name'
609                      , 'omwiki_db_username'
610                      , 'omwiki_db_password'
611                      , 'omcollab_db_table_prefix'
612                      , 'omblogs_database_name'
613                      , 'omblogs_db_username'
614                      , 'omblogs_db_password'
615                      , 'omcollab_db_table_prefix'
616                      , 'ombookmarks_database_name'
617                      , 'ombookmarks_db_username'
618                      , 'ombookmarks_db_password'
619                      , 'omforum_database_name'
620                      , 'omforum_db_username'
621                      , 'omforum_db_password'
622                      , 'omcollab_db_table_prefix'
623                      , 'omcollab_application_name'
624                      , 'omwiki_application_name'
625                      , 'omblog_application_name'
626                      , 'ombookmarks_application_name'
627                      , 'omexplore_application_name'
628                      , 'omwiki_script_path'
629                      , 'omwiki_article_path'
630                      , 'omcollab_initial_skin'
631                          , 'omcollab_google_analytics'
632                          , 'omcollab_google_cse_code'
633                          , 'omcollab_google_cse_forid'
634                          , 'omcollab_google_blog_key'
635                          , 'omwiki_enable_docconvert'
636                          , 'omwiki_docconvert_oo_path' );
637 
638$sOmConfigPhp = file_get_contents( '_InstallationResources/omconfig.php' );
639foreach( $aPlaceholders as $sPlaceholder ){
640    $sOmConfigPhp = str_replace( '{' . $sPlaceholder . '}', $build[ $sPlaceholder ], $sOmConfigPhp );
641}
642file_put_contents( 'common/omconfig.php', $sOmConfigPhp );
643 
644#rename install.php
645copy( dirname( __file__) . '/install.php', dirname( __file__) . '/install.completed.php' );
646unlink( dirname( __file__) . '/install.php' );
647 
648#rewrite index.php
649//$sIndexContents = "<" . "?php\ninclude( \"home.php\" );\n?" . ">";
650//file_put_contents( 'index.php', $sIndexContents );
651unlink( dirname(__file__) . '/index.php');
652copy('_InstallationResources/index_temp.php', dirname(__file__) . '/index.php');
653
654#lastly, to ensure the app can launch without any annoying "you must delete such and such a file" messages....
655rename( '_InstallationResources', '__InstallationResources' );
656rename( 'install.completed.php', '_install.completed.php' );
657
658#for pre-existing installations of omCollab, there may still by this point be some pieces of code
659#somewhere that require additional manipulation.
660#the include statement below is for developers who want to wreak further havoc. the file (in SVN) does not exist
661#and the script will execute just fine without it. but if it's there, it will be called!
662if( file_exists( './my_additional_build_processes.php' ) ){
663  include( './my_additional_build_processes.php' );
664}
665
666#whew that was exhausting, time to
667die( "\n\nBuild complete!\n\n" );
668
Note: See TracBrowser for help on using the repository browser.