diff options
author | Andrey Filipenkov <decapitator@ukr.net> | 2022-05-30 12:42:44 +0300 |
---|---|---|
committer | Andrey Filipenkov <decapitator@ukr.net> | 2022-05-30 12:42:44 +0300 |
commit | 65feb3d9e30223aa298095049a0cdcdcc857f724 (patch) | |
tree | 30a0dc253dd9686783c306ec12c0e3e81659c764 /tools/darwin | |
parent | 1444aa445c01a799bee847c600ec53768d9d9065 (diff) |
[macOS] rewrite DMG creation script in bash
prepares DMG content in temp directory instead of writing directly to the disk image, the image is mounted only to set volume icon
Diffstat (limited to 'tools/darwin')
-rwxr-xr-x | tools/darwin/packaging/osx/dmgmaker.pl | 79 | ||||
-rwxr-xr-x | tools/darwin/packaging/osx/dmgmaker.sh | 42 | ||||
-rwxr-xr-x | tools/darwin/packaging/osx/mkdmg-osx.sh.in | 6 |
3 files changed, 45 insertions, 82 deletions
diff --git a/tools/darwin/packaging/osx/dmgmaker.pl b/tools/darwin/packaging/osx/dmgmaker.pl deleted file mode 100755 index 8d3ab07b53..0000000000 --- a/tools/darwin/packaging/osx/dmgmaker.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) 2008-2013 Team Kodi -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use strict; -use warnings; - -sub make_dmg { - my $mpkg = shift; - my $volname = shift; - my $pkgname = shift; - my $dev_handle; - - die("Could not find \"$mpkg\"\n") - if ! -d $mpkg; - - my $ext = $1 if $mpkg =~ /.*\.(.*?)$/; - $ext = "mpkg" if !$ext; - - # thanks to http://dev.simon-cozens.org/songbee/browser/release-manager-tools/build-dmg.sh - `hdiutil create -fs HFS+ -volname "$pkgname" -format UDRW -srcfolder "$mpkg" "$volname.dmg"`; - $dev_handle = `hdiutil attach -readwrite -noverify -noautoopen "$volname.dmg" | grep Apple_HFS`; - chomp $dev_handle; - $dev_handle = $1 if $dev_handle =~ /^\/dev\/(disk\d+)/; - die("Could not obtain device handle\n") if !$dev_handle; - print "Got device handle \"$dev_handle\"\n"; - #clear the volume - we will copy stuff on it with ditto later - #this removes crap which might have come in via the srcfolder - #parameter of hdiutil above - `rm -r /Volumes/$pkgname/*`; - print "Ignore \"No space left on device\" warnings from ditto, they are an autosize artifact\n"; - `ditto "$mpkg" "/Volumes/$pkgname/$pkgname.$ext"`; - - # set a volume icon if we have one - if ( -f "VolumeIcon.icns" ) { - `ditto VolumeIcon.icns "/Volumes/$pkgname/.VolumeIcon.icns"`; - } - # make symlink to /Applications - `ln -s /Applications "/Volumes/$pkgname/Applications"`; - - `mkdir "/Volumes/$pkgname/background"`; - `ditto ../media/osx/background "/Volumes/$pkgname/background/"`; - `xcrun SetFile -a V "/Volumes/$pkgname/background"`; - `xcrun SetFile -a C "/Volumes/$pkgname/"`; - `cp VolumeDSStoreApp "/Volumes/$pkgname/.DS_Store"`; - `diskutil unmountDisk $dev_handle`; - `hdiutil detach $dev_handle`; - `hdiutil convert "$volname.dmg" -format UDZO -imagekey zlib-level=9 -o "$volname.udzo.dmg"`; - `rm -f "$volname.dmg"`; - `mv "$volname.udzo.dmg" "$volname.dmg"`; - `hdiutil internet-enable -yes "$volname.dmg"`; -} - -if (! defined $ARGV[0]) { - die("Please specify the mpkg to make a DMG of as the first argument\n". - "or -c to create a package and use it.\n"); -} - -if ( $ARGV[0] eq "-c" ) { - die("TODO: -c\n"); - #make_dmg(make_mpkg(), "Kodi Atlantis - 8.10", "Kodi Media Center"); - exit; -} - -make_dmg($ARGV[0], $ARGV[1], "Kodi"); diff --git a/tools/darwin/packaging/osx/dmgmaker.sh b/tools/darwin/packaging/osx/dmgmaker.sh new file mode 100755 index 0000000000..9a5dc2757e --- /dev/null +++ b/tools/darwin/packaging/osx/dmgmaker.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Copyright (C) 2022 Team Kodi +# This file is part of Kodi - https://kodi.tv +# +# SPDX-License-Identifier: GPL-2.0-or-later +# See LICENSES/README.md for more information. + +appPath="$1" +appName="$2" +dmgPath="$3" + +if [[ ! -d "$appPath" ]]; then + echo "app not found at $appPath" + exit 1 +fi + +tempDir=$(mktemp -d -t "$appName") + +# prepare DMG contents +ditto "$appPath" "$tempDir/$appName.app" +ditto VolumeIcon.icns "$tempDir/.VolumeIcon.icns" +cp VolumeDSStoreApp "$tempDir/.DS_Store" +ln -s /Applications "$tempDir/Applications" + +destBackgroundPath="$tempDir/background" +ditto ../media/osx/background "$destBackgroundPath" +xcrun SetFile -a V "$destBackgroundPath" + +# volume icon attribute must be set on the mounted DMG +dmgFileTemp="$(mktemp -t "$appName").dmg" +hdiutil create -fs HFS+ -format UDRW -volname "$appName" -srcfolder "$tempDir" "$dmgFileTemp" +# deviceHandle is /dev/disk<number> +deviceHandle=$(hdiutil attach -readwrite -noverify -noautoopen "$dmgFileTemp" \ + | fgrep GUID_partition_scheme | awk -F '[[:space:]]' '{print $1}') +xcrun SetFile -a C "/Volumes/$appName" + +# compress DMG +diskutil eject "$deviceHandle" +hdiutil convert "$dmgFileTemp" -format ULFO -o "$dmgPath" + +rm -rf "$dmgFileTemp" "$tempDir" diff --git a/tools/darwin/packaging/osx/mkdmg-osx.sh.in b/tools/darwin/packaging/osx/mkdmg-osx.sh.in index 5ef14e9b56..458a7b6ec3 100755 --- a/tools/darwin/packaging/osx/mkdmg-osx.sh.in +++ b/tools/darwin/packaging/osx/mkdmg-osx.sh.in @@ -60,8 +60,8 @@ echo Creating $PACKAGE package version $VERSION revision $REVISION dmgPath="$DIRNAME/$ARCHIVE.dmg" rm -rf "$dmgPath" -if [ -e "/Volumes/@APP_NAME_LC@" ]; then - umount /Volumes/@APP_NAME_LC@ +if [ -e "/Volumes/@APP_NAME@" ]; then + umount /Volumes/@APP_NAME@ fi #generate volume iconset @@ -71,7 +71,7 @@ then iconutil -c icns --output "VolumeIcon.icns" "../media/osx/volumeIcon.iconset" fi -$DIRNAME/dmgmaker.pl $APP $ARCHIVE +"$DIRNAME/dmgmaker.sh" "$APP" "@APP_NAME@" "$dmgPath" echo "done" |