-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·177 lines (154 loc) · 5.13 KB
/
build.sh
File metadata and controls
executable file
·177 lines (154 loc) · 5.13 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_NAME="ScreenPrankLocker"
BUNDLE_ID="com.pranklocker.screenpranklocker"
VERSION="1.0.0"
UNIVERSAL_DIR=".build/universal"
APP_DIR="build/${APP_NAME}.app"
PKG_DIR="build"
create_plist() {
cat > "$1" << PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundleDisplayName</key>
<string>Screen Prank Locker</string>
<key>CFBundleIdentifier</key>
<string>${BUNDLE_ID}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleExecutable</key>
<string>${APP_NAME}</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Screen Prank Locker uses the camera to photograph anyone who tries to use your locked computer.</string>
<key>LSUIElement</key>
<false/>
</dict>
</plist>
PLIST
}
cmd_build() {
echo "==> Building for arm64 (Apple Silicon)..."
swift build -c release --arch arm64
echo "==> Building for x86_64 (Intel)..."
swift build -c release --arch x86_64
echo "==> Stitching together Universal Binary..."
local ARM_BIN_PATH=$(swift build -c release --arch arm64 --show-bin-path)
local X86_BIN_PATH=$(swift build -c release --arch x86_64 --show-bin-path)
mkdir -p "${UNIVERSAL_DIR}"
# We manually use lipo to guarantee the fat binary is created exactly where we want it
lipo -create -output "${UNIVERSAL_DIR}/${APP_NAME}" "${ARM_BIN_PATH}/${APP_NAME}" "${X86_BIN_PATH}/${APP_NAME}"
echo "==> Universal binary created at ${UNIVERSAL_DIR}/${APP_NAME}"
}
cmd_app() {
cmd_build
echo "==> Creating ${APP_NAME}.app bundle"
rm -rf "${APP_DIR}"
mkdir -p "${APP_DIR}/Contents/MacOS"
mkdir -p "${APP_DIR}/Contents/Resources"
# Copy the manually created fat executable
cp "${UNIVERSAL_DIR}/${APP_NAME}" "${APP_DIR}/Contents/MacOS/"
# Resources are copied directly from source — no SwiftPM resource bundle needed
if [ -d "${SCRIPT_DIR}/Sources/ScreenPrankLocker/Resources" ]; then
cp -R "${SCRIPT_DIR}/Sources/ScreenPrankLocker/Resources/" "${APP_DIR}/Contents/Resources/"
fi
# Copy app icon
if [ -f "${SCRIPT_DIR}/AppIcon.icns" ]; then
cp "${SCRIPT_DIR}/AppIcon.icns" "${APP_DIR}/Contents/Resources/"
fi
# Create Info.plist
create_plist "${APP_DIR}/Contents/Info.plist"
# Ad-hoc code sign
echo "==> Code-signing ${APP_DIR} (ad-hoc)..."
codesign --force --sign - "${APP_DIR}"
echo "==> ${APP_DIR} created"
}
cmd_pkg() {
cmd_app
echo "==> Building installer package"
mkdir -p "${PKG_DIR}"
pkgbuild \
--root "${APP_DIR}" \
--identifier "${BUNDLE_ID}" \
--version "${VERSION}" \
--install-location "/Applications/${APP_NAME}.app" \
"${PKG_DIR}/${APP_NAME}-${VERSION}.pkg"
echo "==> ${PKG_DIR}/${APP_NAME}-${VERSION}.pkg created"
}
cmd_dmg() {
cmd_app
echo "==> Building DMG"
mkdir -p "${PKG_DIR}"
local DMG_TMP="${PKG_DIR}/dmg_tmp"
rm -rf "${DMG_TMP}"
mkdir -p "${DMG_TMP}"
cp -R "${APP_DIR}" "${DMG_TMP}/"
ln -s /Applications "${DMG_TMP}/Applications"
hdiutil create -volname "${APP_NAME}" \
-srcfolder "${DMG_TMP}" \
-ov -format UDZO \
"${PKG_DIR}/${APP_NAME}-${VERSION}.dmg"
rm -rf "${DMG_TMP}"
echo "==> ${PKG_DIR}/${APP_NAME}-${VERSION}.dmg created"
}
cmd_install() {
cmd_app
echo "==> Installing to /Applications"
rm -rf "/Applications/${APP_NAME}.app"
cp -R "${APP_DIR}" "/Applications/${APP_NAME}.app"
# Remove the quarantine attribute so macOS does not translocate the app.
/usr/bin/xattr -dr com.apple.quarantine "/Applications/${APP_NAME}.app" 2>/dev/null || true
echo "==> Installed to /Applications/${APP_NAME}.app"
}
cmd_test() {
swift test
}
cmd_run() {
cmd_build
"${UNIVERSAL_DIR}/${APP_NAME}"
}
cmd_clean() {
swift package clean
rm -rf build/
rm -rf "${UNIVERSAL_DIR}"
}
cmd_help() {
echo "Usage: ./build.sh <command>"
echo ""
echo "Commands:"
echo " build Build universal release binary"
echo " app Create .app bundle"
echo " pkg Create .pkg installer"
echo " dmg Create .dmg disk image"
echo " install Install to /Applications"
echo " test Run tests"
echo " run Build and run"
echo " clean Remove build artifacts"
echo " help Show this help"
}
case "${1:-help}" in
build) cmd_build ;;
app) cmd_app ;;
pkg) cmd_pkg ;;
dmg) cmd_dmg ;;
install) cmd_install ;;
test) cmd_test ;;
run) cmd_run ;;
clean) cmd_clean ;;
help) cmd_help ;;
*) echo "Unknown command: $1"; cmd_help; exit 1 ;;
esac