From 8e928e8d8076f7120decb20fa1bc273766d93e6d Mon Sep 17 00:00:00 2001 From: Andrew Hershberger Date: Wed, 20 Apr 2022 06:35:15 -0500 Subject: [PATCH] Avoid overwriting hard-coded MBXAccessToken (#1285) --- scripts/insert_access_token.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/insert_access_token.sh b/scripts/insert_access_token.sh index acc49f0742fe..838861b70df5 100755 --- a/scripts/insert_access_token.sh +++ b/scripts/insert_access_token.sh @@ -5,11 +5,17 @@ token_file=~/.mapbox token_file2=~/mapbox token="$(cat $token_file 2>/dev/null || cat $token_file2 2>/dev/null)" plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" -if [ "$token" ]; then - plutil -replace MBXAccessToken -string "$token" "$plist" - echo "Token insertion successful" -elif /usr/libexec/PlistBuddy -c "Print :MBXAccessToken" "$plist"; then - echo \'error: Missing Mapbox access token\' - echo "error: Get an access token from , then create a new file at ~/.mapbox that contains the access token." - exit 1 + +# Only overwrite or error if the Info.plist contains the MBXAccessToken key with an empty value +# This allows overriding ~/.mapbox and ~/mapbox by editing the Info.plist directly and avoids +# emitting an error if the Info.plist is not configured to need an access token. +if existing_value="$(/usr/libexec/PlistBuddy -c "Print :MBXAccessToken" "$plist")" && [ -z "$existing_value" ]; then + if [ "$token" ]; then + plutil -replace MBXAccessToken -string "$token" "$plist" + echo "Token insertion successful" + else + echo \'error: Missing Mapbox access token\' + echo "error: Get an access token from , then create a new file at ~/.mapbox that contains the access token." + exit 1 + fi fi