echo "Copying MobileFirst configuration file for iOS"
export PLUGIN_DIR=$PWD
export BASE_DIR=$PWD/../..
echo "Plugin dir is "
echo $PLUGIN_DIR
echo $BASE_DIR

echo "Copying MFP Configuration file for iOS..."
if [ -e ../../ios/mfpclient.plist ]
then
    echo "MFP Server Configuration file already exists."
    cp ../../ios/mfpclient.plist ios/Assets/mfpclient.plist
    rm -f ../../ios/mfpclient.plist
    ln -f ios/Assets/mfpclient.plist ../../ios/mfpclient.plist
else
    echo "MFP Server Configuration file doesn't exist, creating one now."
    #cp scripts/mfpclient.plist ../../ios/mfpclient.plist
    ln -f ios/Assets/mfpclient.plist ../../ios/mfpclient.plist
fi


if [ -e  ../../ios/Podfile ]
then
   echo “Podfile already exists. ignore copying”
else
   echo "Podfile doesn't exist, creating one now. For older versions"
   cp scripts/Podfile ../../ios/Podfile
fi

# echo "Installing Pods"
# cd $BASE_DIR/ios
# export TARGET=$(basename *.xcodeproj .xcodeproj)
# echo "Target is "
# echo $TARGET
# sed -i "" "s/<TARGET>/$TARGET/g" Podfile
# pod install
# cd $PLUGIN_DIR

if grep "include ':react-native-bridge'" $BASE_DIR/android/settings.gradle
then
  echo "Skipping copying of internal dependencies"
else
  echo "Adding internal dependencies"
  cat scripts/bridge.settings >> $BASE_DIR/android/settings.gradle
fi

echo "Copying MFP Configuration file for Android..."
if [ -e $BASE_DIR/android/app/src/main/assets/mfpclient.properties ]
then
    echo "MFP Server Configuration file already exists."
else
    echo "MFP Server Configuration file doesn't exist, creating one now."
    cp -R $PLUGIN_DIR/android/src/main/assets $BASE_DIR/android/app/src/main/
fi

echo "Post installation complete"
