Commit a8aaa3ef authored by unknown's avatar unknown

- Do-pkg can now create a separate package including a MySQL Startup Item

   for Mac OS X and add it to the installation Disk Image.


Build-tools/Do-pkg:
   - added code to build the StartupItem PKG along with the MySQL PKG and
     add it to the resulting Disk Image (can be skipped with --skip-si)
   - lots of cleanups (use more builtin Perl functions instead of 
     subprocesses, enable a full dry run without errors)
support-files/MacOSX/StartupItem.Info.plist:
   - removed IFPkgFlagOverwritePermissions and IFPkgFlagUseUserMask
parent 9194f5ef
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Do-pkg - convert a binary distribution into a Mac OS X PKG and put it # Do-pkg - convert a binary distribution into a Mac OS X PKG and put it
# inside a Disk Image (.dmg) # inside a Disk Image (.dmg). Additionally, add a separate package,
# including the required Startup Item to automatically start MySQL on
# bootup.
# #
# The script currently assumes the following environment (which should exist # The script currently assumes the following environment (which should exist
# like that, if the Do-compile script was used to build the binary # like that, if the Do-compile script was used to build the binary
...@@ -17,14 +19,19 @@ ...@@ -17,14 +19,19 @@
# written by Lenz Grimmer <lenz@mysql.com> # written by Lenz Grimmer <lenz@mysql.com>
# #
use Cwd;
use File::Basename;
use File::Copy;
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
use Sys::Hostname;
$opt_dry_run= undef; $opt_dry_run= undef;
$opt_help= undef; $opt_help= undef;
$opt_log= undef; $opt_log= undef;
$opt_mail= ""; $opt_mail= "";
$opt_skip_dmg= undef; $opt_skip_dmg= undef;
$opt_skip_si= undef;
$opt_suffix= undef; $opt_suffix= undef;
$opt_verbose= undef; $opt_verbose= undef;
$opt_version= undef; $opt_version= undef;
...@@ -35,13 +42,14 @@ GetOptions( ...@@ -35,13 +42,14 @@ GetOptions(
"log|l:s", "log|l:s",
"mail|m=s", "mail|m=s",
"skip-dmg|skip-disk-image|s", "skip-dmg|skip-disk-image|s",
"skip-si|skip-startup-item",
"suffix=s", "suffix=s",
"verbose|v", "verbose|v",
"version=s", "version=s",
) || &print_help; ) || &print_help;
# Include helper functions # Include helper functions
chomp($PWD= `pwd`); $PWD= cwd();
$LOGGER= "$PWD/logger.pm"; $LOGGER= "$PWD/logger.pm";
if (-f "$LOGGER") if (-f "$LOGGER")
{ {
...@@ -54,7 +62,7 @@ else ...@@ -54,7 +62,7 @@ else
$PM= "/Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker"; $PM= "/Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker";
$TMP= $ENV{TMPDIR}; $TMP= $ENV{TMPDIR};
$TMP eq "" ? $TMP= $TMP . "/PKGBUILD": $TMP= "/tmp/PKGBUILD"; $TMP eq "" ? $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";
...@@ -62,8 +70,8 @@ $SUFFIX= $opt_suffix; ...@@ -62,8 +70,8 @@ $SUFFIX= $opt_suffix;
$VERSION= $opt_version; $VERSION= $opt_version;
($MAJOR, $MINOR, $RELEASE)= split(/\./, $VERSION); ($MAJOR, $MINOR, $RELEASE)= split(/\./, $VERSION);
$NAME= "mysql$SUFFIX-$VERSION"; $NAME= "mysql$SUFFIX-$VERSION";
chomp($HOST= `hostname`); $HOST= hostname();
chomp($ID= `whoami`); $ID= getpwuid($>);
$HOST=~ /^([^.-]*)/; $HOST=~ /^([^.-]*)/;
$HOST= $1; $HOST= $1;
$LOGFILE= "$PWD/Logs/$HOST-$MAJOR.$MINOR$SUFFIX.log"; $LOGFILE= "$PWD/Logs/$HOST-$MAJOR.$MINOR$SUFFIX.log";
...@@ -73,6 +81,12 @@ $SUPFILEDIR= <$SRCBASEDIR/support-files/MacOSX>; ...@@ -73,6 +81,12 @@ $SUPFILEDIR= <$SRCBASEDIR/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>;
$SI_INFO= <$SUPFILEDIR/StartupItem.Info.plist>;
$SI_DESC= <$SUPFILEDIR/StartupItem.Description.plist>;
$SI_PARAMS= <$SUPFILEDIR/StartupParameters.plist>;
$SI_POST= <$SUPFILEDIR/StartupItem.postinstall>;
$SI_NAME= "MySQLStartupItem";
$SI_SCRIPT= <$SUPFILEDIR/MySQL>;
@RESOURCES= qw/ ReadMe.txt postinstall preinstall /; @RESOURCES= qw/ ReadMe.txt postinstall preinstall /;
@LICENSES= ("$SRCBASEDIR/COPYING","$SRCBASEDIR/MySQLEULA.txt"); @LICENSES= ("$SRCBASEDIR/COPYING","$SRCBASEDIR/MySQLEULA.txt");
...@@ -99,7 +113,9 @@ if (defined $opt_log) ...@@ -99,7 +113,9 @@ if (defined $opt_log)
# Creating the UFS disk image requires root privileges # Creating the UFS disk image requires root privileges
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!") if ($ID ne "root" && !$opt_dry_run);
foreach $file ($TAR, $INFO, $DESC) @files= ($TAR, $INFO, $DESC);
@files= (@files, $SI_INFO, $SI_DESC, $SI_POST, $SI_SCRIPT) unless $opt_skip_si;
foreach $file (@files)
{ {
&abort("Unable to find $file!") unless (-f "$file"); &abort("Unable to find $file!") unless (-f "$file");
} }
...@@ -112,14 +128,22 @@ foreach $dir ($TMP, $PKGROOT, $PKGDEST, $RESOURCE_DIR) ...@@ -112,14 +128,22 @@ foreach $dir ($TMP, $PKGROOT, $PKGDEST, $RESOURCE_DIR)
{ {
if (!-d $dir) if (!-d $dir)
{ {
&run_command("mkdir $dir", "Could not make directory $dir!"); &logger("Creating directory $dir!");
unless($opt_dry_run)
{
mkdir($dir) or &abort("Could not make directory $dir!");
}
} }
} }
foreach $resfile (@RESOURCES) foreach $resfile (@RESOURCES)
{ {
$command= "cp $SUPFILEDIR/$resfile $RESOURCE_DIR"; &logger("Copying $SUPFILEDIR/$resfile to $RESOURCE_DIR");
&run_command($command, "Error while copying $SUPFILEDIR/$resfile to $RESOURCE_DIR"); unless($opt_dry_run)
{
copy("$SUPFILEDIR/$resfile", "$RESOURCE_DIR") or
&abort("Error while copying $SUPFILEDIR/$resfile to $RESOURCE_DIR");
}
} }
# Search for license file # Search for license file
...@@ -127,12 +151,17 @@ foreach $license (@LICENSES) ...@@ -127,12 +151,17 @@ foreach $license (@LICENSES)
{ {
if (-f "$license") if (-f "$license")
{ {
$command= "cp $license $RESOURCE_DIR/License.txt"; &logger("Copy $license to $RESOURCE_DIR/License.txt");
&run_command($command, "Error while copying $license to $RESOURCE_DIR"); unless($opt_dry_run)
{
copy("$license", "$RESOURCE_DIR/License.txt") or
&abort("Error while copying $license to $RESOURCE_DIR");
}
} }
} }
&abort("Could not find a license file!") unless (-f "$RESOURCE_DIR/License.txt"); &abort("Could not find a license file!")
unless (-f "$RESOURCE_DIR/License.txt");
# Extract the binary tarball and create the "mysql" symlink # Extract the binary tarball and create the "mysql" symlink
&logger("Extracting $TAR to $PKGROOT"); &logger("Extracting $TAR to $PKGROOT");
...@@ -145,10 +174,38 @@ foreach $license (@LICENSES) ...@@ -145,10 +174,38 @@ foreach $license (@LICENSES)
# returning a non-zero value, even though the package was created correctly # returning a non-zero value, even though the package was created correctly
&logger("Running PackageMaker"); &logger("Running PackageMaker");
$command= "$PM -build -p $PKGDEST/$NAME.pkg -f $PKGROOT -r $RESOURCE_DIR -i $INFO -d $DESC || true"; $command= "$PM -build -p $PKGDEST/$NAME.pkg -f $PKGROOT -r $RESOURCE_DIR -i $INFO -d $DESC || true";
&run_command($command, "Error while building package!"); &run_command($command, "Error while building package $NAME.pkg!");
#
# Build the Startup Item PKG
#
unless ($opt_skip_si)
{
&logger("Cleaning up $PKGROOT");
&run_command("rm -rf $PKGROOT/*", "Unable to clean up $PKGROOT!");
&logger("Cleaning up $RESOURCE_DIR");
&run_command("rm -rf $RESOURCE_DIR/*", "Unable to clean up $RESOURCE_DIR!");
&logger("Installing MySQL StartupItem files into $PKGROOT/MySQL");
unless($opt_dry_run)
{
mkdir("$PKGROOT/MySQL") or &abort("Error creating $PKGROOT/MySQL");
copy("$SI_SCRIPT", "$PKGROOT/MySQL/")
or &abort("Error copying $SI_SCRIPT!");
chmod(0755, "$PKGROOT/MySQL/" . basename("$SI_SCRIPT"));
copy("$SI_PARAMS", "$PKGROOT/MySQL/")
or &abort("Error copying $SI_PARAMS!");
chmod(0644, "$PKGROOT/MySQL/" . basename("$SI_PARAMS"));
&run_command("chown -R root.wheel $PKGROOT/*", "Cannot chown $PKGROOT!");
copy("$SI_POST", "$RESOURCE_DIR/postinstall")
or &abort("Error copying $SI_POST!");
chmod(0644, "$RESOURCE_DIR/postinstall");
}
&logger("Removing $PKGROOT"); &logger("Building $SI_NAME.pkg using PackageMaker");
&run_command("rm -rf $PKGROOT", "Unable to remove $PKGROOT!"); $command= "$PM -build -p $PKGDEST/$SI_NAME.pkg -f $PKGROOT -r $RESOURCE_DIR -i $SI_INFO -d $SI_DESC || true";
&run_command($command, "Error while building package $SI_NAME.pkg!");
}
if ($opt_skip_dmg) if ($opt_skip_dmg)
{ {
...@@ -159,7 +216,7 @@ if ($opt_skip_dmg) ...@@ -159,7 +216,7 @@ if ($opt_skip_dmg)
# 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
&logger("Determining required disk image size for $PKGDEST"); &logger("Determining required disk image size for $PKGDEST");
if (! $opt_dry_run) unless($opt_dry_run)
{ {
chomp($_= `du -sk $PKGDEST`); chomp($_= `du -sk $PKGDEST`);
@size= split(); @size= split();
...@@ -167,7 +224,10 @@ if (! $opt_dry_run) ...@@ -167,7 +224,10 @@ if (! $opt_dry_run)
&logger("Disk image size: $size KB"); &logger("Disk image size: $size KB");
} }
&abort("Zero bytes? Something is wrong here!") if ($size == 0); unless($opt_dry_run)
{
&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";
...@@ -181,7 +241,7 @@ $command= "hdiutil create $TMPNAME -size ${size}k -ov -fs UFS -volname $NAME"; ...@@ -181,7 +241,7 @@ $command= "hdiutil create $TMPNAME -size ${size}k -ov -fs UFS -volname $NAME";
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f3 -d" "`) if (!$opt_dry_run); chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f3 -d" "`) if (!$opt_dry_run);
&logger("Copying $PKGDEST/$NAME.pkg to Disk image /Volumes/$NAME"); &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 $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!"); &run_command("ditto $SUPFILEDIR/ReadMe.txt /Volumes/$NAME", "Could not copy $SPFILEDIR/ReadMe.txt to /Volumes/$NAME!");
chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f1 -d" "`) if (!$opt_dry_run); chomp($mountpoint=`mount | grep "\/Volumes\/$NAME" | cut -f1 -d" "`) if (!$opt_dry_run);
&abort("/Volumes/$NAME not attached!") if (!$mountpoint && !$opt_dry_run); &abort("/Volumes/$NAME not attached!") if (!$mountpoint && !$opt_dry_run);
&logger("Unmounting $mountpoint"); &logger("Unmounting $mountpoint");
...@@ -221,20 +281,23 @@ NOTE: You need to run this script with root privileges (required ...@@ -221,20 +281,23 @@ NOTE: You need to run this script with root privileges (required
Options: Options:
--dry-run Dry run without executing --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>] -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 -m, --mail=<address> Mail a failure report to the given
(and include a log file snippet, if logging address (and include a log file snippet,
is enabled) if logging is enabled)
Note that the \@-Sign needs to be quoted! Note that the \@-Sign needs to be quoted!
Example: --mail=user\\\@domain.com Example: --mail=user\\\@domain.com
-s, --skip-disk-image Just build the PKG, don't put it into a -s, --skip-disk-image, --skip-dmg Just build the PKGs, don't put it into a
disk image afterwards disk image afterwards
--suffix=<suffix> The package suffix (e.g. "-standard" or "-pro) --skip-startup-item, --skip-si Skip the creation of the StartupItem PKG
--version=<version> The MySQL version number (e.g. 4.0.11-gamma) --suffix=<suffix> The package suffix
-v, --verbose Verbose execution (e.g. "-standard" or "-pro)
--version=<version> The MySQL version number
(e.g. 4.0.11-gamma)
-v, --verbose Verbose execution
EOF EOF
exit 1; exit 1;
......
...@@ -19,13 +19,11 @@ ...@@ -19,13 +19,11 @@
<key>IFPkgFlagAuthorizationAction</key> <key>IFPkgFlagAuthorizationAction</key>
<string>RootAuthorization</string> <string>RootAuthorization</string>
<key>IFPkgFlagDefaultLocation</key> <key>IFPkgFlagDefaultLocation</key>
<string>/Library/StartupItems/</string> <string>/Library/StartupItems</string>
<key>IFPkgFlagInstallFat</key> <key>IFPkgFlagInstallFat</key>
<false/> <false/>
<key>IFPkgFlagIsRequired</key> <key>IFPkgFlagIsRequired</key>
<false/> <false/>
<key>IFPkgFlagOverwritePermissions</key>
<true/>
<key>IFPkgFlagRelocatable</key> <key>IFPkgFlagRelocatable</key>
<false/> <false/>
<key>IFPkgFlagRestartAction</key> <key>IFPkgFlagRestartAction</key>
...@@ -34,8 +32,6 @@ ...@@ -34,8 +32,6 @@
<true/> <true/>
<key>IFPkgFlagUpdateInstalledLanguages</key> <key>IFPkgFlagUpdateInstalledLanguages</key>
<false/> <false/>
<key>IFPkgFlagUseUserMask</key>
<false/>
<key>IFPkgFormatVersion</key> <key>IFPkgFormatVersion</key>
<real>0.10000000149011612</real> <real>0.10000000149011612</real>
</dict> </dict>
......
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