#!/bin/bash

EA_PFX_ID=4172646814
BACKUP_PATH=$HOME/GameBackups

echo "EA-App Prefix      : "$EA_PFX_ID
echo "Backup Destination : "$BACKUP_PATH
echo
echo "If this is incorrect, CANCEL (HOLD Ctr+C until you see the bash interface) IMMIDEATLY AND EDIT THE FIRST LINES"

sleep 10

mkdir -p $BACKUP_PATH/ea
mkdir -p $BACKUP_PATH/pvz

if [ -d "$BACKUP_PATH" ]; then

  echo "Backup of EA Game Library…";
  rsync -ahPz $HOME/.steam/steam/steamapps/compatdata/$EA_PFX_ID/pfx/drive_c/Program\ Files/EA\ Games/  $BACKUP_PATH/ea/lib

  echo "Backup of EA SaveGames…"
  rsync -ahPz $HOME/.steam/steam/steamapps/compatdata/$EA_PFX_ID/pfx/drive_c/users/steamuser/Documents/ $BACKUP_PATH/ea/docs

else
  echo -e "\b [failed]\nAborting"
  exit
fi

sleep 1
clear

echo "EA App Repair Instructions:"
echo -e "\t1st: Back Up you Game Library and you savegames [done]"
echo -e "\t2nd: Start Steam in BPM and delete Proton files for the EA-App"
echo -e "\t3rd: Download the EA-App installer from the Internet, and reinstall the App"
echo -e "\t4th: Put your Game-Library and your savegames back into place"
echo
read -p "This Script helped you to complete Task 1. If you want to proceed, complete Tasks 2 and 3 and then come back. Do you want to complete Task 4 now? (if so, enter 'yes')" USER_CONFIRM

if [[ "$USER_CONFIRM" =~ ^(yes|Yes|YES|y|ja|j|JA|Ja|ok|OK|okay|OKAY|Ok|Okay)$ ]]; then
  echo "Recovering EA-Game Library and EA-Savegames…"
  rsync -ahPz $BACKUP_PATH/ea/lib/ $HOME/.steam/steam/steamapps/compatdata/$EA_PFX_ID/pfx/drive_c/Program\ Files/EA\ Games
  rsync -ahPz $BACKUP_PATH/ea/docs/ $HOME/.steam/steam/steamapps/compatdata/$EA_PFX_ID/pfx/drive_c/users/steamuser/Documents
fi
