First version under CVS.

This commit is contained in:
Geert-Jan Giezeman 1998-07-03 12:50:28 +00:00
parent 9ffeffa17b
commit f227df578d
4 changed files with 1114 additions and 0 deletions

View File

@ -0,0 +1,93 @@
#! /net/bin/perl5 -T
use strict;
#--------------------------------------------------------------#
# This script scans through the mail box $::MAILBOX, using procmail.
# If a message contains a line with the format
#
# package: <URL>
#
# this package will be automatically downloaded, and the sender of
# the message will be notified.
#--------------------------------------------------------------#
# the amount of time between subsequent scans of the mailbox
#$::INCREMENT="30 minutes";
# the mail boxes
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
$::MAIL_IN='/users/geert/PUBLIC/CGAL-submit/incoming-mail';
#$::MAIL_OUT='/users/geert/tmp/handled-mail';
$::MAIL_TMP='/users/geert/PUBLIC/CGAL-submit/temp-mail';
$::SCRIPT='/projects/CGAL/submissions/autohandle/scripts/collect_submissions';
$::MAINTAINER='cgal-submit@cs.uu.nl';
# program locations
$::FORMAIL='/projects/CGAL/submissions/autohandle/scripts/formail';
$::treat_one_mail_program =
'/projects/CGAL/submissions/autohandle/scripts/treat_submit_mail';
$::LOCKCMD='/projects/CGAL/submissions/autohandle/scripts/lockfile';
# the log file
$::LOGFILE='/projects/CGAL/submissions/autohandle/data/collect_submissions.log';
#
$::seconds_between_invocations=600;
$::max_tries_between_warning= int 21600/$::seconds_between_invocations;
$ENV{PATH}='/sbin:/usr/sbin:/usr/bsd:/bin:/usr/bin';
$::please_die=0;
sub termination_signal_handler {
$::please_die=1;
}
$::tries = 1;
while (1) {
$SIG{INT} = \&termination_signal_handler;
$SIG{TERM} = \&termination_signal_handler;
if ( system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
--$::tries;
if ($::tries < 0) {
open NOTICE, "|Mail -s \"Collect_submissions locked!\" $::MAINTAINER";
print NOTICE <<"TOTHIER";
The script $::SCRIPT could not proceed because
it could not acquire the needed lock on file $::LOCKFILE.
TOTHIER
close NOTICE;
$::tries = $::max_tries_between_warning;
}
} else {
$::tries = $::max_tries_between_warning;
open LOGFILE, ">>$::LOGFILE";
print LOGFILE "$$: Executing script on ", `date`, "\n";
close LOGFILE;
if ( -f $::MAIL_TMP ) {
open NOTICE, "|Mail -s \"Mail box $::MAIL_TMP was not emptied!\" $::MAINTAINER";
print NOTICE <<"TOTHIER";
The script $::SCRIPT has been stopped!
TOTHIER
close NOTICE;
unlink $::LOCKFILE;
exit 1;
}
if ( -f $::MAIL_IN ) {
rename($::MAIL_IN, $::MAIL_TMP);
if (system("$::FORMAIL -ns $::treat_one_mail_program < $::MAIL_TMP")== 0 )
{
unlink $::MAIL_TMP;
}
}
unlink $::LOCKFILE;
}
$SIG{INT} = 'DEFAULT';
$SIG{TERM} = 'DEFAULT';
exit 1 if $::please_die;
sleep $::seconds_between_invocations;
}

View File

@ -0,0 +1,377 @@
#! /net/bin/perl5 -w
use strict;
use File::Find;
use Cwd;
# install_submission <sender> <url1> <url2> ...
$::TESTING=0;
umask 002;
if ($::TESTING) {
$::packagedir='/users/geert/tmp/inst_www/packages';
$::oldpackagedir='/users/geert/tmp/inst_www/old_packages';
$::download_dir='/users/geert/tmp/inst_www/download';
$::maintainer='geert@cs.uu.nl';
$::CONSOLE_OUTPUT=1;
} else {
$::packagedir='/users/www/CGAL/Members/Develop/updates/packages';
$::oldpackagedir='/users/www/CGAL/Members/Develop/updates/old_packages';
$::download_dir='/projects/CGAL/submissions/download';
$::maintainer='geert@cs.uu.nl';
$::CONSOLE_OUTPUT=0;
}
$ENV{PATH}=
'/net/bin:/net/unsupported/bin:/sbin:/usr/sbin:/usr/bsd:/bin:/usr/bin:/usr/bin/X11';
# logfile
$::ACTUAL_LOGFILE='install_www_submission.log';
# ----------------------------------------------------
# program for getting files via http/ftp
# GNU wget (see http://sunsite.auc.dk/ftp/pub/infosystems/wget/)
$::WGET="/users/wieger/local/bin/wget -Y off -nd -P $::download_dir";
# ----------------------------------------------------
# You probably don't need to change anything beyond
# ----------------------------------------------------
#
# write to logfile
#
sub log_header($)
{
if ( $::CONSOLE_OUTPUT ) {
print "$_[0] ...\n";
}
print LOGFILE "-------------------------------------------------------\n";
print LOGFILE " $_[0] ...\n";
printf LOGFILE "-------------------------------------------------------\n";
}
sub log_msg($)
{
if ( $::CONSOLE_OUTPUT ) {
print "$_[0] ...\n";
}
printf LOGFILE " $_[0] ...\n";
}
sub log_done()
{
if ( $::CONSOLE_OUTPUT ) {
print " done\n-------------------------------------------------------\n"
}
print LOGFILE "-------------------------------------------------------\n";
print LOGFILE " DONE\n";
print LOGFILE "-------------------------------------------------------\n";
}
sub print_usage()
{
print STDERR "usage: $0 <sender> <url1> \n";
}
#sub strip_version()
#{
# echo $* | $AWK '/^C2$/ { print; exit } \
# /^C3$/ { print; exit } \
# /^H2$/ { print; exit } \
# /^H3$/ { print; exit } \
# /^_2$/ { print; exit } \
# /^_3$/ { print; exit } \
# /^Convex_hull_3$/ { print; exit } \
# /^Opti.*doc.*/ { print "Optimisation_doc"; exit } \
# /^Opti.*imp.*/ { print "Optimisation_imp"; exit } \
# { gsub("([0-9]|\\.)+[a-zA-Z]?$", ""); print; exit }'
#}
sub make_package_name($)
{
$_ = $_[0];
# remove the directory path
s|.*/||;
# remove trailing blanks
s|\s*$||;
# remove suffixes
s|\.gz$||;
s|\.tar$||;
s|\.zip$||;
s|\.tgz$||;
# remove version
# s|([-\.\d]+)+[a-zA-Z]?$||;
# or should that be
s|([-\.]\d+)+[a-zA-Z]?$||;
return $_;
}
sub create_package_dir()
{
$::tempdir="$::packagedir/TMP$$";
mkdir($::tempdir, 0775) ;
}
sub unpack_package($)
{
my ($full_file_name);
$full_file_name = shift;
chdir $::tempdir;
if ( $full_file_name =~ /\.tar\s*$/) {
system 'tar', 'xf', "$full_file_name";
} elsif ($full_file_name =~ /\.zip\s*$/) {
system('unzip', '-oqq', "$full_file_name");
} elsif ($full_file_name =~ /\.tgz\s*$/ or $full_file_name =~ /\.tar.gz\s*$/) {
system("gunzip -c $full_file_name | tar xf -");
} else {
return 0;
}
return !$?;
}
sub gzip_if_psfile
{
if ($_ =~ /\.ps\s*/ and -f $_) {
system('gzip',"$_");
}
}
sub compress_psfiles()
{
if (-d 'doc_ps') {
find(\&gzip_if_psfile, "doc_ps");
}
}
sub get_version($)
{
open VERSION, $_[0] or return ();
while (<VERSION>) {
next if (/^\s*$/);
if ( /^\s*(\d+(?:[\.]\d+)*)\s*\((.*)\)\s*$/ ) {
close VERSION;
return ($1,$2);
}
close VERSION;
return ();
}
close VERSION;
return ();
}
sub check_version($)
{
my $package_name = shift;
my ($new_version_string, $new_date, $old_version_string, $old_date, @nversion, @oversion);
($new_version_string, $new_date) = get_version('version');
if (!defined($new_version_string)) {
log_msg "Failed to parse version file";
return 0;
}
($old_version_string, $old_date) =
get_version("$::packagedir/$package_name/version");
if (!defined($old_version_string)) {
log_msg "No previous version";
return 1;
}
my ($new_nr,$old_nr);
@nversion = split /\./, $new_version_string;
@oversion = split /\./, $old_version_string;
while (@nversion) {
$new_nr = shift @nversion;
$old_nr = shift @oversion;
$old_nr = 0 if !defined($old_nr);
if ($new_nr < $old_nr) {
log_msg "Version $new_version_string is not bigger than $old_version_string";
return 0;
}
if ($new_nr > $old_nr) {
return 1;
}
}
log_msg "Version $new_version_string is not bigger than $old_version_string";
return 0;
}
sub check_package($)
{
if ( ! -f 'version' ) {
log_msg "ERROR: File version is missing!";
return 0;
}
if (!check_version($_[0]) ) {
log_msg "ERROR: version file does not pass the checks!";
return 0;
}
if ( ! -f 'description.txt' ) {
log_msg "WARNING: File description.txt is missing!";
}
if ( ! -f 'changes.txt' ) {
log_msg "WARNING: File changes.txt is missing!";
}
# checks for correct headers, etc.
return 1;
}
sub compress_package($)
{
my $package_name = shift;
compress_psfiles;
system 'zip', '-q', '-r', $package_name, glob("*");
return !$?;
}
sub remove_files()
{
my ($file);
opendir THISDIR, "." or die;
foreach $file (readdir THISDIR) {
if (-d $file) {
next if $file eq '.';
next if $file eq '..';
system 'rm', '-rf', "$file";
} elsif (-f $file) {
next if $file =~ /\.zip$/;
next if $file eq 'doc_ps';
next if $file eq 'version';
next if $file eq 'description.txt';
next if $file eq 'long_description.txt';
next if $file eq 'changes.txt';
unlink $file;
}
}
closedir THISDIR;
}
sub move_packagedir($)
{
my $package_name = shift;
# first remove the earlier version (if it exists)
if ( -d "$::oldpackagedir/$package_name" ) {
# log_msg "removing directory $::oldpackagedir/$package_name"
system('rm', '-rf', "$::oldpackagedir/$package_name");
}
# move existing version to old packages
if ( -d "$::packagedir/$package_name" ) {
# log_msg "moving directory $::packagedir/$package_name to $::oldpackagedir/$package_name"
rename("$::packagedir/$package_name",
"$::oldpackagedir/$package_name") or die;
}
# log_msg "moving directory $::tempdir to $::packagedir/$package_name"
rename($::tempdir, "$::packagedir/$package_name") or die;
system 'chgrp', '-R', 'cgal', "$::packagedir/$package_name";
system 'chmod', '-R', 'ug+w', "$::packagedir/$package_name" ;
}
sub install_submission($)
{
my ($file_name, $file_pathname, $package_name);
$file_name = shift;
$file_pathname = "$::download_dir/$file_name";
$package_name = make_package_name($file_name);
if ($package_name !~ /^[a-zA-Z_]\w*$/) {
log_msg "Filename $file_name was turned into the illegal package name $package_name";
return 0;
}
chdir($::tempdir);
if (! unpack_package( $file_pathname) ) {
log_msg("Failed to unpack $file_pathname");
return 0;
}
if (!check_package($package_name)) {
return 0;
}
if (!compress_package($package_name)) {
log_msg "ERROR: Failed to compress $file_name";
return 0;
}
remove_files;
move_packagedir($package_name);
return 1;
}
sub do_submission($)
{
my ($url, $url_with_password,$FILE);
$url = shift;
$url_with_password = $url;
$url_with_password =~ s|http://|http://member1:cg4any1@|;
unlink glob("$::download_dir/*") if (! $::TESTING);
log_header "downloading $url";
system("$::WGET $url_with_password >> $::ACTUAL_LOGFILE 2>&1") if (! $::TESTING);
($FILE) = ($url =~ m|^.*/(.*?)\s*$|);
if ( ! -f "$::download_dir/$FILE" ) {
log_msg "ERROR: download failed!";
return 0;
}
if (install_submission("$FILE") ) {
log_header "Package was successfully installed!";
} else {
log_header "ERROR: Installation of the package failed!";
return 0;
}
return 1;
}
#-----------------------------------
#
# main loop
#
#-----------------------------------
$SIG{INT}='IGNORE';
$SIG{QUIT} = 'IGNORE';
$SIG{TERM} = 'IGNORE';
unlink $::ACTUAL_LOGFILE;
system("echo >$::ACTUAL_LOGFILE");
open LOGFILE, ">$::ACTUAL_LOGFILE";
if ($#ARGV < 1) {
print_usage;
exit 1;
}
$::SENDER=shift;
$::starting_directory = cwd();
foreach $::submission ( @ARGV) {
if (!create_package_dir) {
log_msg "Failed to create temporary directory";
exit 1;
}
do_submission($::submission);
chdir($::starting_directory);
if (-d "$::tempdir") {
system('rm', '-rf', "$::tempdir");
}
}
close LOGFILE;
system "cat $::ACTUAL_LOGFILE | Mail -s \"CGAL submissions @ARGV\" $::maintainer" if !$::TESTING;
system "cat $::ACTUAL_LOGFILE | Mail -s \"CGAL submission @ARGV\" $::SENDER";
unlink $::ACTUAL_LOGFILE;
exit 0;

View File

@ -0,0 +1,227 @@
#!/net/bin/perl5 -w
use strict;
$::treated_messages_log =
'/projects/CGAL/submissions/autohandle/data/treated_submit_messages';
$::install_submission_program =
# '/projects/CGAL/submissions/install_www_submission';
'/projects/CGAL/submissions/autohandle/scripts/install_www_submission';
$::receive_testresult_program =
'/users/geert/tmp/echo_to_log';
$::update_submissions_www_page_program =
'/projects/CGAL/submissions/create_update_page';
$::maintainer= 'geert@cs.uu.nl';
$::no_of_succesful_submissions = 0;
@::trusted_hosts = ('cs.uu.nl','inria.fr','risc.uni-linz.ac.at',
'inf.ethz.ch','mpi-sb.mpg.de','inf.fu-berlin.de','math.tau.ac.il');
sub get_url()
{
my $html_address="";
while (<>) {
chomp;
if (/^\s*$/) {
return $html_address;
}
s/\s//g;
$html_address .= $_;
if ($html_address =~ /\.tar\.gz$/) {
return $html_address;
}
if ($html_address =~ /\.tgz$/) {
return $html_address;
}
if ($html_address =~ /\.zip$/) {
return $html_address;
}
}
return "";
}
sub is_trusted_url($)
{
my $URL = shift;
foreach (@::trusted_hosts) {
if ($URL =~ m|^\s*http://www.$_/|) {
return 1;
}
}
return 0;
}
sub is_trusted_sender($)
{
my $sender = shift;
foreach (@::trusted_hosts) {
if ($sender =~ m|$_\s*$|) {
return 1;
}
}
return 0;
}
sub is_trusted_url_1($)
{
my $URL = shift;
if ($URL =~ m|^\s*http://www.cs.uu.nl/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.inria.fr/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.risc.uni-linz.ac.at/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.inf.ethz.ch/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.mpi-sb.mpg.de/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.inf.fu-berlin.de/|) {
return 1;
}
elsif ($URL =~ m|^\s*http://www.math.tau.ac.il/|) {
return 1;
}
return 0;
}
sub treat_submission($)
{
my ($URL,$option);
$option = shift;
$URL = get_url;
if ($URL eq "") {
# mail $::Sender that something went wrong.
# do the same to maintainer.
open NOTICE, "|Mail -s \"CGAL autohandle failure!\" $::Sender";
print NOTICE <<"TOTHIER";
Your submission (or one of your submissions) had an unrecognized URL.
The URL should be on a separate line, directly following the line
with the submission keyword, e.g as in:
submission::
http://www.mysite.mycountry/mypackage.zip
Please resend your request or send a message to cgal-submit asking for more
information.
TOTHIER
close NOTICE;
return;
}
if (! is_trusted_url($URL)) {
open NOTICE, "|Mail -s \"Untrusted URL!\" $::maintainer";
print NOTICE <<"TOTHIER";
The submission with URL
$URL
is not trusted and did not proceed.
Please take manual action.
TOTHIER
close NOTICE;
return;
}
if (system("$::install_submission_program", "$::Sender", "$URL") == 0)
{ ++$::no_of_succesful_submissions; }
}
sub treat_testresult($)
{
my ($URL,$release);
$release = shift;
$URL = get_url;
if (!$URL) {
# mail $::Sender that something went wrong.
# do the same to maintainer.
return;
}
if (! is_trusted_url($URL)) {
open NOTICE, "|Mail -s \"Untrusted URL!\" $::maintainer";
print NOTICE <<"TOTHIER";
The Testresult with URL
$URL
is not trusted and did not proceed.
Please take manual action.
TOTHIER
close NOTICE;
return;
}
system("$::receive_testresult_program", "$release", "$::Sender", "$URL");
}
sub message_processed($)
{
my $message_id = shift;
open(TREATED_MESSAGES, "<$::treated_messages_log");
while (<TREATED_MESSAGES>) {
chomp;
if ($message_id eq $_) {
close TREATED_MESSAGES;
return 1;
}
}
close TREATED_MESSAGES;
open(TREATED_MESSAGES, ">>$::treated_messages_log");
print TREATED_MESSAGES "$message_id\n";
close TREATED_MESSAGES;
return 0;
}
sub main()
{
my ($from);
$_ = <>;
chomp;
($from, $::Sender) = split;
if ($from ne "From") {
exit 1;
}
$::Sender =~ s/\s*//g;
if (!is_trusted_sender($::Sender)) {
open NOTICE, "|Mail -s \"Untrusted sender!\" $::maintainer";
print NOTICE <<"TOTHIER";
The submission with sender
$::Sender
is not trusted and did not proceed.
-------------- start of message --------------
TOTHIER
while(<>) {
print NOTICE $_;
}
print NOTICE "-------------- end of message --------------\n";
close NOTICE;
exit 1;
}
while(<>) {
if (/^\s*Message-ID\s*:\s*(.*?)\s*$/) {
last if message_processed($1);
}
elsif (/^\s*submission\s*:\s*([^:]*?)\s*:\s*$/) {
treat_submission($1);
}
elsif (/^\s*testresult\s*:\s*([^:]*?)\s*:\s*$/){
treat_testresult($1);
}
}
if ($::no_of_succesful_submissions > 0) {
system($::update_submissions_www_page_program);
}
}
# don't break off processing of a message
$SIG{INT}='IGNORE';
$SIG{QUIT} = 'IGNORE';
$SIG{TERM} = 'IGNORE';
main;
exit 0;

View File

@ -0,0 +1,417 @@
#!/net/bin/perl5 -w
use strict;
use Cwd;
use File::Copy;
use File::Basename;
use File::Find;
#
# This script creates an internal release for CGAL.
#----------------------------------------------------------------#
# initialization #
#----------------------------------------------------------------#
$::CURRENT_DIR=cwd();
#$::FTPDIR='/users/ftp/CGAL';
#$::DIRNAME=dirname($0);
$::TEMPFILE="TEMPFILE.$$";
$::PACKAGEDIR='/users/www/CGAL/Members/Develop/updates/packages';
$::MISCPACKAGEDIR='/users/www/CGAL/Members/Develop/updates/packages';
$::SCRIPTDIR='/users/www/CGAL/Members/Develop/scripts';
$::ALL_RESULTS_DIR='/users/www/CGAL/Members/Develop/testsuite';
#$::VERSION="";
#$::VERSION_NR=0;
#$::PACKAGEDIR='/users/geert/CGAL/tmp/packages';
#$::ALL_RESULTS_DIR='/users/geert/CGAL/tmp/results';
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
$::LOCKCMD='/projects/CGAL/submissions/autohandle/scripts/lockfile';
$::last_version_file = '/projects/CGAL/lib/last_internal_release';
#----------------------------------------------------------------#
# unzip_files #
#----------------------------------------------------------------#
#
# unzip_files <zipfile> <directories>
#
sub unzip_files($@)
{
my $package = shift;
my ($ITEM, @zip_contents,@to_unzip,$zipped_file);
@zip_contents = `unzip -l $package`;
shift @zip_contents;
shift @zip_contents;
pop @zip_contents;
pop @zip_contents;
foreach $ITEM (@_) {
foreach $zipped_file (@zip_contents) {
if ( $zipped_file =~ m|(\b$ITEM.*\b)| ) {
push(@to_unzip,($1));
}
}
}
system('unzip', '-qq', $package, @to_unzip);
}
#----------------------------------------------------------------#
# get_file_type #
#----------------------------------------------------------------#
sub get_file_type($)
{
open SOURCE_FILE, shift;
while ( <SOURCE_FILE> ) {
if ( /^Copyright \(c\) 1997|8 The CGAL Consortium/ ) {
return 1;
}
if ( /^\/\/ Copyright \(c\) 1997|8 The CGAL Consortium/ ) {
return 2;
}
}
return 0;
}
#----------------------------------------------------------------#
# set_filename #
#----------------------------------------------------------------#
sub set_filename($$)
{
my $filename = shift;
my $filename_with_dir = shift;
unlink $::TEMPFILE;
open SOURCE_FILE, "<$filename" || die "Error opening $filename_with_dir: $!\n";
open TEMPFILE, ">$::TEMPFILE" || die;
while ( <SOURCE_FILE> ) {
s|^\s*//\s*file\s*:.*|// file : $filename_with_dir|;
print TEMPFILE $_;
}
close SOURCE_FILE || die "Error closing $filename_with_dir: $!";
close TEMPFILE || die "Error closing temporary file: $!\n";
rename($::TEMPFILE, $filename )
|| system('mv', "$::TEMPFILE", "$filename")
|| warn "Could not update file $filename_with_dir\n";
}
#----------------------------------------------------------------#
# set_file_headers #
#----------------------------------------------------------------#
#
# replace the old style headers with new ones
#
#sub set_header($)
#{
# my $filename = shift;
# unlink $::TEMPFILE
# awk -f ../$DIRNAME/set_header.awk $FILE > $TEMPFILE
# rename $::TEMPFILE, $FILE
#}
sub set_file_headers()
{
chdir $::CURRENT_DIR;
find(\&file_header_setting, 'include', 'src',
glob("config/testfiles/CGAL_CFG*"));
}
sub file_header_setting
{
my ($filename,$dev,$ino,$mode,$nlink,$uid,$gid,$filetype);
$filename = $_;
if ( ! /\.[h|C]$/ ||
! (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($filename)) ||
! -f _ ) {
return;
}
$filetype = get_file_type($filename);
if ($filetype == 0)
{warn "$filename has unrecognized header.\n"; }
elsif ($filetype == 0)
{ warn "$filename has old style header.\n"; }
else {
set_filename($filename, $File::Find::name);
system("$::SCRIPTDIR/create_internal_release_file2 $filename $::VERSION");
}
}
#---------------------------------------------------------------#
# set the headers
#---------------------------------------------------------------#
sub SetFileHeaders()
{
print "Setting file headers...\n";
chdir $::CURRENT_DIR;
set_file_headers;
unlink(glob("include/CGAL/*.bak"));
unlink (glob("include/CGAL/*/*.bak"));
unlink (glob("src/*.bak"));
unlink (glob("config/testfiles/*.bak"));
}
#---------------------------------------------------------------#
# set the version information in the config.h include file.
#---------------------------------------------------------------#
sub set_version_in_config()
{
my $V = substr($::VERSION,5);
chdir "$::CURRENT_DIR/include/CGAL" or die;
open(SOURCE_FILE, '<config.h') or die "Error opening config.h: $!";
open(TEMPFILE, ">$::TEMPFILE") or die;
while ( <SOURCE_FILE> ) {
s|^\s*\#\s*define\s+CGAL_VERSION\b.*$|#define CGAL_VERSION $V|;
s|^\s*\#\s*define\s*CGAL_VERSION_NR\b.*$|#define CGAL_VERSION_NR $::VERSION_NR|;
print TEMPFILE $_;
}
close SOURCE_FILE || die "Error closing config.h_with_dir: $!";
close TEMPFILE || die "Error closing temporary file: $!\n";
rename($::TEMPFILE, 'config.h' )
|| system('mv', "$::TEMPFILE", 'config.h')
|| warn "Could not update file config.h";
chdir '../..' or die;
}
#---------------------------------------------------------------#
# CreateExampleTestDirs
#---------------------------------------------------------------#
sub CreateExampleTestDirs()
{
my $DIR;
print "Creating example test directories ...\n";
chdir 'examples' or return;
foreach $DIR (glob("*")) {
print "$DIR\n";
if ( -d $DIR ) {
system('cp', '-r', "$DIR", "../test/Examples$DIR");
# mkdir("$::THIS_RELEASE_RESULTS/Examples$DIR", 0775);
# if ( -f 'version' ) {
# copy('version', $::THIS_RELEASE_RESULTS/Examples$DIR);
# }
}
}
chdir '..';
}
#---------------------------------------------------------------#
# list_test_directories
#---------------------------------------------------------------#
# list_test_directories <package>
#
# drukt de testdirectories af die in de submission aanwezig zijn
sub list_test_directories($)
{
my $filename = shift;
my (@zip_contents,$zipped_file,%test_dirs);
@zip_contents = `unzip -l $filename`;
shift @zip_contents;
shift @zip_contents;
pop @zip_contents;
pop @zip_contents;
foreach $zipped_file (@zip_contents) {
if ( $zipped_file =~ m|\btest/([^/\n]+)| ) {
$test_dirs{$1} = 1;
}
}
return keys %test_dirs;
}
#---------------------------------------------------------------#
# install_packages
#---------------------------------------------------------------#
# install_packages
sub install_packages()
{
my ($filenaam, $direc);
@_ = glob("$::PACKAGEDIR/*/*.zip");
#really should use readdir and exlude certain directories that are marked as
#such.
print "Installing packages ...\n";
foreach $filenaam (@_) {
print "$filenaam\n";
unzip_files("$filenaam", "include", "test", "examples", "demo", "src", "version","doc_tex");
foreach $direc ( list_test_directories($filenaam)) {
if ( -f 'version' && -d "test/$direc" && ! -f "test/$direc/version") {
copy('version', "test/$direc");
# mkdir("$::THIS_RELEASE_RESULTS/$direc", 0775);
# copy('version', "$::THIS_RELEASE_RESULTS/$direc");
}
if ( -f 'version' && -d "examples/$direc"
&& ! -f "examples/$direc/version") {
copy('version', "examples/$direc");
}
}
unlink 'version';
}
}
#---------------------------------------------------------------#
# install_misc
#---------------------------------------------------------------#
sub install_misc()
{
system 'unzip', '-o', "$::MISCPACKAGEDIR/Auxiliary/Auxiliary.zip";
system 'unzip', '-o', "$::MISCPACKAGEDIR/Configuration/Configuration.zip";
system 'unzip', '-o', "$::MISCPACKAGEDIR/Installation/Installation.zip";
system 'unzip', '-o', "$::MISCPACKAGEDIR/Scripts/Scripts.zip";
unlink 'version', 'description.txt', 'long_description.txt', 'changes.txt';
}
#---------------------------------------------------------------#
# make_testscripts
#---------------------------------------------------------------#
sub make_testscripts()
{
my ($DIR, $BASEDIR);
$BASEDIR = cwd();
print "In make_testscripts\n";
chdir 'test';
foreach $DIR (glob("*")) {
if ( -d $DIR ) {
print "checking makefile and cgal_test in $DIR\n";
chdir $DIR;
if ( ! -f 'makefile' ) {
print "creating makefile ...\n";
system("$::SCRIPTDIR/create_makefile", '-t');
}
if ( ! -f 'cgal_test' ) {
print "creating cgal_test ...\n";
system("$::SCRIPTDIR/create_cgal_test");
}
chdir '..';
}
}
chdir $BASEDIR;
}
#---------------------------------------------------------------#
# make_results_page
# Create a directory (with subdirectories) where the results are to be put.
# Copy the version files of the packages used for this release to
# the result directories.
#---------------------------------------------------------------#
sub make_results_page()
{
my $direc;
$::THIS_RELEASE_RESULTS = "$::ALL_RESULTS_DIR/$::VERSION";
mkdir "$::THIS_RELEASE_RESULTS", 0775
|| die "Cannot create test results directory";
chdir ("$::CURRENT_DIR/test") or return;
foreach $direc (glob("*")) {
if ( -d "$direc" && -f "$direc/version" ) {
mkdir("$::THIS_RELEASE_RESULTS/$direc", 0775);
copy("$direc/version", "$::THIS_RELEASE_RESULTS/$direc")
or warn "Could not copy test/$direc/version to $::THIS_RELEASE_RESULTS/$direc $!";
}
}
}
#---------------------------------------------------------------#
# check_call
#
# checks if this program is called with the right arguments,
# in particular if the version number is high enough.
#---------------------------------------------------------------#
sub wrong_usage()
{
print STDERR "usage: $0 <version-no>\n";
print STDERR " where version-no is <major>-<minor>-<internal>\n";
print STDERR " E.g.: $0 2-3-12\n";
}
sub check_call()
{
my ($major, $minor, $internal);
if ($#ARGV !=0) {
wrong_usage();
exit(1);
}
if ( ($major, $minor, $internal) =
($ARGV[0] =~ m/^(\d{1,3})-(\d{1,3})-(\d{1,2})$/)) {
$major = $major + 0;
$minor = $minor + 0;
$internal = $internal + 0;
$::VERSION_NR = ((1000 + $major)*1000 + $minor)*1000 + $internal;
$::VERSION = "CGAL-$major.$minor-I-$internal";
} else {
wrong_usage();
die "Illegal version number $ARGV[0]";
}
print "Version: $::VERSION ($::VERSION_NR)\n";
open VERSION, $::last_version_file or return;
$_ = <VERSION>;
defined($_) or die "corrupted file $::last_version_file";
close VERSION;
/\s*(\d+)\s*(\d+)\s*(\d+)\s*$/ or die "corrupted file $::last_version_file";
die "major version number too low" if ( $major < $1);
if ($major == $1) {
die "minor version number too low" if ( $minor < $2);
if ($minor == $2) {
die "internal version number too low" if ( $internal <= $3);
}
}
open VERSION, ">$::last_version_file" or die;
print VERSION "$major $minor $internal\n" or die;
close VERSION or die;
}
sub termination_signal_handler {
unlink $::LOCKFILE;
exit 1;
}
sub lock()
{
if (system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
print STDERR <<"TOTHIER";
The script could not proceed because
it could not acquire the needed lock on file $::LOCKFILE.
TOTHIER
exit 1;
}
$SIG{INT} = \&termination_signal_handler;
$SIG{TERM} = \&termination_signal_handler;
}
sub unlock()
{
unlink $::LOCKFILE;
$SIG{INT} = 'DEFAULT';
$SIG{TERM} = 'DEFAULT';
}
umask(002);
if ($::CURRENT_DIR ne '/private') {
die "$0 should only be called from directory /private on goya.\n";
}
check_call;
mkdir "$::VERSION",0775 or die;
chdir $::VERSION or die;
$::CURRENT_DIR=cwd();
lock;
install_packages();
install_misc;
unlock;
CreateExampleTestDirs;
make_testscripts;
SetFileHeaders;
set_version_in_config;
make_results_page;