2
0
MasterPassword/platform-darwin/Scripts/updatePlist

71 lines
2.7 KiB
Plaintext
Raw Normal View History

2014-11-02 15:27:02 +00:00
#!/usr/bin/env bash
cd "${BASH_SOURCE%/*}"
source ./bashlib
trap 'c=$BASH_COMMAND s=$?; (( s )) && echo "ERROR: $s: $c"; exit $s' EXIT
set -e
2014-11-02 15:27:02 +00:00
cd ..
export PATH+=:/usr/libexec
addPlistWithKey() {
local key=$1 type=$2 value=$3 plist=${4:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Delete :'$key'" "$plist" 2>/dev/null || true
PlistBuddy -c "Add :'$key' '$type' '$value'" "$plist"
}
setPlistWithKey() {
local key=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Set :'$key' '$value'" "$plist"
}
getPlistWithKey() {
local key=$1 plist=${2:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Print :'$key'" "$plist"
}
setSettingWithTitle() {
local i title=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/Settings.bundle/Root.plist"}
for (( i=0; 1; ++i )); do
PlistBuddy -c "Print :PreferenceSpecifiers:$i" "$plist" &>/dev/null || break
inf "Checking preference specifier $i"
[[ $(PlistBuddy -c "Print :PreferenceSpecifiers:$i:Title" "$plist" 2>/dev/null) = $title ]] || continue
inf "Correct title, setting value."
PlistBuddy -c "Set :PreferenceSpecifiers:$i:DefaultValue $value" "$plist"
break
done
}
2017-04-14 04:43:34 +00:00
case $PLATFORM_NAME in
macosx) platform=mac ;;
2017-04-14 17:08:23 +00:00
iphone*) platform=ios ;;
2017-04-14 04:43:34 +00:00
*) ftl 'ERROR: Unknown platform: %s.' "$PLATFORM_NAME"; exit 1 ;;
esac
description=$(git describe --always --dirty --long --match "*-$platform*")
2017-04-14 04:43:34 +00:00
version=${description%-g*} build=${version##*-} version=${version%-$build}
version=${version//-$platform/} version=${version//-/.} commit=${description##*-g}
2014-11-02 15:27:02 +00:00
addPlistWithKey GITDescription string "$description"
2017-04-01 04:43:44 +00:00
setPlistWithKey CFBundleVersion "$(hr "${version%%.*}" 14).${version#*.}"
setPlistWithKey CFBundleShortVersionString "$version"
2014-11-02 15:27:02 +00:00
setSettingWithTitle "Build" "$commit"
setSettingWithTitle "Version" "$version"
setSettingWithTitle "Copyright" "$(getPlistWithKey NSHumanReadableCopyright)"
if [[ $DEPLOYMENT_LOCATION = YES ]]; then
# This build is a release. Do some release checks.
fabricPlist="$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Fabric.plist"
2014-11-02 15:27:02 +00:00
passed=1
[[ $description != *-dirty ]] || \
{ passed=0; err 'ERROR: Cannot release a dirty version, first commit any changes.'; }
2017-04-14 04:43:34 +00:00
[[ $build == 0 ]] || \
{ passed=0; err 'ERROR: Commit is not tagged for release, first tag accordingly.'; }
[[ -r "$fabricPlist" && $(PlistBuddy -c "Print :'API Key'" "$fabricPlist" 2>/dev/null) ]] || \
{ passed=0; err 'ERROR: Cannot release: Fabric API key is missing.'; }
2014-11-02 15:27:02 +00:00
(( passed )) || \
{ ftl "Failed to pass release checks. Fix the above errors and re-try. Aborting."; exit 1; }
fi