One of the pain points observed when upgrading SAP BI Mobile SDK for iOS is migrating the preferences specified in DefaultSettings.plist file.This article provides a sample script to migrate the preferences.

We will be looking at two different approaches to write shell scripts.

Approach 1: Writing a shell script to overwrite specific values of the plist.

Let’s consider the customization of the following 3 features:

  1. feature.email.enabled.default
  2. feature.streamwork.enabled.default
  3. feature.predefinedconnections.list.default:0

Sample script:

MOBI_BASE_PLIST=“./DefaultSettings_v5.0.plist”

MOBI_MODIFIED_PLIST=“./DefaultSettings_v4.4.plist”

MOBI_NEW_PLIST=“./DefaultSettings_v5.0.plist”



declare -a cust_arr=( \

“Customizations:feature.email.enabled.default” \

“Customizations:feature.streamwork.enabled.default” \

“Customizations:feature.addconnection.SUP.enabled.default” \

“Customizations:feature.predefinedconnections.list.default:0” \

)

echo “The script uses files in following locations, please exit and change the paths in script if needed: “

echo “Base version of file: [${MOBI_BASE_PLIST}]”

echo “Customized version of file: [${MOBI_MODIFIED_PLIST}]”

echo “”

echo “##################################################################”

echo “”

read -p “Do you want to proceed? “ -n 1 -r

echo

if [[ ! $REPLY =~ ^[Yy]$ ]]

then

exit 1

fi


# Loop through the items in the array.

for i in ${cust_arr[@]}

do

MOBI_MODIFIED_VAL=$(/usr/libexec/PlistBuddy -c “Print :$i” “${MOBI_MODIFIED_PLIST}”)

if [ “$?” == “0” ] #Proceed only if entry exists in modified file

then

MOBI_ORIG_VAL=$(/usr/libexec/PlistBuddy -c “Print :$i” “${MOBI_BASE_PLIST}”)

if [ “$?” == “0” ]

then

if [ “$MOBI_ORIG_VAL” != “$MOBI_MODIFIED_VAL” ]

then

echo Customization found: $i is changed from $MOBI_ORIG_VAL to $MOBI_MODIFIED_VAL.

/usr/libexec/PlistBuddy -c “Set :$i ${MOBI_MODIFIED_VAL}” “${MOBI_NEW_PLIST}”

fi

else

/usr/libexec/PlistBuddy -c “Add :$i string ${MOBI_MODIFIED_VAL}” “${MOBI_NEW_PLIST}”

fi

fi

done

if [ “$?” != “0” ]

then

  clear

  echo “##################################################################”

  echo “Script run is complete. No customizations were detected.”

  echo “”

  echo “If you are sure that you had performed customizations, ensure that following information is correct, and you have sufficient read/write permissions: “

  echo “”

  echo “Base version of the file: [${MOBI_BASE_PLIST}]”

  echo “Customized version of the file: [${MOBI_MODIFIED_PLIST}]”

  echo “##################################################################”

fi

Approach 2: Writing a shell script that generates a shell script to overwrite specific values of the plist.

This script generates another script file(runGeneratedOverrides.sh in our example).

Let’s consider the customization of the following 3 features:

  1. feature.email.enabled.default
  2. feature.streamwork.enabled.default
  3. feature.predefinedconnections.list.default:0

Sample script:

MOBI_BASE_PLIST=“./DefaultSettings_v5.0.plist”

MOBI_MODIFIED_PLIST=“./DefaultSettings_v4.4.plist”

MOBI_NEW_PLIST=“./DefaultSettings_v5.0.plist”

MOBI_CHANGE_SCRIPT=“./runGeneratedOverrides.sh”

declare -a cust_arr=( \

“Customizations:feature.email.enabled.default” \

“Customizations:feature.streamwork.enabled.default” \

“Customizations:feature.addconnection.SUP.enabled.default” \

“Customizations:feature.predefinedconnections.list.default:0” \

)

#Inform the user that they need to review the generate file for any discrepancies.

clear

echo “##################################################################”

echo “This script will generate the following file, deleting any existing copies: “

echo ”  ${MOBI_CHANGE_SCRIPT}”

echo “”

echo “The script uses files in following locations, please exit and change path in the script if needed: “

echo “Base version of the file: [${MOBI_BASE_PLIST}]”

echo “Customized version of the file: [${MOBI_MODIFIED_PLIST}]”

echo “”

echo “You must review the generated file for its completeness  and make any additional changes that you desire.”

echo “##################################################################”

echo “”

read -p “Do you want to proceed? “ -n 1 -r

echo

if [[ ! $REPLY =~ ^[Yy]$ ]]

then

exit 1

fi

#copy the Modified plist file as Change plist file.

rm “${MOBI_CHANGE_SCRIPT}”

# Loop through the items in the array.

for i in ${cust_arr[@]}

do

MOBI_MODIFIED_VAL=$(/usr/libexec/PlistBuddy -c “Print :$i” “${MOBI_MODIFIED_PLIST}”)

if [ “$?” == “0” ] #Proceed only if entry exists in modified file

then

MOBI_ORIG_VAL=$(/usr/libexec/PlistBuddy -c “Print :$i” “${MOBI_BASE_PLIST}”)

if [ “$?” == “0” ]

then

if [ “$MOBI_ORIG_VAL” != “$MOBI_MODIFIED_VAL” ]

then

echo /usr/libexec/PlistBuddy -c \“Set :$i ${MOBI_MODIFIED_VAL}\” \”${MOBI_NEW_PLIST}\” >> “${MOBI_CHANGE_SCRIPT}

fi

else

echo /usr/libexec/PlistBuddy -c \“Add :$i string ${MOBI_MODIFIED_VAL}\” \”${MOBI_NEW_PLIST}\” >> “${MOBI_CHANGE_SCRIPT}

fi

fi

done

#Mark the script as an executable

chmod +x “${MOBI_CHANGE_SCRIPT}”

if [ “$?” == “0” ]

then

  clear

  echo “##################################################################”

  echo “Script run is complete. Please review the following file for its completeness and make any additional changes that you desire: “

  echo “”

  echo ”  ${MOBI_CHANGE_SCRIPT}”

  echo “”

  echo “##################################################################”

  echo “”

else

  clear

  echo “##################################################################”

  echo “Script run is complete. No customizations were detected.”

  echo “”

  echo “If you are sure that you had performed customizations, ensure that following information is correct, and you have sufficient read/write permissions: “

  echo “”

  echo “Base version of the file: [${MOBI_BASE_PLIST}]”

  echo “Customized version of file: [${MOBI_MODIFIED_PLIST}]”

  echo “”

  echo “Script output file: [${MOBI_CHANGE_SCRIPT}]”

  echo “##################################################################”

fi


Shell scripts implementing both the approaches are attached to this article as .txt files. Kindly rename them to .sh formats after downloading.


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply