File indexing completed on 2024-04-28 16:06:41

0001 #!/bin/bash
0002 # Can be used to create an image with only amd64 binaries when using
0003 # Qt6 with an OSX cross toolchain.
0004 #
0005 # Example usage:
0006 # fatdmg=(kid3/*-Darwin.dmg)
0007 # slimdmg=${fatdmg/-Darwin./-Darwin-amd64.}
0008 # PATH=$PATH:/opt/osxcross/target/bin ../kid3/macosx/mac-strip-arm64.sh $fatdmg $slimdmg
0009 
0010 SRC=${1?path to source dmg missing}
0011 DST=${2?path to destination dmg missing}
0012 if ! hash lipo 2>/dev/null; then
0013   echo "lipo not found"
0014   exit 1
0015 fi
0016 set -e
0017 APPDIR=/tmp/inst
0018 test -d "$APPDIR" && rm -rf "$APPDIR"
0019 mkdir "$APPDIR"
0020 # 7z x "$SRC" -o"$APPDIR" # does not preserve permissions and symlinks
0021 DMGIMG=/tmp/dmg.img
0022 dmg2img "$SRC" -o "$DMGIMG"
0023 mkdir -p /tmp/mnt
0024 archivemount "$DMGIMG" /tmp/mnt
0025 #sudo mount -t iso9660 -o loop "$DMGIMG" /tmp/mnt
0026 cp -a /tmp/mnt/* "$APPDIR"
0027 fusermount -u /tmp/mnt
0028 #sudo umount /mnt
0029 rmdir /tmp/mnt
0030 rm "$DMGIMG"
0031 
0032 set +e
0033 for f in $(find "$APPDIR" -type f); do
0034   ARCHS=$(lipo -archs $f 2>/dev/null)
0035   if test $? -eq 0; then
0036     if test -z "${ARCHS#*arm64*}"; then
0037       echo $f
0038       lipo "$f" -remove arm64 -output "$f"
0039     fi
0040   fi
0041 done
0042 set -e
0043 
0044 genisoimage -V "Kid3" -D -R -apple -no-pad -o "$DST.uncompressed" "$APPDIR"
0045 dmg dmg "$DST.uncompressed" "$DST"
0046 rm "$DST.uncompressed"
0047 rm -rf "$APPDIR"