source: locker/deploy/bin/onserver.pm @ 456

Last change on this file since 456 was 456, checked in by quentin, 17 years ago
mediawiki 1.11 installer + improvements to installer system
  • Property svn:executable set to *
File size: 3.2 KB
RevLine 
[127]1package onserver;
2use strict;
3use Exporter;
[456]4use Sys::Hostname;
5use File::Spec::Functions;
6use File::Basename;
7use Socket;
8use Cwd qw(abs_path);
9use POSIX qw(strftime);
[127]10our @ISA = qw(Exporter);
11our @EXPORT = qw(setup totmp print_login_info press_enter $server $tmp $USER $HOME $sname $deploy $addrend $admin_username $requires_sql $addrlast $sqlhost $sqluser $sqlpass $sqldb $sqldbcurl $admin_password $scriptsdev $human);
12
13our $server = "scripts.mit.edu";
14
15our ($tmp, $USER, $HOME, $sname, $deploy, $addrend, $admin_username, $requires_sql, $addrlast, $sqlhost, $sqluser, $sqlpass, $sqldb, $sqldbcurl, $admin_password, $scriptsdev, $human);
16
17$tmp = ".scripts-tmp";
18sub totmp {
19  open(FILE, ">$tmp");
20  print FILE $_[0];
21  close(FILE);
22}
23
24sub print_login_info {
25  print "\nYou will be able to log in to $sname using the following:\n";
26  print "  username: $admin_username\n";
27  print "  password: $admin_password\n";
28}
29
[456]30sub getclienthostname {
31    if (my $sshclient = $ENV{"SSH_CLIENT"}) {
32        my ($clientip) = split(' ', $sshclient);
33        my $hostname = gethostbyaddr(inet_aton($clientip), AF_INET);
34        return $hostname || $clientip;
35    } else {
36        return hostname();
37    }
38}
39
[127]40sub press_enter {
41  local $/ = "\n";
42  print "Press [enter] to continue with the install.";
43  my $enter = <STDIN>; 
44}
45
46sub setup {
47  $ENV{PATH} = '/bin:/usr/bin';
48  $USER = $ENV{USER};
49  $HOME = $ENV{HOME};
50 
51  ($sname, $deploy, $addrend, $admin_username, $requires_sql, $scriptsdev, $human) = @ARGV;
52  chdir "$HOME/web_scripts/$addrend";
53 
54  if($addrend =~ /^(.*)\/$/) {
55    $addrend = $1;
56  }
57  ($addrlast) = ($addrend =~ /([^\/]*)$/);
58 
59  if($requires_sql) {
60    print "\nCreating SQL database for $sname...\n";
61   
62    my $getpwd=`/mit/scripts/sql/bin$scriptsdev/get-password`;
63    ($sqlhost, $sqluser, $sqlpass) = split(/\s/, $getpwd);
64   
65    $sqldb=`/mit/scripts/sql/bin$scriptsdev/get-next-database "$addrlast"`;
66    $sqldb=`/mit/scripts/sql/bin$scriptsdev/create-database "$sqldb"`;
67    if($sqldb eq "") {
68      print "\nERROR:\n";
69      print "Your SQL account failed to create a SQL database.\n";
70      print "You should log in at http://sql.mit.edu to check whether\n";
71      print "your SQL account is at its database limit or its storage limit.\n";
72      print "If you cannot determine the cause of the problem, please\n";
73      print "feel free to contact sql\@mit.edu for assistance.\n";
74      `touch .failed`;
75      exit 1;
76    }
77    $sqldbcurl = $sqldb;
78    $sqldbcurl =~ s/\+/\%2B/;
79  }
80 
[239]81  if(-e "$HOME/web_scripts/$addrend/.admin") { 
82    $admin_password=`cat $HOME/web_scripts/$addrend/.admin`;
[240]83    chomp($admin_password);
84    unlink "$HOME/web_scripts/$addrend/.admin";
85  } 
86
[127]87  print "\nConfiguring $sname...\n";
88 
[456]89  open(VERSION, ">.scripts-version") or die "Can't write scripts-version file: $!\n";
90  print VERSION strftime("%F %T %z\n", localtime);
91  print VERSION $ENV{'USER'}, '@', getclienthostname(), "\n";
92  my $tarball = abs_path("/mit/scripts/deploy$scriptsdev/$deploy.tar.gz");
93  print VERSION $tarball, "\n";
94  $tarball =~ s|/deploydev/|/deploy/|;
95  print VERSION dirname($tarball), "\n";
96  close(VERSION);
97  if (0) {
98      `date > .scripts-version`;
99      `stat /mit/scripts/deploy$scriptsdev/$deploy.tar.gz >> .scripts-version`;
100  }
[127]101
102  select STDOUT;
103  $| = 1; # STDOUT is *hot*!
104}
Note: See TracBrowser for help on using the repository browser.