forked from HeidiSQL/HeidiSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-macos-app.sh
More file actions
executable file
·326 lines (258 loc) · 9.47 KB
/
Copy pathcreate-macos-app.sh
File metadata and controls
executable file
·326 lines (258 loc) · 9.47 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/usr/bin/env bash
set -euo pipefail
DO_NOTARIZE=false
# parse args
for arg in "$@"; do
case "$arg" in
--notarize) DO_NOTARIZE=true ;;
esac
done
### CONFIGURATION
APP_NAME="heidisql"
BUNDLE_NAME="${APP_NAME}.app"
APP_DIR="$(pwd)/${BUNDLE_NAME}"
# Path to the already built Lazarus executable
EXECUTABLE_SRC="$(pwd)/out/heidisql"
EXECUTABLE_TRG="${APP_DIR}/Contents/MacOS/${APP_NAME}"
# Homebrew prefix (auto-detected; override if needed)
BREW_PREFIX="$(brew --prefix 2>/dev/null || echo "/opt/homebrew")"
# Your Developer ID identity, as shown by: security find-identity -v -p codesigning
TEAM_ID="QBD4CC6FH3"
CODESIGN_IDENTITY="Developer ID Application: Ansgar Becker (${TEAM_ID})"
# Name for notarytool keychain profile (store once with notarytool store-credentials)
NOTARY_PROFILE="notarytool-profile"
LOCALES_ZIP_URL="https://www.heidisql.com/downloads/locale/HeidiSQL-locale.zip"
### INSTALL REQUIRED LIBRARIES VIA HOMEBREW
# MySQL client (libmysqlclient.dylib)
brew list mysql-client >/dev/null 2>&1 || brew install mysql-client
# PostgreSQL client (libpq.dylib)
brew list libpq >/dev/null 2>&1 || brew install libpq
# SQLite (libsqlite3.dylib; comes with macOS, but install via brew for consistency)
brew list sqlite >/dev/null 2>&1 || brew install sqlite
# MariaDB Connector/C (libmariadb*.dylib)
brew list mariadb-connector-c >/dev/null 2>&1 || brew install mariadb-connector-c
# OpenSSL 1.1 for TFPHTTPClient
brew list openssl@1.1 >/dev/null 2>&1 || brew install openssl@1.1
MYSQL_LIB_DIR="${BREW_PREFIX}/opt/mysql-client/lib"
PG_LIB_DIR="${BREW_PREFIX}/opt/libpq/lib"
SQLITE_LIB_DIR="${BREW_PREFIX}/opt/sqlite/lib"
MARIADB_LIB_DIR="${BREW_PREFIX}/opt/mariadb-connector-c/lib"
MYSQL_PLUGIN_DIR="${MYSQL_LIB_DIR}/plugin"
MARIADB_PLUGIN_DIR="${MARIADB_LIB_DIR}/mariadb/plugin"
OPENSSL11_LIB_DIR="${BREW_PREFIX}/opt/openssl@1.1/lib"
### PREPARE APP BUNDLE STRUCTURE
rm -rf "${APP_DIR}"
mkdir -p "${APP_DIR}/Contents/MacOS"
mkdir -p "${APP_DIR}/Contents/Resources"
mkdir -p "${APP_DIR}/Contents/Frameworks" # where we will put .dylib and .so files
# Copy main executable
cp "${EXECUTABLE_SRC}" "${EXECUTABLE_TRG}"
chmod +x "${EXECUTABLE_TRG}"
codesign --force --options runtime --timestamp --sign "${CODESIGN_IDENTITY}" "${EXECUTABLE_TRG}"
# Minimal Info.plist (adjust identifiers/versions as needed)
cat > "${APP_DIR}/Contents/Info.plist" <<EOF
<?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>${APP_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.example.${APP_NAME}</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleExecutable</key>
<string>${APP_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSMinimumSystemVersion</key>
<string>15.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleIconFile</key>
<string>heidisql</string>
</dict>
</plist>
EOF
### COPY INI FILES INTO RESOURCES
cp extra/ini/*.ini "${APP_DIR}/Contents/Resources/"
cp res/heidisql.icns "${APP_DIR}/Contents/Resources/"
### FUNCTION: COPY A DYLIB AND ITS DEPENDENCIES
copy_and_rewrite_dylib() {
local src_dylib="$1"
local dest_dir="${APP_DIR}/Contents/Frameworks"
mkdir -p "${dest_dir}"
local base
base="$(basename "${src_dylib}")"
local dest_dylib="${dest_dir}/${base}"
# If already copied, skip
if [[ -f "${dest_dylib}" ]]; then
return
fi
echo "Copying ${src_dylib} -> ${dest_dylib}"
cp "${src_dylib}" "${dest_dylib}"
# Make it writable for install_name_tool
chmod u+w "${dest_dylib}"
# Change its own install name to @rpath/@loader_path-style inside the app
install_name_tool -id "@rpath/${base}" "${dest_dylib}"
# Find direct dependencies
local deps
# otool -L output: first line is the file itself, subsequent lines are dependencies
deps=$(otool -L "${dest_dylib}" | tail -n +2 | awk '{print $1}')
for dep in ${deps}; do
case "${dep}" in
/usr/lib/*|/System/*)
# System libraries: keep them as-is, do not copy
continue
;;
esac
# If dependency already points into @rpath/@loader_path, just rewrite to Frameworks
local dep_base
dep_base="$(basename "${dep}")"
local new_dep_path="@loader_path/../Frameworks/${dep_base}"
echo " Rewriting dep ${dep} -> ${new_dep_path}"
install_name_tool -change "${dep}" "${new_dep_path}" "${dest_dylib}"
# If dep is an absolute path, copy that dylib too
if [[ -f "${dep}" ]]; then
copy_and_rewrite_dylib "${dep}"
fi
done
}
### COPY CLIENT LIBRARIES AND DEPENDENCIES
# libmysqlclient.dylib
if ls "${MYSQL_LIB_DIR}"/libmysqlclient*.dylib >/dev/null 2>&1; then
for f in "${MYSQL_LIB_DIR}"/libmysqlclient*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libmysqlclient*.dylib found in ${MYSQL_LIB_DIR}" >&2
fi
# libpq.dylib
if [[ -f "${PG_LIB_DIR}/libpq.dylib" ]]; then
copy_and_rewrite_dylib "${PG_LIB_DIR}/libpq.dylib"
else
# libpq often has versioned names
if ls "${PG_LIB_DIR}"/libpq*.dylib >/dev/null 2>&1; then
for f in "${PG_LIB_DIR}"/libpq*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libpq*.dylib found in ${PG_LIB_DIR}" >&2
fi
fi
# libsqlite3.dylib
if [[ -f "${SQLITE_LIB_DIR}/libsqlite3.dylib" ]]; then
copy_and_rewrite_dylib "${SQLITE_LIB_DIR}/libsqlite3.dylib"
elif ls "${SQLITE_LIB_DIR}"/libsqlite3*.dylib >/dev/null 2>&1; then
for f in "${SQLITE_LIB_DIR}"/libsqlite3*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libsqlite3*.dylib found in ${SQLITE_LIB_DIR}" >&2
fi
# libmariadb*.dylib (MariaDB Connector/C)
if ls "${MARIADB_LIB_DIR}"/libmariadb*.dylib >/dev/null 2>&1; then
for f in "${MARIADB_LIB_DIR}"/libmariadb*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libmariadb*.dylib found in ${MARIADB_LIB_DIR}" >&2
fi
# MARIADB PLUGIN .so FILES
if ls "${MARIADB_PLUGIN_DIR}"/*.so >/dev/null 2>&1; then
for f in "${MARIADB_PLUGIN_DIR}"/*.so; do
[[ -f "${f}" ]] || continue
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: MariaDB plugin directory not found: ${MARIADB_PLUGIN_DIR}" >&2
fi
# MYSQL PLUGIN .so FILES
if ls "${MYSQL_PLUGIN_DIR}"/*.so >/dev/null 2>&1; then
for f in "${MYSQL_PLUGIN_DIR}"/*.so; do
[[ -f "${f}" ]] || continue
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: MySQL plugin directory not found: ${MYSQL_PLUGIN_DIR}" >&2
fi
# libssl.1.1.dylib and libcrypto.1.1.dylib (names may vary slightly)
if ls "${OPENSSL11_LIB_DIR}"/libssl*.1.1*.dylib >/dev/null 2>&1; then
for f in "${OPENSSL11_LIB_DIR}"/libssl*.1.1*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libssl*.1.1*.dylib found in ${OPENSSL11_LIB_DIR}" >&2
fi
if ls "${OPENSSL11_LIB_DIR}"/libcrypto*.1.1*.dylib >/dev/null 2>&1; then
for f in "${OPENSSL11_LIB_DIR}"/libcrypto*.1.1*.dylib; do
copy_and_rewrite_dylib "${f}"
done
else
echo "WARNING: No libcrypto*.1.1*.dylib found in ${OPENSSL11_LIB_DIR}" >&2
fi
### FIX MAIN EXECUTABLE’S REFERENCES TO CLIENT LIBS
# Helper: rewrite dependency of the main executable to bundled Frameworks
rewrite_exe_dep () {
local pattern="$1" # e.g. libmysqlclient
local dep
dep=$(otool -L "${EXECUTABLE_TRG}" | awk "/${pattern}.*dylib/ {print \$1}" | head -n1 || true)
if [[ -n "${dep}" ]]; then
local base
base="$(basename "${dep}")"
local new="@loader_path/../Frameworks/${base}"
echo "Rewriting ${EXECUTABLE_TRG} dep ${dep} -> ${new}"
chmod u+w "${EXECUTABLE_TRG}"
install_name_tool -change "${dep}" "${new}" "${EXECUTABLE_TRG}"
fi
}
rewrite_exe_dep "libmysqlclient"
rewrite_exe_dep "libpq"
rewrite_exe_dep "libsqlite3"
rewrite_exe_dep "libmariadb"
rewrite_exe_dep "libssl.3"
rewrite_exe_dep "libssl" # OpenSSL 1.1
rewrite_exe_dep "libcrypto"
### DOWNLOAD AND EXTRACT LOCALE FILES
if [[ -n "${LOCALES_ZIP_URL}" ]]; then
LOCALE_DEST="${APP_DIR}/Contents/Resources/locale"
mkdir -p "${LOCALE_DEST}"
TMP_ZIP="$(mktemp -t heidisql_locales.XXXXXX).zip"
echo "Downloading locales from ${LOCALES_ZIP_URL}..."
curl -L --fail --show-error "${LOCALES_ZIP_URL}" -o "${TMP_ZIP}"
echo "Extracting locales to ${LOCALE_DEST}..."
/usr/bin/unzip -o "${TMP_ZIP}" -d "${LOCALE_DEST}" >/dev/null
rm -f "${TMP_ZIP}"
fi
echo "Done. Bundled app is at: ${APP_DIR}"
### SIGN ALL DYLIBS AND THE APP BUNDLE
echo "Signing embedded libraries..."
find "${APP_DIR}/Contents" -type f \( -name "*.dylib" -o -name "*.so" \) | while read -r f; do
echo " Signing ${f}"
codesign --force --options runtime --timestamp --sign "${CODESIGN_IDENTITY}" "${f}"
done
echo "Signing main app bundle..."
codesign --force --options runtime --timestamp --deep --sign "${CODESIGN_IDENTITY}" "${APP_DIR}"
echo "Verifying code signature..."
codesign --verify --deep --strict --verbose=2 "${APP_DIR}"
### ZIP, NOTARIZE, AND STAPLE
if ! $DO_NOTARIZE; then
echo "Skip notarization (--notarize not given)"
exit 0
fi
ZIP_PATH="${APP_DIR}.zip"
rm -f "${ZIP_PATH}"
echo "Zipping app for notarization..."
/usr/bin/zip -r -y "${ZIP_PATH}" "${BUNDLE_NAME}"
echo "Submitting to Apple notary service..."
xcrun notarytool submit "${ZIP_PATH}" \
--keychain-profile "${NOTARY_PROFILE}" \
--team-id "${TEAM_ID}" \
--wait
echo "Stapling notarization ticket..."
xcrun stapler staple "${APP_DIR}"
echo "Notarization complete. Distribute: ${APP_DIR}"