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