Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·116 lines (102 loc) · 3.8 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·116 lines (102 loc) · 3.8 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
#!/bin/bash
set -euo pipefail
REPO="$(cd "$(dirname "$0")" && pwd)"
source "$REPO/scripts/dev-config.sh"
SPM="$REPO/SuperPaste"
APP="$DEV_APP"
RESET_ONBOARDING=false
RESET_PERMISSIONS=false
LAUNCH_APP=true
usage() {
cat <<EOF
Usage: ./build.sh [--fresh] [--fresh-permissions] [--no-launch]
Options:
--fresh Reset local onboarding defaults before launching.
--fresh-permissions Reset onboarding defaults plus Screen Recording and
Accessibility TCC grants before launching.
--no-launch Build, package, and sign without opening the app.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--fresh)
RESET_ONBOARDING=true
shift
;;
--fresh-permissions)
RESET_ONBOARDING=true
RESET_PERMISSIONS=true
shift
;;
--no-launch)
LAUNCH_APP=false
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
done
CERT_NAME="SuperPaste Developer"
if ! security find-identity -v -p codesigning 2>/dev/null | grep "\"${CERT_NAME}\"" >/dev/null; then
echo "Stable signing identity missing. Run ./setup_codesign.sh before building." >&2
exit 1
fi
if [[ "${RESET_ONBOARDING}" == true ]]; then
RESET_ARGS=()
if [[ "${RESET_PERMISSIONS}" == true ]]; then
RESET_ARGS+=(--permissions)
fi
"$REPO/bin/reset-onboarding.sh" "${RESET_ARGS[@]}"
fi
echo "Building..."
cd "$SPM"
swift build -c release --product SuperPaste
echo "Packaging..."
pkill -x "$DEV_EXECUTABLE" 2>/dev/null || true
rm -rf "$APP"
mkdir -p "$APP/Contents/MacOS"
mkdir -p "$APP/Contents/Resources"
cp "$SPM/.build/release/SuperPaste" "$APP/Contents/MacOS/$DEV_EXECUTABLE"
cp "$SPM/Resources/Info.plist" "$APP/Contents/"
cp "$SPM/Resources/AppIcon.icns" "$APP/Contents/Resources/"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $DEV_BUNDLE_ID" "$APP/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $DEV_APP_NAME" "$APP/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $DEV_APP_NAME" "$APP/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $DEV_EXECUTABLE" "$APP/Contents/Info.plist"
# Development builds must never install the release app under their identity.
/usr/libexec/PlistBuddy -c "Delete :SUFeedURL" "$APP/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :SUEnableAutomaticChecks false" "$APP/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :SUAutomaticallyUpdate false" "$APP/Contents/Info.plist"
# Copy asset catalog resources if present
if [ -d "$SPM/.build/release/SuperPaste_SuperPaste.bundle" ]; then
cp -r "$SPM/.build/release/SuperPaste_SuperPaste.bundle/." "$APP/Contents/Resources/"
fi
"$REPO/scripts/embed-sparkle.sh" "$SPM" "$APP"
echo "Signing..."
# Persistent self-signed cert keeps macOS TCC grants (Accessibility, Screen Recording)
# alive across rebuilds. Ad-hoc signing ties the grant to a cdhash that changes on every
# recompile, forcing the user back into System Settings each time.
ENTITLEMENTS="$SPM/Resources/SuperPaste.entitlements"
SIGN_ARGS=("${CERT_NAME}" --force --deep --options runtime)
if [[ -f "$ENTITLEMENTS" ]]; then
echo " Using entitlements: $ENTITLEMENTS"
SIGN_ARGS+=(--entitlements "$ENTITLEMENTS")
fi
# With a self-signed identity `--timestamp` would try to reach Apple's servers
# and fail, slowing down the build. Only use timestamp with a Developer ID cert.
if security find-identity -v -p codesigning 2>/dev/null | grep -q "Developer ID Application:"; then
SIGN_ARGS+=(--timestamp)
fi
codesign -s "${SIGN_ARGS[@]}" "$APP"
if [[ "${LAUNCH_APP}" == true ]]; then
echo "Launching..."
open "$APP"
fi
echo "Done."