2
0
MasterPassword/Scripts/updatePlist

63 lines
2.3 KiB
Plaintext
Raw Normal View History

2014-11-02 15:27:02 +00:00
#!/usr/bin/env bash
cd "${BASH_SOURCE%/*}"
source ./bashlib
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
}
description=$(git describe --always --dirty --long --match '*-release')
version=${description%-g*}
release=${version%%-*} build=${version##*-}
printf -v version '%s.%d' "$release" "$build"
printf -v commit '%s' "${description##*-g}"
2014-11-02 15:27:02 +00:00
addPlistWithKey GITDescription string "$description"
setPlistWithKey CFBundleVersion "$version"
setPlistWithKey CFBundleShortVersionString "$release"
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.
crashlyticsPlist="$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Crashlytics.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.'; }
[[ -r "$crashlyticsPlist" && $(PlistBuddy -c "Print :'API Key'" "$crashlyticsPlist" 2>/dev/null) ]] || \
2014-11-02 15:27:02 +00:00
{ passed=0; err 'ERROR: Cannot release: Crashlytics API key is missing.'; }
(( passed )) || \
{ ftl "Failed to pass release checks. Fix the above errors and re-try. Aborting."; exit 1; }
fi