|
5 | 5 | # |
6 | 6 | # Copyright © 2019 LoopKit Authors. All rights reserved. |
7 | 7 |
|
8 | | -echo "Gathering build details in ${SRCROOT}" |
9 | | -cd "${SRCROOT}" |
| 8 | +SCRIPT="$(basename "${0}")" |
| 9 | +SCRIPT_DIRECTORY="$(dirname "${0}")" |
10 | 10 |
|
11 | | -plist="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}" |
| 11 | +error() { |
| 12 | + echo "ERROR: ${*}" >&2 |
| 13 | + echo "Usage: ${SCRIPT} [-r|--git-source-root git-source-root] [-p|--provisioning-profile-path provisioning-profile-path] [-i|--info-plist-path info-plist-path]" >&2 |
| 14 | + echo "Parameters:" >&2 |
| 15 | + echo " -r|--git-source-root <git-source-root> root location of git repository to gather information from; optional, defaults to \${WORKSPACE_ROOT} if present, otherwise defaults to \${SRCROOT}" >&2 |
| 16 | + echo " -p|--provisioning-profile-path <provisioning-profile-path> path to the .mobileprovision provisioning profile file to check for expiration; optional, defaults to \${HOME}/Library/MobileDevice/Provisioning Profiles/\${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" >&2 |
| 17 | + echo " -i|--info-plist-path <info-plist-path> path to the Info.plist file to modify; optional, defaults to \${BUILT_PRODUCTS_DIR}/\${INFOPLIST_PATH}" >&2 |
| 18 | + exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +warn() { |
| 22 | + echo "WARN: ${*}" >&2 |
| 23 | +} |
| 24 | + |
| 25 | +info() { |
| 26 | + echo "INFO: ${*}" >&2 |
| 27 | +} |
| 28 | + |
| 29 | +git_source_root="${WORKSPACE_ROOT:-${SRCROOT}}" |
| 30 | +info_plist_path="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}" |
| 31 | +provisioning_profile_path="${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" |
| 32 | +xcode_build_version=${XCODE_PRODUCT_BUILD_VERSION:-$(xcodebuild -version | grep version | cut -d ' ' -f 3)} |
| 33 | +while [[ $# -gt 0 ]] |
| 34 | +do |
| 35 | + case $1 in |
| 36 | + -r|--git-source-root) |
| 37 | + git_source_root="${2}" |
| 38 | + shift 2 |
| 39 | + ;; |
| 40 | + -i|--info-plist-path) |
| 41 | + info_plist_path="${2}" |
| 42 | + shift 2 |
| 43 | + ;; |
| 44 | + -p|--provisioning-profile-path) |
| 45 | + provisioning_profile_path="${2}" |
| 46 | + shift 2 |
| 47 | + ;; |
| 48 | + esac |
| 49 | +done |
| 50 | + |
| 51 | +if [ ${#} -ne 0 ]; then |
| 52 | + error "Unexpected arguments: ${*}" |
| 53 | +fi |
| 54 | + |
| 55 | +if [ -z "${git_source_root}" ]; then |
| 56 | + error "Must provide one of --git-source-root, \${WORKSPACE_ROOT}, or \${SRCROOT}." |
| 57 | +fi |
| 58 | + |
| 59 | +if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then |
| 60 | + error "Must provide valid --info-plist-path, or have valid \${BUILT_PRODUCTS_DIR} and \${INFOPLIST_PATH} set." |
| 61 | +fi |
| 62 | + |
| 63 | +info "Gathering build details in ${git_source_root}" |
| 64 | +cd "${git_source_root}" |
12 | 65 |
|
13 | 66 | if [ -e .git ]; then |
14 | 67 | rev=$(git rev-parse HEAD) |
15 | | - plutil -replace com-loopkit-Loop-git-revision -string ${rev} "${plist}" |
16 | | - branch=$(git branch | grep \* | cut -d ' ' -f2-) |
17 | | - plutil -replace com-loopkit-Loop-git-branch -string "${branch}" "${plist}" |
18 | | -fi; |
19 | | -plutil -replace com-loopkit-Loop-srcroot -string "${SRCROOT}" "${plist}" |
20 | | -plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${plist}" |
21 | | -plutil -replace com-loopkit-Loop-xcode-version -string "${XCODE_PRODUCT_BUILD_VERSION}" "${plist}" |
| 68 | + plutil -replace com-loopkit-Loop-git-revision -string ${rev} "${info_plist_path}" |
| 69 | + branch=$(git branch --show-current) |
| 70 | + if [ -n "$branch" ]; then |
| 71 | + plutil -replace com-loopkit-Loop-git-branch -string "${branch}" "${info_plist_path}" |
| 72 | + else |
| 73 | + warn "No git branch found, not setting com-loopkit-Loop-git-branch" |
| 74 | + fi |
| 75 | +fi |
| 76 | + |
| 77 | +plutil -replace com-loopkit-Loop-srcroot -string "${git_source_root}" "${info_plist_path}" |
| 78 | +plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${info_plist_path}" |
| 79 | +plutil -replace com-loopkit-Loop-xcode-version -string "${xcode_build_version}" "${info_plist_path}" |
| 80 | + |
| 81 | +if [ -e "${provisioning_profile_path}" ]; then |
| 82 | + profile_expire_date=$(security cms -D -i "${provisioning_profile_path}" | plutil -p - | grep ExpirationDate | cut -b 23-) |
| 83 | + # Convert to plutil format |
| 84 | + profile_expire_date=$(date -j -f "%Y-%m-%d %H:%M:%S" "${profile_expire_date}" +"%Y-%m-%dT%H:%M:%SZ") |
| 85 | + plutil -replace com-loopkit-Loop-profile-expiration -date "${profile_expire_date}" "${info_plist_path}" |
| 86 | +else |
| 87 | + warn "Invalid provisioning profile path ${provisioning_profile_path}" |
| 88 | +fi |
22 | 89 |
|
| 90 | +info "Added ${profile_expire_date} as profile expiration to ${info_plist_path}" |
0 commit comments