mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
2d8e40ef8e
a missing space) - Define the subject of the failure mail reports within the calling script instead of logger.pm Build-tools/Bootstrap: - Define the subject for the failure mail within the Build script Build-tools/Do-rpm: - Define the subject of the failure email within the build script - Added missing space to make moving of the resulting packages working Build-tools/logger.pm: - Define the subject for the failure mail within the calling script instead of here
105 lines
1.9 KiB
Perl
105 lines
1.9 KiB
Perl
# Helper functions
|
|
|
|
#
|
|
# Create a log entry
|
|
#
|
|
sub logger
|
|
{
|
|
my $message=$_[0];
|
|
print timestamp() . " " . $message . "\n" if $opt_verbose;
|
|
if (defined $opt_log && !$opt_dry_run)
|
|
{
|
|
open LOG, ">>$LOGFILE" or die "Can't open logfile $LOGFILE!";
|
|
print LOG timestamp() . " " . $message . "\n";
|
|
close LOG;
|
|
}
|
|
}
|
|
|
|
#
|
|
# run_command(<command>,<error message>)
|
|
# Execute the given command or die with the respective error message
|
|
# Just print out the command when doing a dry run
|
|
#
|
|
sub run_command
|
|
{
|
|
my $command= $_[0];
|
|
my $errormsg= $_[1];
|
|
if ($opt_dry_run)
|
|
{
|
|
print "$command\n";
|
|
}
|
|
else
|
|
{
|
|
&logger($command);
|
|
$command.= " >> $LOGFILE 2>&1" if defined $opt_log;
|
|
$command.= " > /dev/null" if (!$opt_verbose && !$opt_log);
|
|
system($command) == 0 or &abort("$errormsg\n");
|
|
}
|
|
}
|
|
|
|
#
|
|
# abort(<message>)
|
|
# Exit with giving out the given error message or by sending
|
|
# it via email to the given mail address (including a log file snippet,
|
|
# if available)
|
|
#
|
|
sub abort
|
|
{
|
|
my $message= $_[0];
|
|
my $messagefile;
|
|
$message= "ERROR: " . $message;
|
|
&logger($message);
|
|
|
|
if ($opt_mail && !$opt_dry_run)
|
|
{
|
|
$messagefile= "/tmp/message.$$";
|
|
open(TMP,">$messagefile");
|
|
print TMP "$message\n\n";
|
|
close TMP;
|
|
if (defined $opt_log)
|
|
{
|
|
system("tail -n 40 $LOGFILE >> $messagefile");
|
|
}
|
|
system("mail -s \"$subject\" $opt_mail < $messagefile");
|
|
unlink($messagefile);
|
|
}
|
|
|
|
exit 1;
|
|
}
|
|
|
|
# Create a time stamp for logging purposes
|
|
sub timestamp
|
|
{
|
|
return &ymd() . " " . &hms();
|
|
}
|
|
|
|
#
|
|
# return the current time as a string (HH:MM:SS)
|
|
#
|
|
sub hms
|
|
{
|
|
my @ta= localtime(time());
|
|
my $h= $ta[2];
|
|
$h= "0" . "$h" if ($h <= 9);
|
|
my $m= $ta[1];
|
|
$m= "0" . "$m" if ($m <= 9);
|
|
my $s= $ta[0];
|
|
$s="0" . "$s" if ($s <= 9);
|
|
|
|
return "$h:$m:$s";
|
|
}
|
|
|
|
#
|
|
# return the current date as a string (YYYYMMDD)
|
|
#
|
|
sub ymd
|
|
{
|
|
my @ta=localtime(time());
|
|
my $d=$ta[3];
|
|
$d="0" . "$d" if ($d <= 9);
|
|
my $m=$ta[4]+1;
|
|
$m="0" . "$m" if ($m <= 9);
|
|
my $y=1900+$ta[5];
|
|
|
|
return "$y$m$d";
|
|
}
|