| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# myproxy-server-setup: interactive myproxy-server installer |
| 4 |
|
| 5 |
use File::Temp qw(tempdir); |
| 6 |
use IPC::Open3; |
| 7 |
|
| 8 |
$CONFIG = "/etc/myproxy-server.config"; |
| 9 |
|
| 10 |
$tmpdir = tempdir(CLEANUP => 1); |
| 11 |
|
| 12 |
&checksanity(); |
| 13 |
&checkcerts(); |
| 14 |
&setupconfig(); |
| 15 |
&setupboot(); |
| 16 |
&startserver(); |
| 17 |
&testserver(); |
| 18 |
|
| 19 |
exit 0; |
| 20 |
|
| 21 |
sub checksanity { |
| 22 |
die "must be run as root, stopped" if ($>); |
| 23 |
die "\$GLOBUS_LOCATION not defined, stopped" |
| 24 |
if (!defined $ENV{'GLOBUS_LOCATION'}); |
| 25 |
chomp($gpi = `which grid-proxy-init 2>/dev/null`); |
| 26 |
die "grid-proxy-init not in PATH, stopped" if (!(-x $gpi)); |
| 27 |
chomp($gpd = `which grid-proxy-destroy 2>/dev/null`); |
| 28 |
die "grid-proxy-destroy not in PATH, stopped" if (!(-x $gpd)); |
| 29 |
chomp($mps = `which myproxy-server 2>/dev/null`); |
| 30 |
die "myproxy-server not in PATH, stopped" if (!(-x $mps)); |
| 31 |
} |
| 32 |
|
| 33 |
sub checkcerts { |
| 34 |
if (defined $ENV{'X509_USER_CERT'}) { |
| 35 |
$hostcert = $ENV{'X509_USER_CERT'}; |
| 36 |
} else { |
| 37 |
$hostcert = "/etc/grid-security/hostcert.pem"; |
| 38 |
} |
| 39 |
if (defined $ENV{'X509_USER_KEY'}) { |
| 40 |
$hostkey = $ENV{'X509_USER_KEY'}; |
| 41 |
} else { |
| 42 |
$hostkey = "/etc/grid-security/hostkey.pem"; |
| 43 |
} |
| 44 |
if (!-e $hostcert && !-e $hostkey) { |
| 45 |
die "no host credentials found, stopped"; |
| 46 |
} |
| 47 |
$cmd = "$gpi -debug -verify -cert $hostcert -key $hostkey -out $tmpdir/p"; |
| 48 |
($exitstatus, $output) = &runcmd($cmd, undef); |
| 49 |
system("$gpd $tmpdir/p >/dev/null 2>&1"); |
| 50 |
if ($exitstatus) { |
| 51 |
print STDERR "Problem with host credentials:\n$output\n"; |
| 52 |
exit 1; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
sub setupconfig { |
| 57 |
if (-e $CONFIG) { |
| 58 |
print "Existing $CONFIG not modified.\n"; |
| 59 |
} else { |
| 60 |
open(CONF, ">$CONFIG") || die "failed to open $CONFIG, stopped"; |
| 61 |
print CONF "# Default policy written by myproxy-server-setup.\n"; |
| 62 |
print CONF "accepted_credentials \"*\"\n"; |
| 63 |
print CONF "authorized_retrievers \"*\"\n"; |
| 64 |
print CONF "default_retrievers \"*\"\n"; |
| 65 |
print CONF "authorized_renewers \"*\"\n"; |
| 66 |
print CONF "default_renewers \"none\"\n"; |
| 67 |
print CONF "authorized_key_retrievers \"*\"\n"; |
| 68 |
print CONF "default_key_retrievers \"none\"\n"; |
| 69 |
print CONF "trusted_retrievers \"*\"\n"; |
| 70 |
print CONF "default_trusted_retrievers \"none\"\n"; |
| 71 |
print CONF "cert_dir /etc/grid-security/certificates\n"; |
| 72 |
close(CONF); |
| 73 |
print "Wrote a default myproxy-server configuration to $CONFIG.\n"; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
sub setupboot { |
| 78 |
if (-e "/etc/init.d/myproxy") { |
| 79 |
print "Existing /etc/init.d/myproxy not modified.\n"; |
| 80 |
} elsif (-e "/etc/rc.d/init.d/myproxy") { |
| 81 |
print "Existing /etc/rc.d/init.d/myproxy not modified.\n" |
| 82 |
} elsif (-d "/etc/init.d") { |
| 83 |
$initdir = "/etc/init.d"; |
| 84 |
} elsif (-d "/etc/rc.d/init.d") { |
| 85 |
$initdir = "/etc/rc.d/init.d"; |
| 86 |
} else { |
| 87 |
print "No init.d directory found. Manual installation of myproxy init script required.\n"; |
| 88 |
} |
| 89 |
if (defined $initdir) { |
| 90 |
$IN = "$ENV{'GLOBUS_LOCATION'}/share/myproxy/etc.init.d.myproxy"; |
| 91 |
open(IN) || die "failed to open $IN, stopped"; |
| 92 |
open(OUT, ">$initdir/myproxy") || |
| 93 |
die "failed to open $initdir/myproxy, stopped"; |
| 94 |
while (<IN>) { |
| 95 |
if (/GLOBUS_LOCATION=/) { |
| 96 |
print OUT "GLOBUS_LOCATION=\"$ENV{'GLOBUS_LOCATION'}\"\n"; |
| 97 |
} else { |
| 98 |
print OUT; |
| 99 |
} |
| 100 |
} |
| 101 |
close(IN); |
| 102 |
close(OUT); |
| 103 |
chmod(0755, "$initdir/myproxy"); |
| 104 |
print "Installed $initdir/myproxy.\n"; |
| 105 |
if (-x "/sbin/chkconfig") { |
| 106 |
$chkconfig = "/sbin/chkconfig"; |
| 107 |
} elsif (-x "/usr/sbin/chkconfig") { |
| 108 |
$chkconfig = "/usr/sbin/chkconfig"; |
| 109 |
} else { |
| 110 |
chomp($chkconfig = `which chkconfig 2>/dev/null`); |
| 111 |
} |
| 112 |
if (-x "/sbin/update-rc.d") { |
| 113 |
$updatercd = "/sbin/update-rc.d"; |
| 114 |
} elsif (-x "/usr/sbin/update-rc.d") { |
| 115 |
$updatercd = "/usr/sbin/update-rc.d"; |
| 116 |
} else { |
| 117 |
chomp($updatercd = `which update-rc.d 2>/dev/null`); |
| 118 |
} |
| 119 |
if (-x $chkconfig) { |
| 120 |
system("$chkconfig --add myproxy"); |
| 121 |
} elsif (-x $updatercd) { |
| 122 |
system("update-rc.d myproxy defaults"); |
| 123 |
} else { |
| 124 |
print "Manual configuration of rc.d links may be required.\n"; |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
sub startserver { |
| 130 |
if (defined $initdir && -x "$initdir/myproxy") { |
| 131 |
system("$initdir/myproxy start") && |
| 132 |
die "failed to start myproxy-server, stopped"; |
| 133 |
} else { |
| 134 |
print "Starting myproxy-server.\n"; |
| 135 |
system("myproxy-server") && |
| 136 |
die "failed to start myproxy-server, stopped"; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
sub testserver { |
| 141 |
print "Running myproxy-server tests...\n"; |
| 142 |
delete $ENV{'$COG_INSTALL_PATH'}; |
| 143 |
$ENV{'X509_USER_PROXY'} = "$tmpdir/p"; |
| 144 |
$cmd = "$gpi -cert $hostcert -key $hostkey -out $ENV{'X509_USER_PROXY'}"; |
| 145 |
system("$cmd >/dev/null 2>&1"); |
| 146 |
($exitstatus, $output) = &runcmd("myproxy-test", undef); |
| 147 |
system("$gpd $ENV{'X509_USER_PROXY'} >/dev/null 2>&1"); |
| 148 |
if ($exitstatus) { |
| 149 |
print STDERR "myproxy-test failed:\n$output\n"; |
| 150 |
exit 1; |
| 151 |
} else { |
| 152 |
print "Success!\n"; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
sub runcmd { |
| 157 |
local($command, $input) = @_; |
| 158 |
|
| 159 |
$pid = open3(*Writer, *Reader, '', "exec $command") || |
| 160 |
die "failed to run $command"; |
| 161 |
print Writer $input if (defined($input)); |
| 162 |
close(Writer); |
| 163 |
@output = <Reader>; |
| 164 |
close(Reader); |
| 165 |
waitpid($pid, 0); |
| 166 |
$exitstatus = $?; |
| 167 |
$output = join('', @output); |
| 168 |
|
| 169 |
return ($exitstatus, $output); |
| 170 |
} |