contrib/macos/build-dmg.sh (2302 bytes)
1 #!/bin/sh 2 3 # build-dmg.sh: make sbm-VERSION.dmg, the portable macOS edition, in the top 4 # directory of the source. Run it on macOS: 5 # 6 # sh contrib/macos/build-dmg.sh 7 # 8 # The image holds sbm.app. The app contains bm, the bm-* tools and fzf, so it 9 # needs no other software. The script gets fzf from the fzf release on 10 # GitHub. It stops if the SHA-256 sum of a download is not the expected one. 11 12 set -e 13 14 fzf_version=0.74.4 15 fzf_amd64_sum=2d392b50be66e2ab104ccd52a6072df692b1f9b9c5b449a9c098de885f32c4c5 16 fzf_arm64_sum=4f6a113bfc0c7959e0005c78d566a51afc4fcefc956f43735c62a9deb19e92ae 17 18 here=$(cd "$(dirname "$0")" && pwd) 19 top=$(cd "$here/../.." && pwd) 20 version=$(sed -n 's/^VERSION=//p' "$top/config.mk") 21 out=$top/sbm-$version.dmg 22 23 work=${TMPDIR:-/tmp}/sbm-dmg.$$ 24 mkdir "$work" 25 trap 'rm -rf "$work"' EXIT INT TERM 26 app=$work/root/sbm.app 27 mkdir -p "$app/Contents/MacOS" 28 29 make -s -C "$top" install PREFIX="$app/Contents/Resources" >/dev/null 30 cp "$here/sbm" "$app/Contents/MacOS/sbm" 31 cp "$here/sbm-run" "$app/Contents/Resources/sbm-run" 32 cp "$top/LICENSE" "$app/Contents/Resources/LICENSE" 33 chmod 755 "$app/Contents/MacOS/sbm" "$app/Contents/Resources/sbm-run" 34 sed "s/@VERSION@/$version/g" "$here/Info.plist" > "$app/Contents/Info.plist" 35 plutil -lint "$app/Contents/Info.plist" >/dev/null 36 37 url=https://github.com/junegunn/fzf/releases/download/v$fzf_version 38 for arch in amd64 arm64; do 39 curl -fsSL -o "$work/fzf-$arch.tar.gz" \ 40 "$url/fzf-$fzf_version-darwin_$arch.tar.gz" 41 done 42 shasum -a 256 -c >/dev/null <<EOF 43 $fzf_amd64_sum $work/fzf-amd64.tar.gz 44 $fzf_arm64_sum $work/fzf-arm64.tar.gz 45 EOF 46 for arch in amd64 arm64; do 47 mkdir "$work/$arch" 48 tar -xzf "$work/fzf-$arch.tar.gz" -C "$work/$arch" 49 done 50 # One fzf for Intel and Apple silicon. 51 lipo -create -output "$app/Contents/Resources/bin/fzf" \ 52 "$work/amd64/fzf" "$work/arm64/fzf" 53 curl -fsSL -o "$app/Contents/Resources/fzf-LICENSE.txt" \ 54 "https://raw.githubusercontent.com/junegunn/fzf/v$fzf_version/LICENSE" 55 56 # The app has no signature from a registered developer. An ad-hoc signature 57 # still lets macOS find a damaged app. 58 codesign --force --deep --sign - "$app" 59 60 ln -s /Applications "$work/root/Applications" 61 hdiutil create -quiet -volname "sbm $version" -srcfolder "$work/root" \ 62 -ov -format UDZO "$out" 63 printf '%s\n' "$out"