#!/usr/bin/perl
use strict;
use lib '/mit/scripts/deploy/bin';
use onserver;
use DBI;

setup();

fetch_uri(
    'wp-admin/setup-config.php',
    {step => 2},
    {dbhost => $sqlhost,
     uname => $sqluser,
     dbname => $sqldb,
     pwd => $sqlpass,
     prefix => '',
     submit => 'Submit',
     step => 2});

my $html = fetch_uri(
    'wp-admin/install.php',
    {step => 2},
    {weblog_title => 'My Blog',
     admin_email => $email,
     submit => 'Continue',
     step => 2});
while ($html =~ /<code>(.*)<\/code>/g) {
    $admin_username = $admin_password;
    $admin_password = $1;
}

my $dbh = DBI->connect("dbi:mysql:database=$sqldb;host=$sqlhost", $sqluser, $sqlpass);
$dbh->do("update wp_options set option_value = ? where option_name = 'siteurl'",
         {}, "/~$USER/$addrend");
$dbh->do("update wp_options set option_value = ? where option_name = 'home'",
         {}, "http://$USER.$server/$addrend");
$dbh->disconnect;

print_login_info();
print "You will also receive this login information at your MIT email address.\n";
press_enter();
