-
Notifications
You must be signed in to change notification settings - Fork 82
/
mockingbird
executable file
·61 lines (52 loc) · 2.14 KB
/
mockingbird
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
#!/usr/bin/env bash
# ::DESCRIPTION
# Launcher that downloads a versioned release artifact if no executable exists.
#
# ::OVERRIDES
# Usage: export <option>=<value>
# - MKB_VERSION: The release artifact version.
# - MKB_ARTIFACTS_URL: A templated URL in the format `https://example.com/<VERSION>/<FILE>`.
# - MKB_NO_VERIFY: Disable verifying the code signature of downloaded artifacts.
set -eu
readonly srcroot="$(dirname "$0")"
pushd . > /dev/null
cd "${srcroot}"
function getVersion {
/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' Sources/MockingbirdCli/Info.plist
}
readonly version="${MKB_VERSION:-"$(getVersion)"}"
echo "Using Mockingbird v${version}"
readonly binDir="bin"
readonly executable="${binDir}/${version}/mockingbird"
mkdir -p "${binDir}"
if [[ ! -x "${executable}" ]]; then
readonly archiveName='Mockingbird'
readonly archiveFileName="${archiveName}.zip"
curlOpts=( --progress-bar --location --output "${binDir}/${archiveFileName}" )
if [[ -n "${GH_ACCESS_TOKEN+x}" ]]; then
curlOpts+=( --header "Authorization: token ${GH_ACCESS_TOKEN}" )
fi
# Download
readonly artifactsUrl="${MKB_ARTIFACTS_URL:-https://github.com/birdrides/mockingbird/releases/download/<VERSION>/<FILE>}"
readonly downloadUrl="$(echo "${artifactsUrl}" | sed "s|<VERSION>|${version}|" | sed "s|<FILE>|${archiveFileName}|")"
echo "Downloading Mockingbird from ${downloadUrl} into ${binDir}/${version}"
curl "${curlOpts[@]}" "${downloadUrl}"
# Extract
unzip -oq "${binDir}/${archiveFileName}" -d "${binDir}"
rm "${binDir}/${archiveFileName}"
rm -rf "${binDir}/${version}"
mv -f "${binDir}/${archiveName}" "${binDir}/${version}"
# Verify
if [[ "${MKB_NO_VERIFY:-}" -ne 1 ]]; then
if xcrun codesign -vv -R Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/mockingbird.txt "${executable}"; then
echo '✅ Verified the code signature'
else
echo "error: Mockingbird does not have a valid code signature; set 'MKB_NO_VERIFY=1' to bypass this error at your own risk"
rm "${executable}"
exit 1
fi
fi
chmod u+x "${executable}"
fi
popd > /dev/null
MKB_LAUNCHER="$0" "${srcroot}/${executable}" "$@"