84 lines
2.6 KiB
Bash
Executable File
84 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build secure-editor-go and package it as a macOS .app bundle so the
|
|
# Dock shows the bundled logo (iconutil/sips convert logo.jpeg -> logo.icns).
|
|
#
|
|
# Usage:
|
|
# ./build.sh # build binary + assemble .app bundle
|
|
# ./build.sh --binary-only # build only the plain binary, no bundle
|
|
#
|
|
# Run the app:
|
|
# ./secure-editor-go.app/Contents/MacOS/secure-editor-go <file> aes-256-gcm <key> <nonce>
|
|
|
|
set -euo pipefail
|
|
|
|
APP_NAME="secure-editor-go"
|
|
APP_BUNDLE="${APP_NAME}.app"
|
|
THIS_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
cd "$THIS_DIR"
|
|
|
|
BINARY_ONLY=0
|
|
if [ "${1-}" = "--binary-only" ]; then
|
|
BINARY_ONLY=1
|
|
fi
|
|
|
|
# 1. Build the Go binary.
|
|
# Silence the Xcode 15+ linker warning "ignoring duplicate libraries: '-lobjc'"
|
|
# emitted by Fyne/GLFW CGo packages passing -lobjc more than once.
|
|
echo "==> building binary"
|
|
CGO_LDFLAGS="-Wl,-no_warn_duplicate_libraries" go build -o "$APP_NAME" .
|
|
|
|
if [ "$BINARY_ONLY" -eq 1 ]; then
|
|
echo "==> done (binary only): $APP_NAME"
|
|
exit 0
|
|
fi
|
|
|
|
# 2. Generate logo.icns from logo.jpeg using macOS tooling.
|
|
if [ -f logo.jpeg ]; then
|
|
echo "==> generating logo.icns"
|
|
rm -rf logo.iconset logo.icns
|
|
mkdir -p logo.iconset
|
|
|
|
gen() {
|
|
# $1 = pixel size, $2 = iconset file name (without .png)
|
|
sips -s format png -z "$1" "$1" logo.jpeg --out "logo.iconset/$2.png" >/dev/null
|
|
}
|
|
|
|
gen 16 icon_16x16
|
|
gen 32 icon_16x16@2x
|
|
gen 32 icon_32x32
|
|
gen 64 icon_32x32@2x
|
|
gen 128 icon_128x128
|
|
gen 256 icon_128x128@2x
|
|
gen 256 icon_256x256
|
|
gen 512 icon_256x256@2x
|
|
gen 512 icon_512x512
|
|
gen 1024 icon_512x512@2x
|
|
|
|
iconutil -c icns logo.iconset -o logo.icns
|
|
rm -rf logo.iconset
|
|
else
|
|
echo "warning: logo.jpeg not found, bundle will have no icon" >&2
|
|
fi
|
|
|
|
# 3. Assemble the .app bundle.
|
|
echo "==> assembling $APP_BUNDLE"
|
|
rm -rf "$APP_BUNDLE"
|
|
mkdir -p "$APP_BUNDLE/Contents/MacOS"
|
|
mkdir -p "$APP_BUNDLE/Contents/Resources"
|
|
cp "$APP_NAME" "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
|
|
[ -f logo.icns ] && cp logo.icns "$APP_BUNDLE/Contents/Resources/logo.icns"
|
|
cp Info.plist "$APP_BUNDLE/Contents/Info.plist"
|
|
|
|
# Refresh LaunchServices' view of the bundle so the icon takes effect.
|
|
touch "$APP_BUNDLE"
|
|
touch "$APP_BUNDLE/Contents/Info.plist"
|
|
|
|
# 4. (Optional) register with LaunchServices so the icon is picked up.
|
|
LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister"
|
|
if [ -x "$LSREGISTER" ]; then
|
|
"$LSREGISTER" "$APP_BUNDLE" >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
echo "==> done: $APP_BUNDLE"
|
|
echo " run: $APP_BUNDLE/Contents/MacOS/$APP_NAME <file> aes-256-gcm <key> <nonce>"
|