0) { /* * Create project and copy files for drupal */ prln('Connecting to database '.$login_data['manager_user'].':'.$login_data['manager_password'].'@'.$db_server ); mysql_connect($db_server, $login_data['manager_user'], $login_data['manager_password']) or die(mysql_error()); //create database and user for Drupal prln('Setting up users and database. '); mysql_query("CREATE USER 'origo_" . $project_id . "'@'localhost' IDENTIFIED BY '" . $password . "'") or prln(mysql_error()); mysql_query("CREATE DATABASE `origo_" . $project_name . "`") or prln(mysql_error()); mysql_query("GRANT ALL PRIVILEGES ON `origo_" . $project_name . "` . * TO 'origo_" . $project_id . "'@'localhost'") or prln(mysql_error()); prln('Creating sites directory and setting up symlinks'); //create site directory mkdir($origo_path . 'sites/' . $project_name, 0755); //symbolic link for drupal site detection symlink($project_name, $origo_path . 'sites/' . $project_name . '.' . $origo_server); //copy initial settings from template copy($origo_path . 'sites/template/settings.php', $origo_path . 'sites/' . $project_name . '/settings.php'); //set rights on settings file exec('chmod 666 ' . $origo_path . 'sites/' . $project_name . '/settings.php'); //copy files directory exec('cp -R ' . $origo_path . 'sites/template/files ' . $origo_path . 'sites/' . $project_name . '/files'); //set owner for files directory exec('chown -R www-data:www-data ' . $origo_path . 'sites/' . $project_name . '/files'); // might have to change to "sudo chown -R ..." /* * Drupal installation using the Origo profile */ prln('Drupal installation using the Origo profile'); require_once "HTTP/Request.php"; $req =& new HTTP_Request('http://' . $project_name . '.' . $origo_server . '/install.php?profile=origo'); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addPostData('db_type', 'mysqli'); $req->addPostData('db_path', 'origo_' . $project_name); $req->addPostData('db_user', 'origo_' . $project_id); $req->addPostData('db_pass', $password); $req->addPostData('db_host', 'localhost'); $req->addPostData('form_id', 'install_settings_form'); $req->sendRequest(); $req = new HTTP_Request('http://' . $project_name . '.' . $origo_server . '/install.php?profile=origo'); $req->sendRequest(); /* * DB changes after Drupal installation */ mysql_select_db('origo_' . $project_name) or prln(mysql_error()); //set own project id and name mysql_query("INSERT INTO `variable` ( `name` , `value` ) VALUES ('origo_project_id', 'i:".$project_id.";')") or prln(mysql_error()); mysql_query("INSERT INTO `variable` ( `name` , `value` ) VALUES ('origo_project_name', 's:".strlen($project_name).":\"".$project_name."\";')") or prln(mysql_error()); //set site name mysql_query("UPDATE `variable` SET `value` = 's:" . strlen($project_name) . ":\"".ucwords($project_name)."\";' WHERE CONVERT( `variable`.`name` USING utf8 ) = 'site_name' LIMIT 1 ;") or prln(mysql_error()); //set file directory mysql_query("INSERT INTO `variable` ( `name` , `value` ) VALUES ('file_directory_path', 's:".(strlen($project_name)+12).":\"sites/".$project_name."/files\";');") or prln(mysql_error()); //set 'home' page title to project name mysql_query("UPDATE `node` SET `title` = '" . ucwords($project_name) . "' WHERE `node`.`nid` =5 AND `node`.`vid` =30 LIMIT 1 ;") or prln(mysql_error()); //mysql_query("UPDATE `menu` SET `title` = '".ucwords($project_name)."' WHERE `menu`.`mid` =145 LIMIT 1 ;"); mysql_query("UPDATE `node_revisions` SET `title` = '" . ucwords($project_name) . "' WHERE `node_revisions`.`vid` =29 LIMIT 1 ;") or prln(mysql_error()); mysql_query("UPDATE `node_revisions` SET `body` = 'Welcome!\r\n\r\nThis is the new web site of ''''''" . ucwords($project_name) . "'''''' - find more info here:\r\n* [[Doc]]\r\n* [[Screenshots]]\r\n* [[path:download|Downloads]]\r\nIf you want to report an issue - please refer to the [[path:issues|issue tracker]].\r\n\r\n''''''" . ucwords($project_name) . "'''''' is hosted by [http://origo.ethz.ch Origo] - if you want to get informed about project activities like wiki edits, commits, forum posts or new releases then [[path:user/register|create an Origo user account]], bookmark this project and configure your [[path:origo_home/settings/subscriptions|work item subscriptions]].\r\nOnce you have an ''''''Origo'''''' account, you can also create ''''''your own'''''' projects - it''s ''''''free''''''!' WHERE `node_revisions`.`vid` =29 LIMIT 1 ;") or prln(mysql_error()); //set correct alias for home page mysql_query("UPDATE `url_alias` SET `dst` = 'wiki/".strtolower($project_name)."' WHERE `src` ='node/5';") or prln(mysql_error()); //remove latest items from menu mysql_query("UPDATE `menu` SET `type` = '48' WHERE `menu`.`path` ='tracker' LIMIT 1 ;") or prln(mysql_error()); //remove logout from left menu mysql_query("UPDATE `menu` SET `type` = '48' WHERE `menu`.`path` ='logout' LIMIT 1 ;") or prln(mysql_error()); /* * Update settings file */ copy($origo_path . 'sites/' . $project_name . '/settings.php', $origo_path . 'sites/' . $project_name . '/settings.save'); exec('patch -p0 ' . $origo_path . 'sites/' . $project_name . '/settings.php < ' . $origo_path . 'sites/template/settings.patch'); //set rights on settings file exec('chmod 644 ' . $origo_path . 'sites/' . $project_name . '/settings.php'); prln ("project creation done"); } else { prln( "usage:\n arg1\t project id\n arg2\t project name "); } // random password generation function generate_password() { $rows = array(); array_push($rows, range('A' , 'Z')); array_push($rows, range('a' , 'z')); array_push($rows, range(0 , 9)); $min_length = 8; $max_length = 11; $shuffle = 3; $chars = array(); foreach($rows as $row) $chars = array_merge($chars, $row); for ($i = 0 ; $i < $shuffle ; $i++) shuffle($chars); $password = ''; $length = rand($min_length , $max_length); for ($i = 0 ; $i < $length ; $i++) $password .= $chars[array_rand($chars , 1)]; return $password; } function prln($str) { global $verbose; if ($verbose) echo $str."\n"; } ?>