Commit 3c2f6dbb authored by unknown's avatar unknown

- Heavily reworked the Do-pkg script to use functions from logger.pm

 - moved helper functions from Bootstrap script to logger.pm 


Build-tools/Bootstrap:
   - renamed logfile -> LOGFILE
   - moved functions abort() and run_command() to logger.pm for better
     reusability
Build-tools/Do-pkg:
   - heavily reworked: now make use of the logger.pm helper functions
   - added new options: --dry-run, --log, --mail, --verbose
Build-tools/logger.pm:
   - added functions run_command() and abort() from Bootstrap script for
     better code reusability
support-files/MacOSX/postinstall.sh:
   - made script more robust
parent ed3ff3bd
......@@ -13,7 +13,7 @@
use Getopt::Long;
Getopt::Long::Configure ("bundling");
# Include logging function
# Include helper functions
$LOGGER= "$ENV{HOME}/bin/logger.pm";
if (-f $LOGGER)
{
......@@ -26,8 +26,8 @@ else
# Some predefined settings
$build_command= "BUILD/compile-pentium-max";
chomp ($logfile= `pwd`);
$logfile.= "/Bootstrap.log";
chomp ($LOGFILE= `pwd`);
$LOGFILE.= "/Bootstrap.log";
chomp ($opt_directory= `pwd`);
$opt_docdir= $opt_directory . "/mysqldoc";
$opt_changelog= undef;
......@@ -71,12 +71,12 @@ if (defined $opt_log)
{
if ($opt_log =~ /^\/.*/)
{
$logfile= $opt_log;
$LOGFILE= $opt_log;
}
else
{
chomp ($logfile= `pwd`);
$logfile.= "/" . $opt_log;
chomp ($LOGFILE= `pwd`);
$LOGFILE.= "/" . $opt_log;
}
}
}
......@@ -95,7 +95,7 @@ if (($opt_directory ne ".") && (!-d $opt_directory && !$opt_dry_run))
&abort("Could not find target directory \"$opt_directory\"!");
}
&logger("Logging to $logfile") if (defined $opt_log);
&logger("Logging to $LOGFILE") if (defined $opt_log);
#
# Use a temporary name until we know the version number
......@@ -306,61 +306,6 @@ if (!$opt_skip_check)
&logger("SUCCESS: Build finished successfully.") if (!$opt_dry_run);
exit 0;
# Helper functions
#
# 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.$$";
$subject= "Bootstrap of $REPO failed";
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;
}
#
# Print the help text message (with an optional message on top)
#
......@@ -400,7 +345,7 @@ Options:
do not build or test the source distribution
-h, --help Print this help message
-l, --log[=<filename>] Write a log file [to <filename>]
(default is "$logfile")
(default is "$LOGFILE")
-m, --mail=<address> Mail a failure report to the given address (and
include a log file snippet, if logging is enabled)
Note that the \@-Sign needs to be quoted!
......
......@@ -9,125 +9,176 @@
#
use Getopt::Long;
Getopt::Long::Configure ("bundling");
$opt_dry_run= undef;
$opt_help= undef;
$opt_log= undef;
$opt_mail= "";
$opt_suffix= undef;
$opt_verbose= undef;
$opt_version= undef;
GetOptions(
"dry-run",
"help|h",
"log|l:s",
"mail|m=s",
"suffix=s",
"verbose|v",
"version=s",
) || &print_help;
&print_help if ($opt_help || !$opt_suffix || !$opt_version);
# Include helper functions
chomp($PWD= `pwd`);
$LOGGER= "$PWD/logger.pm";
if (-f $LOGGER)
{
do "$LOGGER";
}
else
{
die "ERROR: $LOGGER cannot be found!\n";
}
$PM= "/Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker";
$HOME= $ENV{HOME};
$TMP= "/tmp/PKGBUILD";
$PKGROOT= "$TMP/PMROOT";
$PKGDEST= "$TMP/PKG";
$RESOURCE_DIR= "$TMP/Resources";
$SUFFIX= $opt_suffix;
$VERSION= $opt_version;
($MAJOR, $MINOR, $RELEASE)= split(/\./, $VERSION);
$NAME= "mysql$SUFFIX-$VERSION";
chomp($HOST= `hostname`);
chomp($ID= `whoami`);
$HOST=~ /^([^.-]*)/;
$HOST= $1;
$BUILDDIR= "$HOME/$HOST";
$LOGFILE= "$PWD/Logs/$HOST-$MAJOR.$MINOR$SUFFIX.log";
$BUILDDIR= "$PWD/$HOST";
$SUPFILEDIR= <$BUILDDIR/mysql*-$VERSION/support-files/MacOSX>;
$TAR= <$BUILDDIR/$NAME-apple-darwin*-powerpc.tar.gz>;
$INFO= <$SUPFILEDIR/Info.plist>;
$DESC= <$SUPFILEDIR/Description.plist>;
@RESOURCES= qw/ ReadMe.txt postinstall preinstall /;
print "TAR: $TAR\nINFO: $INFO\nDESC: $DESC\n";
&print_help("") if ($opt_help || !$opt_suffix || !$opt_version);
#
# Override predefined Log file name
#
if (defined $opt_log)
{
if ($opt_log ne "")
{
if ($opt_log =~ /^\/.*/)
{
$LOGFILE= $opt_log;
}
else
{
$LOGFILE= $PWD . "/" . $opt_log;
}
}
}
# Creating the UFS disk image requires root privileges
chomp($ID= `whoami`);
die "You must be root to run this script!\nUse \"sudo\" or become root first.\n" if ($ID ne "root");
die("You must be root to run this script!") if ($ID ne "root" && !$opt_dry_run);
foreach $file ($TAR, $INFO, $DESC)
{
die "Unable to find $file!\n" if (!-f $file);
&abort("Unable to find $file!") if (!-f $file);
}
# Remove old temporary build directories first
system ("rm -rf $TMP");
print "Creating temp directories\n";
&logger("Cleaning up temporary build directories");
&run_command("rm -rf $TMP", "Could not clean up $TMP!");
&logger("Creating temp directories");
foreach $dir ($TMP, $PKGROOT, $PKGDEST, $RESOURCE_DIR)
{
if (!-d $dir)
{
mkdir $dir;
&run_command("mkdir $dir", "Could not make directory $dir!");
}
}
foreach $resfile (@RESOURCES)
{
system ("cp $SUPFILEDIR/$resfile $RESOURCE_DIR") == 0 or die "Error while copying $SUPFILEDIR/$resfile to $RESOURCE_DIR: ?!";
$command= "cp $SUPFILEDIR/$resfile $RESOURCE_DIR";
&run_command($command, "Error while copying $SUPFILEDIR/$resfile to $RESOURCE_DIR");
}
# Extract the binary tarball and create the "mysql" symlink
print "Extracting $TAR to $PKGROOT\n";
system("gnutar zxf $TAR -C $PKGROOT") if (-f $TAR);
system("cd $PKGROOT ; ln -s mysql* ./mysql");
system("chown -R root.wheel $PKGROOT/*");
&logger("Extracting $TAR to $PKGROOT");
&run_command("gnutar zxf $TAR -C $PKGROOT", "Unable to extract $TAR!");
&run_command("cd $PKGROOT ; ln -s mysql* ./mysql", "Unable to create symlink!");
&run_command("chown -R root.wheel $PKGROOT/*", "Cannot chown $PKGROOT!");
# Now build the PGK using PackageMaker
print "Running PackageMaker\n";
system("$PM -build -p $PKGDEST/$NAME.pkg -f $PKGROOT -r $RESOURCE_DIR -i $INFO -d $DESC") or die "Error while building package: $!\n";
# The "|| true" is a nasty hack to work around a problem with Package Maker
# returning a non-zero value, even though the package was created correctly
&logger("Running PackageMaker");
$command= "$PM -build -p $PKGDEST/$NAME.pkg -f $PKGROOT -r $RESOURCE_DIR -i $INFO -d $DESC || true";
&run_command($command, "Error while building package!");
print "Removing $PKGROOT\n";
system("rm -rf $PKGROOT");
&logger("Removing $PKGROOT");
&run_command("rm -rf $PKGROOT", "Unable to remove $PKGROOT!");
# Determine the size of the Disk image to be created and add a 5% safety
# margin for filesystem overhead
print "Determining required disk image size for $PKGDEST: ";
chomp($_= `du -sk $PKGDEST`);
@size= split();
$size= int($size[0]+($size[0]*0.05));
print "$size KB\n";
&logger("Determining required disk image size for $PKGDEST");
if (! $opt_dry_run)
{
chomp($_= `du -sk $PKGDEST`);
@size= split();
$size= int($size[0]+($size[0]*0.05));
&logger("Disk image size: $size KB");
}
die "Zero bytes? Something is wrong here!\n" if ($size == 0);
&abort("Zero bytes? Something is wrong here!") if ($size == 0);
# Now create and mount the disk image
$TMPNAME= $NAME . ".tmp";
print "Creating temporary Disk image $TMPNAME\n";
system("hdiutil create $TMPNAME -size ${size}k -ov -fs UFS -volname $NAME");
print "Result: $!\n";
print "Attaching Disk image $TMPNAME.dmg\n";
system("hdid $TMPNAME.dmg");
print "Result: $!\n";
&logger("Creating temporary Disk image $TMPNAME.dmg");
$command= "hdiutil create $TMPNAME -size ${size}k -ov -fs UFS -volname $NAME";
&run_command($command, "Unable to create disk image $TMPNAME.dmg!");
&logger("Attaching Disk image $TMPNAME.dmg");
&run_command("hdid $TMPNAME.dmg", "Unable to attach $TMPNAME.dmg!");
# Install the PKG into the .dmg
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f3 -d" "`);
print "Copying $PKGDEST/$NAME.pkg to Disk image /Volumes/$NAME\n";
system("ditto $PKGDEST /Volumes/$NAME");
system("ditto $RESOURCE_DIR/ReadMe.txt /Volumes/$NAME");
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f1 -d" "`);
die "/Volumes/$NAME not attached!\n" if (!$mountpoint);
print "Unmounting $mountpoint\n";
system("hdiutil detach $mountpoint");
print "Result: $!\n";
unlink ("$NAME.dmg") if (-f "$NAME.dmg");
print "Compressing disk image\n";
system("hdiutil convert $TMPNAME.dmg -format UDZO -imagekey zlib-level=9 -o $NAME.dmg");
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f3 -d" "`) if (!$opt_dry_run);
&logger("Copying $PKGDEST/$NAME.pkg to Disk image /Volumes/$NAME");
&run_command("ditto $PKGDEST /Volumes/$NAME", "Could not copy $PKGDEST to /Volumes/$NAME!");
&run_command("ditto $RESOURCE_DIR/ReadMe.txt /Volumes/$NAME", "Could not copy $RESOURCE_DIR/ReadMe.txt to /Volumes/$NAME!");
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f1 -d" "`) if (!$opt_dry_run);
&abort("/Volumes/$NAME not attached!") if (!$mountpoint && !$opt_dry_run);
&logger("Unmounting $mountpoint");
&run_command("hdiutil detach $mountpoint", "Unable to detach $mountpoint");
&run_command("rm -f $NAME.dmg", "Unable to remove $NAME.dmg!") if (-f "$NAME.dmg");
&logger("Compressing disk image");
$command= "hdiutil convert $TMPNAME.dmg -format UDZO -imagekey zlib-level=9 -o $NAME.dmg";
&run_command($command, "Unable to compress disk image!");
# Final cleanups
print "Removing $TMPNAME.dmg\n";
unlink ("$TMPNAME.dmg");
print "Removing $TMP\n";
system("rm -rf $TMP");
&logger("Removing $TMPNAME.dmg");
&run_command("rm -f $TMPNAME.dmg", "Unable to remove $TMPNAME.dmg!");
&logger("Removing $TMP");
&run_command("rm -rf $TMP", "Unable to remove $TMP!");
print "$NAME.dmg created.\n";
&logger("SUCCESS: $NAME.dmg created.") if (!$opt_dry_run);
exit 0;
sub print_help
{
my $message= $_[0];
if ($message ne "")
{
print "\n";
print "ERROR: $message\n";
}
print <<EOF;
Usage: Do-pkg --suffix=<suffix> --version=<version>
Usage: Do-pkg <options> --suffix=<suffix> --version=<version>
Creates a Mac OS X installation package (PKG) and stores it inside
a Disk Image (.dmg) file. You need to create a binary distribution
......@@ -138,9 +189,18 @@ NOTE: You need to run this script with root privileges (required
Options:
--dry-run Dry run without executing
-h, --help Print this help
-l, --log[=<filename>] Write a log file [to <filename>]
(default is "$LOGFILE")
-m, --mail=<address> Mail a failure report to the given address
(and include a log file snippet, if logging
is enabled)
Note that the \@-Sign needs to be quoted!
Example: --mail=user\\\@domain.com
--suffix=<suffix> The package suffix (e.g. "-standard" or "-pro)
--version=<version> The MySQL version number (e.g. 4.0.11-gamma)
-v, --verbose Verbose execution
EOF
exit 1;
......
# Helper functions
#
# Create a log entry
#
......@@ -7,12 +9,65 @@ sub logger
print timestamp() . " " . $message . "\n" if $opt_verbose;
if (defined $opt_log && !$opt_dry_run)
{
open LOG, ">>$logfile" or die "Can't open logfile $logfile!";
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.$$";
$subject= "Bootstrap of $REPO failed";
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
{
......
......@@ -8,11 +8,14 @@
# afterwards.
#
cd @prefix@
if [ ! -f data/mysql/db.frm ] ; then
./scripts/mysql_install_db
fi
if cd @prefix@ ; then
if [ ! -f data/mysql/db.frm ] ; then
./scripts/mysql_install_db
fi
if [ -d data ] ; then
chown -R @MYSQLD_USER@ data
if [ -d data ] ; then
chown -R @MYSQLD_USER@ data
fi
else
exit $?
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment