Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·88 lines (72 loc) · 2.83 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·88 lines (72 loc) · 2.83 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
#!/bin/bash
#
# Build and sign LoginScriptPlugin.bundle with clang, without the Xcode
# project. The result is written to build/LoginScriptPlugin.bundle.
#
# Usage:
# ./build.sh "Apple Development: Your Name (TEAMID)"
#
# Run it without arguments to list the signing identities in your keychain.
#
# Optional environment variables:
# ARCHS architectures to build (default: this Mac's, e.g. arm64)
# MIN_MACOS oldest macOS version the plugin should load on (default: 11.0)
# BUNDLE_ID bundle identifier (default: local.LoginScriptPlugin)
set -o errexit
set -o nounset
set -o pipefail
declare -r PLUGIN="LoginScriptPlugin"
declare -r BUNDLE="build/$PLUGIN.bundle"
ARCHS="${ARCHS:-$(uname -m)}"
MIN_MACOS="${MIN_MACOS:-11.0}"
BUNDLE_ID="${BUNDLE_ID:-local.$PLUGIN}"
function usage() {
echo "Usage: $(basename "$0") \"<signing identity>\""
echo
echo "Signing identities in your keychain:"
security find-identity -v -p codesigning | sed 's/^/ /'
}
function main() {
local identity="${1:-}"
local arch_flags=()
local arch
if [[ -z "$identity" ]]; then
usage
return 64 # EX_USAGE
fi
# Build from the repository root with relative paths, so the binary
# doesn't contain the path of your checkout.
cd "$(dirname "$0")"
for arch in $ARCHS; do
arch_flags+=(-arch "$arch")
done
echo "* Building $BUNDLE ($ARCHS, macOS $MIN_MACOS or later)"
rm -rf "$BUNDLE"
mkdir -p "$BUNDLE/Contents/MacOS"
# Fill in the Xcode placeholders in Info.plist.
sed -e 's/\$(EXECUTABLE_NAME)/'"$PLUGIN"'/' \
-e 's/\$(PRODUCT_BUNDLE_IDENTIFIER)/'"$BUNDLE_ID"'/' \
-e 's/\$(PRODUCT_NAME)/'"$PLUGIN"'/' \
"$PLUGIN/Info.plist" > "$BUNDLE/Contents/Info.plist"
# asl_log() is deprecated but still compiles, and the #warning is about
# the *-user script modes, which run in root's session.
clang "${arch_flags[@]}" -bundle -O2 -mmacosx-version-min="$MIN_MACOS" \
-Wno-deprecated-declarations -Wno-#warnings \
-framework Security -framework CoreFoundation \
-o "$BUNDLE/Contents/MacOS/$PLUGIN" "$PLUGIN/$PLUGIN.c"
echo "* Signing with \"$identity\""
if [[ "$identity" == "-" ]]; then
echo "Warning: ad-hoc signatures haven't been tested, macOS may refuse to load the plugin"
codesign --force --options runtime --sign - "$BUNDLE"
elif ! codesign --force --options runtime --timestamp --sign "$identity" "$BUNDLE"; then
echo
echo "Signing failed. If the error was errSecInternalComponent and you're"
echo "connected over SSH, unlock your keychain and run this script again:"
echo " security unlock-keychain ~/Library/Keychains/login.keychain-db"
return 1
fi
codesign --verify --strict --verbose=2 "$BUNDLE"
echo "* Built $(pwd)/$BUNDLE"
return 0
}
main "$@"