-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·92 lines (76 loc) · 3.15 KB
/
Copy pathpackage.sh
File metadata and controls
executable file
·92 lines (76 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/zsh
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
APP_NAME="TouchBro"
BUILD_DIR=".build/release"
APP_BUNDLE="${APP_NAME}.app"
DMG_NAME="${APP_NAME}.dmg"
ICON_SRC="icon.png"
ICON_NAME="AppIcon"
SIGN_APP="${SIGN_APP:-1}"
RESET_TCC="${RESET_TCC:-1}"
# 0. Stop running app instance
pkill -x "$APP_NAME" || true
# 0. Optionally reset TCC entries for this bundle id
if [ "$RESET_TCC" = "1" ]; then
echo "Resetting TCC permissions..."
tccutil reset Accessibility com.example.TouchBro | head -n 1 || true
fi
# 1. Build
echo "Building..."
swift build -c release -Xswiftc -D -Xswiftc APP_BUNDLE
if [ $? -ne 0 ]; then
echo "Build failed."
exit 1
fi
# 2. Create .app structure
echo "Creating ${APP_BUNDLE}..."
rm -rf "${APP_BUNDLE}"
mkdir -p "${APP_BUNDLE}/Contents/MacOS"
mkdir -p "${APP_BUNDLE}/Contents/Resources"
# 3. Copy Executable
cp "${BUILD_DIR}/${APP_NAME}" "${APP_BUNDLE}/Contents/MacOS/"
# 4. Copy Info.plist
cp Info.plist "${APP_BUNDLE}/Contents/"
# 5. Generate and copy app icon
if [ -f "$ICON_SRC" ]; then
echo "Generating app icon from ${ICON_SRC}..."
ICONSET_DIR="$(mktemp -d)/${ICON_NAME}.iconset"
mkdir -p "$ICONSET_DIR"
sips -s format png -z 16 16 "$ICON_SRC" --out "${ICONSET_DIR}/icon_16x16.png" >/dev/null
sips -s format png -z 32 32 "$ICON_SRC" --out "${ICONSET_DIR}/icon_16x16@2x.png" >/dev/null
sips -s format png -z 32 32 "$ICON_SRC" --out "${ICONSET_DIR}/icon_32x32.png" >/dev/null
sips -s format png -z 64 64 "$ICON_SRC" --out "${ICONSET_DIR}/icon_32x32@2x.png" >/dev/null
sips -s format png -z 128 128 "$ICON_SRC" --out "${ICONSET_DIR}/icon_128x128.png" >/dev/null
sips -s format png -z 256 256 "$ICON_SRC" --out "${ICONSET_DIR}/icon_128x128@2x.png" >/dev/null
sips -s format png -z 256 256 "$ICON_SRC" --out "${ICONSET_DIR}/icon_256x256.png" >/dev/null
sips -s format png -z 512 512 "$ICON_SRC" --out "${ICONSET_DIR}/icon_256x256@2x.png" >/dev/null
sips -s format png -z 512 512 "$ICON_SRC" --out "${ICONSET_DIR}/icon_512x512.png" >/dev/null
sips -s format png -z 1024 1024 "$ICON_SRC" --out "${ICONSET_DIR}/icon_512x512@2x.png" >/dev/null
iconutil -c icns "$ICONSET_DIR" -o "${APP_BUNDLE}/Contents/Resources/${ICON_NAME}.icns"
# Nudge Finder to refresh the app icon cache
touch "${APP_BUNDLE}/Contents/Info.plist"
touch "${APP_BUNDLE}"
else
echo "Warning: ${ICON_SRC} not found; skipping icon generation."
fi
# 6. Optional signing
if [ "$SIGN_APP" = "1" ]; then
echo "Signing (ad-hoc)..."
codesign --force --deep --timestamp=none --identifier com.example.TouchBro --sign - "${APP_BUNDLE}"
else
rm -rf "${APP_BUNDLE}/Contents/_CodeSignature"
echo "Skipping codesign (SIGN_APP=$SIGN_APP)."
fi
# 7. Create DMG
echo "Creating ${DMG_NAME}..."
rm -f "$DMG_NAME"
DMG_STAGING_DIR="$(mktemp -d)"
cp -R "${APP_BUNDLE}" "${DMG_STAGING_DIR}/"
ln -s /Applications "${DMG_STAGING_DIR}/Applications"
hdiutil create -volname "${APP_NAME}" -srcfolder "${DMG_STAGING_DIR}" -ov -format UDZO "${DMG_NAME}"
rm -rf "${DMG_STAGING_DIR}"
echo "Done! Created ${DMG_NAME}"
# 8. Launch the built app
echo "Launching ${APP_BUNDLE}..."
open "${SCRIPT_DIR}/${APP_BUNDLE}"