#!/usr/bin/php 0) { $txt = "Connecting to database ".$config_data['drupal_user'] .':'. $config_data['drupal_password'].'@'.$db_server; logger($logfile, $txt); mysql_connect($db_server, $config_data['drupal_user'], $config_data['drupal_password']) or die(mysql_error()); //create database and user for Drupal logger($logfile, 'Connected.'); mysql_query("CREATE USER 'origo_" . $project_id . "'@'localhost' IDENTIFIED BY '" . $password . "'") or file_put_contents($logfile, mysql_error() ."\n", FILE_APPEND); mysql_query("CREATE DATABASE `origo_" . $project_name . "`") or file_put_contents($logfile, mysql_error() ."\n", FILE_APPEND); // priviledges on project-db mysql_query("GRANT ALL PRIVILEGES ON `origo_" . $project_name . "` . * TO 'origo_" . $project_id . "'@'localhost'") or file_put_contents($logfile, mysql_error() ."\n", FILE_APPEND); // priviledges on shared db mysql_query("GRANT ALL PRIVILEGES ON `drupal_shared` . * TO 'origo_" . $project_id . "'@'localhost'") or file_put_contents($logfile, mysql_error() ."\n", FILE_APPEND); logger($logfile, "Database created. Now continuing creating files and folders."); logger($logfile, "Creating sites directory and setting up symlinks"); //create site directory mkdir($origo_path . 'sites/' . $project_name, 0755); //symbolic link for drupal site detection // one for access via subdomain if ($config_data['origo_use_subdomains']) { symlink($project_name, $origo_path . 'sites/' . $project_name . '.' . $origo_server); } else { // one for access via subdirectory symlink($project_name, $origo_path . 'sites/'. $origo_server .'.projects.'. $project_name); // and one apache-redirection for subdirectory access symlink($origo_path, $origo_path . 'projects/'. $project_name); } //touch initial settings exec('touch ' . $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 ..." logger($logfile, 'Done.'); // Drupal installation using the Origo profile logger($logfile, "Drupal installation using the Origo profile"); require_once dirname(__FILE__) .'/drupal-installer.php'; if ($config_data['origo_use_subdomains']) { $project_url = 'http://' . $project_name .'.'. $origo_server .'/'; } else { $project_url = 'http://'. $origo_server .'/projects/'. $project_name .'/'; } $project_configuration_variables = array ( 'profile' => $drupal_profile, 'db' => 'origo_' . $project_name, 'db_type' => $db_type, 'db_host' => $db_server, 'db_user' => 'origo_' . $project_id, 'db_password' => $password, 'site_name' => $project_name, 'username' => 'admin', 'password' => 'origo_admin_pass', 'email' => $config_data['email_sender_default'], 'url' => $project_url, ); origo_install($project_configuration_variables); logger($logfile, "Finished Drupal installer."); // 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()); // Update settings file exec('chmod 644 ' . $origo_path . 'sites/' . $project_name . '/settings.php'); // shared tables configuration // Note: we need to do this here, as there's currently no way to specify shared tables during the installation $settings_file = $origo_path . 'sites/' . $project_name . '/settings.php'; $txt = "\n\n\$db_prefix = array(\n"; $txt .= "\t'default' => '',\n"; $txt .= "\t'bayesian_tokens' => 'drupal_shared.',\n"; $txt .= ");\n\n"; file_put_contents($settings_file, $txt, FILE_APPEND); // Disable update module, as this is enabled internally by the installer we can not control this with the profile logger($logfile, shell_exec('cd '.$origo_path.' && php '.$drush_script.' -y -l '.$project_name.' disable update'), true); logger($logfile, "Project creation done.\n", false); } 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 logger($file, $msg, $indent = true) { $t = date('H:i:s', time()); $tab = $indent ? "\t" : ''; file_put_contents($file, $tab ."[ $t ] $msg\n", FILE_APPEND); } function prln($str) { global $verbose; if ($verbose) { echo $str."\n"; } }