[127] | 1 | package onserver; |
---|
| 2 | use strict; |
---|
| 3 | use Exporter; |
---|
| 4 | our @ISA = qw(Exporter); |
---|
| 5 | our @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); |
---|
| 6 | |
---|
| 7 | our $server = "scripts.mit.edu"; |
---|
| 8 | |
---|
| 9 | our ($tmp, $USER, $HOME, $sname, $deploy, $addrend, $admin_username, $requires_sql, $addrlast, $sqlhost, $sqluser, $sqlpass, $sqldb, $sqldbcurl, $admin_password, $scriptsdev, $human); |
---|
| 10 | |
---|
| 11 | $tmp = ".scripts-tmp"; |
---|
| 12 | sub totmp { |
---|
| 13 | open(FILE, ">$tmp"); |
---|
| 14 | print FILE $_[0]; |
---|
| 15 | close(FILE); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | sub print_login_info { |
---|
| 19 | print "\nYou will be able to log in to $sname using the following:\n"; |
---|
| 20 | print " username: $admin_username\n"; |
---|
| 21 | print " password: $admin_password\n"; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | sub press_enter { |
---|
| 25 | local $/ = "\n"; |
---|
| 26 | print "Press [enter] to continue with the install."; |
---|
| 27 | my $enter = <STDIN>; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | sub setup { |
---|
| 31 | $ENV{PATH} = '/bin:/usr/bin'; |
---|
| 32 | $USER = $ENV{USER}; |
---|
| 33 | $HOME = $ENV{HOME}; |
---|
| 34 | |
---|
| 35 | ($sname, $deploy, $addrend, $admin_username, $requires_sql, $scriptsdev, $human) = @ARGV; |
---|
| 36 | chdir "$HOME/web_scripts/$addrend"; |
---|
| 37 | |
---|
| 38 | if($addrend =~ /^(.*)\/$/) { |
---|
| 39 | $addrend = $1; |
---|
| 40 | } |
---|
| 41 | ($addrlast) = ($addrend =~ /([^\/]*)$/); |
---|
| 42 | |
---|
| 43 | if($requires_sql) { |
---|
| 44 | print "\nCreating SQL database for $sname...\n"; |
---|
| 45 | |
---|
| 46 | my $getpwd=`/mit/scripts/sql/bin$scriptsdev/get-password`; |
---|
| 47 | ($sqlhost, $sqluser, $sqlpass) = split(/\s/, $getpwd); |
---|
| 48 | |
---|
| 49 | $sqldb=`/mit/scripts/sql/bin$scriptsdev/get-next-database "$addrlast"`; |
---|
| 50 | $sqldb=`/mit/scripts/sql/bin$scriptsdev/create-database "$sqldb"`; |
---|
| 51 | if($sqldb eq "") { |
---|
| 52 | print "\nERROR:\n"; |
---|
| 53 | print "Your SQL account failed to create a SQL database.\n"; |
---|
| 54 | print "You should log in at http://sql.mit.edu to check whether\n"; |
---|
| 55 | print "your SQL account is at its database limit or its storage limit.\n"; |
---|
| 56 | print "If you cannot determine the cause of the problem, please\n"; |
---|
| 57 | print "feel free to contact sql\@mit.edu for assistance.\n"; |
---|
| 58 | `touch .failed`; |
---|
| 59 | exit 1; |
---|
| 60 | } |
---|
| 61 | $sqldbcurl = $sqldb; |
---|
| 62 | $sqldbcurl =~ s/\+/\%2B/; |
---|
| 63 | } |
---|
| 64 | |
---|
[239] | 65 | if(-e "$HOME/web_scripts/$addrend/.admin") { |
---|
| 66 | $admin_password=`cat $HOME/web_scripts/$addrend/.admin`; |
---|
[240] | 67 | chomp($admin_password); |
---|
| 68 | unlink "$HOME/web_scripts/$addrend/.admin"; |
---|
| 69 | } |
---|
| 70 | |
---|
[127] | 71 | print "\nConfiguring $sname...\n"; |
---|
| 72 | |
---|
| 73 | `date > .scripts-version`; |
---|
| 74 | `stat /mit/scripts/deploy$scriptsdev/$deploy.tar.gz >> .scripts-version`; |
---|
| 75 | |
---|
| 76 | select STDOUT; |
---|
| 77 | $| = 1; # STDOUT is *hot*! |
---|
| 78 | } |
---|