#!/usr/bin/php 0) { prln('Connecting to database '.$config_data['drupal_user'].':'.$config_data['drupal_password'].'@'.$db_server ); mysql_connect($db_server, $config_data['drupal_user'], $config_data['drupal_password']) or die(mysql_error()); //create database and user for Drupal prln('Connection to database OK - setting up users and database. '); 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); mysql_query("GRANT ALL PRIVILEGES ON `origo_" . $project_name . "` . * TO 'origo_" . $project_id . "'@'localhost'") or file_put_contents($logfile, mysql_error() ."\n", FILE_APPEND); file_put_contents($logfile, "database created. now continuing creating files and folders.\n", FILE_APPEND); prln('Creating sites directory and setting up symlinks'); file_put_contents($logfile, "Creating sites directory and setting up symlinks\n", FILE_APPEND); //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 ..." prln('done'."\n"); // Drupal installation using the Origo profile prln('Drupal installation using the Origo profile'); file_put_contents($logfile, "Drupal installation using the Origo profile\n", FILE_APPEND); 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); prln('finished drupal installer.'); file_put_contents($logfile, "finished drupal installer.\n", FILE_APPEND); // 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'); // Disable update module, as this is enabled internally by the installer we can not control this with the profile file_put_contents($logfile, shell_exec('cd '.$origo_path.' && php '.$drush_script.' -y -l '.$project_name.' disable update'), FILE_APPEND); prln ("project creation done"); file_put_contents($logfile, "project creation done.\n\n", FILE_APPEND); } 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"; } }