Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92774206
install
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 23, 14:59
Size
5 KB
Mime Type
text/x-perl
Expires
Mon, Nov 25, 14:59 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
22499415
Attached To
R6835 Tequila Perl client
install
View Options
#!/usr/bin/perl
#
use strict;
use Socket;
use Getopt::Long;
my ($test, $verbose);
my $ret = GetOptions (
verbose => \$verbose,
test => \$test,
);
my ($config, $defaultsesdir, $defaultserver, $defaultserverurl);
#
print "\nTequila perl client simple setup.\n\n";
checkpackages ();
setupserver ();
setupdirectories ();
copyfiles ();
fixowners ();
writeetcconf ();
sub checkpackages {
my @requiredpackages = (
'IO::Socket::SSL',
'IO::Socket::INET',
);
my @missing;
foreach my $package (@requiredpackages) {
push (@missing, $package) if (!eval "use $package; 1;");
}
if (@missing) {
warn "Some necessary Perl packages are missing :\n\n";
foreach my $package (@missing) {
warn " $package\n";
}
warn "\nYou should install them before proceeding.\n";
exit unless (eval "use CPAN; 1;");
my $yorn = getentry ("Should I do it for you using CPAN (y/n)", 'y');
exit if ($yorn ne 'y');
foreach my $package (@missing) {
CPAN::install ($package);
}
my @stillmissing;
foreach my $package (@requiredpackages) {
push (@stillmissing, $package) if (!eval "use $package; 1;");
}
if (@stillmissing) {
warn "\nSorry, some necessary Perl packages are still missing :\n\n";
foreach my $package (@missing) {
warn " $package\n";
}
warn "\nYou should install them before proceeding.\n";
warn "If the installation of IO::Socket::SSL failed, maybe it is beacuse ",
"you don't have openssl-devel installed.\n";
exit;
}
}
}
sub setupdirectories {
my $root = getdir ('Root directory where to install everything ?', "/var/www");
die "$root is not writable, exiting..." unless -w $root;
my $cgibin = getdir ('cgi-bin directory', "$root/cgi-bin");
die "$cgibin is not writable, exiting..." unless -w $cgibin;
my $sesdir = getdir (
'Sessions directory (this directory must be readable '.
'and writable by apache user)', "$root/Tequila/Sessions"
);
$defaultsesdir = "$config->{root}/Tequila";
$config->{root} = $root;
$config->{cgibin} = $cgibin;
$config->{sesdir} = $sesdir;
}
sub setupserver {
my $localdomain = `hostname -d`; chomp $localdomain;
$localdomain ||= 'epfl.ch';
$defaultserver = 'tequila.' . $localdomain;
my $server = getentry ("Tequila server ?", $defaultserver);
$config->{server} = $server;
$defaultserverurl = 'https://' . $server . '/tequila';
my $serverurl = getentry ("Tequila server URL ?", $defaultserverurl);
$config->{serverurl} = $serverurl;
}
sub notdefault {
my ($attribute, $defaultvalue) = @_;
return if (
($config->{sesdir} eq $defaultsesdir) &&
($config->{server} eq $defaultserver) &&
($config->{serverurl} eq $defaultserverurl)
);
if ($> && $<) { # Not root.
print "You have choosen some attributes that do not the default value.\n",
"For your client to work properly you have to create a file /etc/tequila.conf \n",
"to store these values, since you are not root, I am unable to do this for you.\n",
"Either execute this script as root, use your the default value, or put this \n",
"in /etc/tequila.conf : \n\n";
if ($config->{sesdir} ne $defaultsesdir) {
print "SessionsDir: $config->{sesdir}\n";
}
if ($config->{server} ne $defaultserver) {
print "TequilaServer: $config->{server}\n";
}
if ($config->{serverurl} ne $defaultserverurl) {
print "TequilaServerUrl: $config->{serverurl}\n";
}
exit;
}
}
sub writeetcconf {
return if (
($config->{server} eq $defaultserver) &&
($config->{serverurl} eq $defaultserverurl) &&
($config->{sesdir} eq $defaultsesdir)
);
open (CONF, ">/etc/tequila.conf") || die "Unable to create /etc/tequila.conf : $!";
print CONF "TequilaServer: $config->{server}\n"
if ($config->{server} ne $defaultserver);
print CONF "TequilaServerUrl: $config->{serverurl}\n"
if ($config->{serverurl} ne $defaultserverurl);
print CONF "SessionsDir: $config->{sesdir}\n"
if ($config->{sesdir} ne $defaultsesdir);
close (CONF);
}
sub copyfiles {
unless (-d "$config->{sesdir}/") {
mkdir ("$config->{sesdir}/") || die "Unable to create Sessions directory : $!";
}
unless (-d "$config->{cgibin}/Tequila/") {
mkdir ("$config->{cgibin}/Tequila/") || die "Unable to create CGI Tequila directory : $!";
}
system ("cp clients/perl/Client.pm $config->{cgibin}/Tequila/");
}
sub fixowners {
if ($< && $>) {
warn "\nTake care that all files creates are readable by the user running",
" your http server!\n\n";
$config->{fixownersnotok} = 1;
return;
}
my $apache = getentry ("Which user httpd is running on", "apache");
my $groupe = getentry ("Which group httpd is running on", "apache");
system ("chown -R $apache:$groupe $config->{cgibin}/Tequila");
system ("chown -R $apache:$groupe $config->{sesdir}/");
}
sub getdir {
my ($msg, $default) = @_;
print "$msg "; print "[$default] " if $default; print ": ";
my $dir = <>; chomp $dir;
$dir = $default unless $dir;
unless (-d $dir) {
print "$dir does not exist, should I create it [y] ? ";
my $resp = <>;
chomp $resp;
exit if ($resp && ($resp ne 'y'));
mkdir ($dir) || die "Unable to create $dir : $!";
}
return $dir
}
sub getentry {
my ($msg, $default) = @_;
my $entry;
while (!$entry) {
print "$msg "; print "[$default] " if $default; print ": ";
$entry = <>; chomp $entry;
$entry = $default unless $entry;
}
return $entry
}
Event Timeline
Log In to Comment