Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·87 lines (78 loc) · 3.63 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·87 lines (78 loc) · 3.63 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
#!/bin/bash
# Build MXControl.app — a self-contained menu bar app, no dependencies.
set -euo pipefail
cd "$(dirname "$0")"
APP="MXControl.app"
BUNDLE_ID="com.theseriouspdx.mxcontrol"
# Quit any running instance first. `open` on an already-running app only brings
# it forward, so without this you keep using the previous binary and conclude
# the build did nothing — or worse, that permissions broke. Quitting via
# AppleScript lets applicationWillTerminate release any withheld button press.
if pgrep -qf "MXControl.app/Contents/MacOS/MXControl"; then
osascript -e 'quit app "MXControl"' 2>/dev/null ||
pkill -f "MXControl.app/Contents/MacOS/MXControl" || true
sleep 1
echo "quit running instance"
fi
rm -rf "$APP"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cp MXControl/Info.plist "$APP/Contents/Info.plist"
cp MXControl/Resources/* "$APP/Contents/Resources/"
# Stamp the copied plist; the source plist stays a template and is never edited
# for a release. The displayed version is the VERSION file; the build number is
# the commit count, which only ever increases. -dev marks any build that is not
# exactly a tagged commit with a clean tree, so a build from uncommitted code
# can never be mistaken for a release.
VERSION="$(cat VERSION)"
COMMITS="$(git rev-list --count HEAD 2>/dev/null || echo 0)"
SUFFIX=""
if [ -n "$(git status --porcelain 2>/dev/null)" ] ||
! git describe --exact-match --tags HEAD >/dev/null 2>&1; then
SUFFIX="-dev"
fi
plutil -replace CFBundleShortVersionString -string "$VERSION$SUFFIX" "$APP/Contents/Info.plist"
plutil -replace CFBundleVersion -string "$COMMITS" "$APP/Contents/Info.plist"
swiftc -O \
-o "$APP/Contents/MacOS/MXControl" \
MXControl/HIDPP.swift \
MXControl/MXDevice.swift \
MXControl/MXController.swift \
MXControl/Bindings.swift \
MXControl/Actions.swift \
MXControl/SecretStore.swift \
MXControl/UIDriver.swift \
MXControl/ChordEngine.swift \
MXControl/Diagnostics.swift \
MXControl/ChordDetector.swift \
MXControl/ButtonChips.swift \
MXControl/MacroMenuRow.swift \
MXControl/MouseDiagramView.swift \
MXControl/DeviceSettingsView.swift \
MXControl/BindingsWindow.swift \
MXControl/main.swift
# Sign with the dedicated self-signed identity. This matters more than it looks:
# it makes the designated requirement
# identifier "com.theseriouspdx.mxcontrol" and certificate root = H"..."
# which is stable across rebuilds. An ad-hoc signature ties the requirement to
# the cdhash instead, so every rebuild silently revokes Input Monitoring.
# Inherited attributes can invalidate the seal, so clear them before signing.
xattr -cr "$APP" 2>/dev/null || true
IDENTITY="${MXCONTROL_IDENTITY:-MX Control Signing}"
# Note: no -v here. A self-signed cert reports CSSMERR_TP_NOT_TRUSTED and is
# filtered out by -v, but codesign signs with it happily.
if security find-identity 2>/dev/null | grep -q "$IDENTITY"; then
codesign --force --sign "$IDENTITY" --identifier "$BUNDLE_ID" "$APP"
else
codesign --force --sign - --identifier "$BUNDLE_ID" "$APP"
echo
echo "warning: signing identity '$IDENTITY' not found — signed ad-hoc."
echo " Input Monitoring and Accessibility will be revoked on EVERY"
echo " rebuild. Run ./scripts/gen-signing-cert.sh once to fix this."
echo
fi
# Strip inherited extended attributes before signing, and re-register with
# LaunchServices afterwards. Without this, a changed bundle can be refused as
# "damaged or incomplete" even though the signature itself is valid.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
-f "$APP" >/dev/null 2>&1 || true
echo "built $APP $VERSION$SUFFIX ($COMMITS) — run: open $APP"