forked from Dimillian/CodexMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacos-fix-openssl.sh
More file actions
executable file
·126 lines (107 loc) · 4.56 KB
/
macos-fix-openssl.sh
File metadata and controls
executable file
·126 lines (107 loc) · 4.56 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
#!/usr/bin/env bash
set -euo pipefail
app_path="${1:-src-tauri/target/release/bundle/macos/Codex Monitor.app}"
identity="${CODESIGN_IDENTITY:-}"
entitlements_path="${ENTITLEMENTS_PATH:-src-tauri/Entitlements.plist}"
if [[ -z "${identity}" ]]; then
echo "CODESIGN_IDENTITY is required. Example:"
echo " CODESIGN_IDENTITY='Developer ID Application: Your Name (TEAMID)' $0"
exit 1
fi
if [[ ! -d "${app_path}" ]]; then
echo "App bundle not found: ${app_path}"
exit 1
fi
codesign_entitlements=()
if [[ -f "${entitlements_path}" ]]; then
echo "Using entitlements: ${entitlements_path}"
codesign_entitlements=(--entitlements "${entitlements_path}")
else
echo "Warning: entitlements file not found at ${entitlements_path}; signing without entitlements."
fi
openssl_prefix=""
if command -v brew >/dev/null 2>&1; then
openssl_prefix="$(brew --prefix openssl@3 2>/dev/null || true)"
fi
if [[ -z "${openssl_prefix}" ]]; then
if [[ -d "/opt/homebrew/opt/openssl@3" ]]; then
openssl_prefix="/opt/homebrew/opt/openssl@3"
elif [[ -d "/usr/local/opt/openssl@3" ]]; then
openssl_prefix="/usr/local/opt/openssl@3"
fi
fi
if [[ -z "${openssl_prefix}" ]]; then
echo "OpenSSL@3 not found. Install it with Homebrew first."
exit 1
fi
libssl="${openssl_prefix}/lib/libssl.3.dylib"
libcrypto="${openssl_prefix}/lib/libcrypto.3.dylib"
frameworks_dir="${app_path}/Contents/Frameworks"
bin_path="${app_path}/Contents/MacOS/codex-monitor"
daemon_path="${app_path}/Contents/MacOS/codex_monitor_daemon"
daemonctl_path="${app_path}/Contents/MacOS/codex_monitor_daemonctl"
daemon_source="${DAEMON_BINARY_PATH:-src-tauri/target/release/codex_monitor_daemon}"
daemonctl_source="${DAEMONCTL_BINARY_PATH:-src-tauri/target/release/codex_monitor_daemonctl}"
copy_if_missing() {
local source_path="$1"
local destination_path="$2"
local label="$3"
if [[ -f "${destination_path}" ]]; then
return
fi
if [[ -f "${source_path}" ]]; then
cp -f "${source_path}" "${destination_path}"
chmod +x "${destination_path}"
echo "Bundled ${label} binary from ${source_path}"
else
echo "Warning: ${label} binary not found in app or at ${source_path}"
fi
}
copy_if_missing "${daemon_source}" "${daemon_path}" "daemon"
copy_if_missing "${daemonctl_source}" "${daemonctl_path}" "daemonctl"
if [[ ! -f "${libssl}" || ! -f "${libcrypto}" ]]; then
echo "OpenSSL dylibs not found at ${openssl_prefix}/lib"
exit 1
fi
mkdir -p "${frameworks_dir}"
cp -f "${libssl}" "${frameworks_dir}/"
cp -f "${libcrypto}" "${frameworks_dir}/"
install_name_tool -id "@rpath/libssl.3.dylib" "${frameworks_dir}/libssl.3.dylib"
install_name_tool -id "@rpath/libcrypto.3.dylib" "${frameworks_dir}/libcrypto.3.dylib"
for candidate in \
"${libcrypto}" \
"/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib" \
"/usr/local/opt/openssl@3/lib/libcrypto.3.dylib" \
"/opt/homebrew/Cellar/openssl@3/3.6.0/lib/libcrypto.3.dylib" \
"/usr/local/Cellar/openssl@3/3.6.0/lib/libcrypto.3.dylib"
do
install_name_tool -change "${candidate}" "@rpath/libcrypto.3.dylib" "${frameworks_dir}/libssl.3.dylib" 2>/dev/null || true
done
for candidate in \
"${libssl}" \
"/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib" \
"/usr/local/opt/openssl@3/lib/libssl.3.dylib"
do
install_name_tool -change "${candidate}" "@rpath/libssl.3.dylib" "${bin_path}" 2>/dev/null || true
done
for candidate in \
"${libcrypto}" \
"/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib" \
"/usr/local/opt/openssl@3/lib/libcrypto.3.dylib"
do
install_name_tool -change "${candidate}" "@rpath/libcrypto.3.dylib" "${bin_path}" 2>/dev/null || true
done
if ! otool -l "${bin_path}" | { command -v rg >/dev/null 2>&1 && rg -q "@executable_path/../Frameworks" || grep -q "@executable_path/../Frameworks"; }; then
install_name_tool -add_rpath "@executable_path/../Frameworks" "${bin_path}"
fi
codesign --force --options runtime --timestamp --sign "${identity}" "${frameworks_dir}/libcrypto.3.dylib"
codesign --force --options runtime --timestamp --sign "${identity}" "${frameworks_dir}/libssl.3.dylib"
codesign --force --options runtime --timestamp --sign "${identity}" "${codesign_entitlements[@]}" "${bin_path}"
if [[ -f "${daemon_path}" ]]; then
codesign --force --options runtime --timestamp --sign "${identity}" "${codesign_entitlements[@]}" "${daemon_path}"
fi
if [[ -f "${daemonctl_path}" ]]; then
codesign --force --options runtime --timestamp --sign "${identity}" "${codesign_entitlements[@]}" "${daemonctl_path}"
fi
codesign --force --options runtime --timestamp --sign "${identity}" "${codesign_entitlements[@]}" "${app_path}"
echo "Bundled OpenSSL dylibs and re-signed ${app_path}"