Install drupal with cURL

<?php

/**
 * playing around with curl. Here is an example of using curl for installing drupal
 * without using the browser
 *
 * Just change different settings and run
 * php drupal-curl.php
 *
 * Script will produce html for all urls visited. To collect the result use:
 * php drupal-curl.php > drul.html
 *  
 * Written by dennis iversen
 */


// your site
$site_url = 'http://drupal-dev';

// profile
$profile = 'default';

// locale
$locale = 'en';

// database
$db_path = 'drupaldev';

// database user
$db_user = 'root';

// database pass
$db_pass = 'pass';

// database host
$db_host = 'localhost';

// name of site
$site_name = 'site_name';

// site email
$site_mail = 'site_mail@site.com';

// admin account name
$account_name = 'admin';

// admin account email
$account_mail = 'admin@admin.dk';

// admin account pass
$account_pass = 'admin';

// date time zone
$date_default_timezone = '-39600';

// use clean url.
$clean_url = '1';

// update status module
$update_status_module = '1';

// end of settings

// create a url for curling db settings
$url_str = "db_path=$db_path&";
$url_str.= "db_user=$db_user&";
$url_str.= "db_pass=$db_pass&";
$url_str.= "db_host=$db_host&";
$url_str.= "db_prefix=&";
$url_str.= "db_port=&";
$url_str.= "op=" .urlencode("Save and continue") . "&";
$url_str.= "form_id=install_settings_form";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=$profile&locale=$locale");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url_str);
$html = curl_exec ($ch); // execute the curl command
curl_close ($ch);
unset($ch);
echo $html;

// we need to do the same address again because cookie
// is only set second time, then we get cookie and move on.

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookieFileName");
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=$profile&locale=$locale");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url_str);
$html = curl_exec ($ch); // execute the curl command
curl_close ($ch);
unset($ch);
echo $html;

// install modules part one 80 %
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cookieFileName");
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=$profile&locale=$locale&op=do_nojs&id=1");
$html = curl_exec ($ch); // execute the curl command
curl_close ($ch);
unset($ch);
echo $html;

// install last 20 %
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cookieFileName");
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=$profile&locale=$locale&op=do_nojs&id=1");
$html = curl_exec ($ch); // execute the curl command
curl_close ($ch);
unset($ch);
echo $html;

// confirm finished
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cookieFileName");
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=$profile&locale=$locale&op=finished&id=1");
$html = curl_exec ($ch); // execute the curl command
curl_close ($ch);
unset($ch);
echo $html;

// set settings for loading database with site base settings
$url_str = "site_name=$site_name&";
$url_str.= "site_mail=$site_mail&";
$url_str.= "account[name]=$account_name&";
$url_str.= "account[mail]=$account_mail&";
$url_str.= "account[pass][pass1]=$account_pass&";
$url_str.= "account[pass][pass2]=$account_pass&";
$url_str.= "date_default_timezone=$date_default_timezone&";
$url_str.= "clean_url=$clean_url&";
$url_str.= "form_id=install_configure_form&";
$url_str.= "update_status_module[1]=$update_status_module";

   
// enter these settings in a last curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cookieFileName");
curl_setopt($ch, CURLOPT_URL,"$site_url/install.php?profile=default&locale=en");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url_str);

$html = curl_exec ($ch);
curl_close ($ch);
echo $html;

?>