#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $usage = "./canIinstallCGI \n"; my $cgi2install = shift or die($usage); my $dir2install = shift or die($usage); my $registry = "/usr/local/share/cwb/registry"; my $corporaDir = "/corpora"; createDir($registry); createDir($corporaDir); isCQPinstalled(); my $res = installCGI($cgi2install); print "*** CGI not installed ***\n\n" if ($res == 0); sub createDir { my $dir = shift; my $answer; if (-d $dir) { unless(-x $dir && -r $dir){`chmod o+r $dir`;} print "the directory $dir exists...\n\n"; } else { print "the directory $dir does not exists...\nDo you wish to create it? [yes|no] "; chomp($answer = ); if($answer =~ /y[.]*/) { `mkdir -p $dir`; `chmod a+rwx $dir`; print "$dir created...\n\n"; } } } sub isCQPinstalled { my $result = `echo \$PATH`; my @resultsArray = split /:/, $result; for my $result (@resultsArray) { if (-e "$result/cqp") { print "cqp is correctly installed...\n\n"; return; } } die "You have to install cqp...\n\n"; } sub installCGI { my $cgi = shift; my $answer; if(-e "$dir2install/$cgi") { print "A CGI with this name already exists...\nDo you wish to overwrite it? [yes|no] "; chomp($answer = ); if ($answer =~ /y[.]*/) { `rm $dir2install/$cgi`; `chmod +x $cgi`; `cp $cgi $dir2install`; print "CGI correclty installed...\n\n"; return 1; } else { print "Choose another name to your CGI file...\n\n"; return 1; } } else { `chmod +x $cgi`; `cp $cgi $dir2install`; print "CGI correclty installed...\n\n"; return 1; } return 0; } __END__ =head1 NAME canIinstallCGI - installs a CGI in a specific directory. =head1 SYNOPSIS canIinstallCGI =head1 DESCRIPTION Given a path of a CGI and a path of the directory where we want to install the CGI, it tests if all necessary software is correctly installed, and it also changes the permissions of the CGI file, giving the garantee that it can be executed by the server. During the execution, the script will tell us the steps that it could do and can't do, asking either to continue or not. =head1 AUTHOR J. Joao Almeida Alberto Simoes Joana Vilas Boas =head1 SEE ALSO perl(1). =cut