Skip to content

Commit

Permalink
Avoid overwriting hard-coded MBXAccessToken (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
macdrevx authored Apr 20, 2022
1 parent eb8c74b commit 8e928e8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions scripts/insert_access_token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.mapbox.com/studio/account/tokens/>, 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 <https://www.mapbox.com/studio/account/tokens/>, then create a new file at ~/.mapbox that contains the access token."
exit 1
fi
fi

0 comments on commit 8e928e8

Please sign in to comment.