-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart-mac.sh
More file actions
executable file
·138 lines (109 loc) · 2.77 KB
/
start-mac.sh
File metadata and controls
executable file
·138 lines (109 loc) · 2.77 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
#!/usr/local/bin/bash-5.1
# shellcheck disable=SC1090,SC2155
set -o pipefail
readonly BuildServerKeychain=$HOME/Library/Keychains/BuildServer.keychain-db
# Ensure that critical variables are set in the config
check_config() {
if [[ -z $MacDeveloperID ]]; then
echo 'ERROR: MacDeveloperID (Developer ID Application creator) not set in config.' >&2
return 1
fi
if [[ -z $MacDevelopmentTeam ]]; then
echo 'ERROR: MacDevelopmentTeam (Xcode DEVELOPMENT_TEAM) is not set in config.' >&2
return 1
fi
return 0
}
get_default_keychains() {
declare -n Keychains=$1
shift
while read -r Keychain; do
Keychain=${Keychain#*\"}
Keychain=${Keychain%\"*}
Keychains+=("$Keychain")
done < <(security list-keychains -d user)
}
nproc() {
sysctl -n hw.ncpu
}
mac_target() {
declare MacOSVersion=$1
shift
export MACOSX_DEPLOYMENT_TARGET="$MacOSVersion"
}
make_dmg() {
declare VolumeName=$1
shift
declare Output=$1
shift
declare Ret=0
if mkdir image; then
rm -f "$Output"
if hdiutil create -size 300m -srcfolder ./image -volname "$VolumeName" -fs HFS+ -format UDRW "$Output" &&
hdiutil attach -readwrite -noverify -noautoopen "$Output" -mountpoint image; then
cp -a "$@" ./image &&
hdiutil detach ./image
Ret=$?
fi
rmdir image
fi
if (( Ret == 0 )); then
hdiutil convert "$Output" -format UDBZ -o "tmp$Output" &&
mv "tmp$Output" "$Output" &&
return
fi
return "$Ret"
}
mount_dmg() {
declare Image=$1
shift
declare Cmd=$1
shift
declare Ret=1
if TempDir=$(mktemp -d); then
if hdiutil attach -readonly -noverify -noautoopen "$Image" -mountpoint "$TempDir"; then
declare OrigPwd=$(pwd)
pushd "$TempDir" &>/dev/null &&
call "$Cmd" "$OrigPwd" "$@"
Ret=$?
popd &> /dev/null || Ret=$?
hdiutil detach "$TempDir"
fi
rmdir "$TempDir"
fi
return "$Ret"
}
sign_app() {
declare Bundle=$1
shift
codesign --timestamp --options=runtime -s "Developer ID Application: $MacDeveloperID" -f --deep "$Bundle"
}
main() {
# Load modules and configuration
cd "${0%/*}" || return
# Find Xcode SDKs path
MacSdkPath=$(xcrun --show-sdk-path)
MacSdkPath=${MacSdkPath%/MacOSX.sdk}
. ~/Library/Preferences/BuildServer/config.sh
check_config || return
declare Module
for Module in modules/*.sh mac/*.sh; do
. "$Module"
done
cd ..
# shellcheck disable=SC2034
declare -g BaseWorkingDir=$(pwd)
# Start building
parse_args "$@"
shift $((OPTIND-1))
# We need to change the default keychain and set it back for Xcode
declare DefaultKeychains=()
get_default_keychains DefaultKeychains
security unlock-keychain -p "$KeychainPassword" "$BuildServerKeychain" || return
security list-keychains -d user -s "$BuildServerKeychain" || return
run_builds
declare Ret=$?
security list-keychains -d user -s "${DefaultKeychains[@]}"
return "$Ret"
}
main "$@" || exit