summaryrefslogtreecommitdiff
path: root/Build-tools/Do-pkg
diff options
context:
space:
mode:
authorunknown <lenz@mysql.com>2003-02-25 15:20:07 +0100
committerunknown <lenz@mysql.com>2003-02-25 15:20:07 +0100
commitbaa0238c9465171c6886add1738dbaadc9ae8b3f (patch)
tree8073215415f8ff5b8fb24a6df0a5e682d9ddac8b /Build-tools/Do-pkg
parentc7c6abeecebe0a859dd1a541cd9ff48b6f8ed0d7 (diff)
downloadmariadb-git-baa0238c9465171c6886add1738dbaadc9ae8b3f.tar.gz
- 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
Diffstat (limited to 'Build-tools/Do-pkg')
-rwxr-xr-xBuild-tools/Do-pkg158
1 files changed, 109 insertions, 49 deletions
diff --git a/Build-tools/Do-pkg b/Build-tools/Do-pkg
index 8f80d2bf362..67c0e612828 100755
--- a/Build-tools/Do-pkg
+++ b/Build-tools/Do-pkg
@@ -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;