#!/bin/bash
# Rescapp Fsck run script
# Copyright (C) 2012,2013,2014,2015,2016,2017,2018,2019,2020 Adrian Gibanel Lopez
#
# Rescapp is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rescapp is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rescapp.  If not, see <http://www.gnu.org/licenses/>.

source ${RESCAPP_LIB_FILE}

set -x
set -v


# fsck Main program

UEFIFAKEMICROSOFT_OK_STR="The faking of the UEFI, Microsoft Windows boot entry was OK ! :)"
UEFIFAKEMICROSOFT_KO_STR="The faking of the UEFI, Microsoft Windows boot entry was not ok :("
UEFIFAKEMICROSOFT_RUNNING_STR="Faking UEFI Microsoft Windows boot entry"
UEFIFAKEMICROSOFT_PARTITIONS_NOT_FOUND="No partitions were found or chosen."
UEFIFAKEMICROSOFT_EFI_FILE_NOT_FOUND="No EFI files were found or chosen."
UEFIFAKEMICROSOFT_BACKUP_WENT_WRONG="Backup of EFI directory went wrong."


SELECTED_EFI_PARTITION="$(rtux_Choose_EFI_System_partition)"
if [ "x${SELECTED_EFI_PARTITION}" != "x" ] ; then
  SELECTED_EFI_FILE="$(rtux_UEFI_Choose_EFI_File ${SELECTED_EFI_PARTITION})"
  if [ "x${SELECTED_EFI_FILE}" != "x" ] ; then
    if rtux_backup_efi_partition "${SELECTED_EFI_PARTITION}" ; then
      if rtux_Run_Show_Progress "${UEFIFAKEMICROSOFT_RUNNING_STR}" rtux_UEFI_Fake_Microsoft_Boot_Entry "${SELECTED_EFI_PARTITION}" "${SELECTED_EFI_FILE}";
      then
      rtux_Message_Success ${UEFIFAKEMICROSOFT_OK_STR}
      else
      rtux_Message_Failure ${UEFIFAKEMICROSOFT_KO_STR}
      fi
    else
      rtux_Message_Warning ${UEFIFAKEMICROSOFT_BACKUP_WENT_WRONG}
      rtux_Message_Failure ${UEFIFAKEMICROSOFT_KO_STR}
    fi
  else
    rtux_Message_Warning ${UEFIFAKEMICROSOFT_EFI_FILE_NOT_FOUND}
    rtux_Message_Failure ${UEFIFAKEMICROSOFT_KO_STR}
  fi
else
  rtux_Message_Warning ${UEFIFAKEMICROSOFT_PARTITIONS_NOT_FOUND}
  rtux_Message_Failure ${UEFIFAKEMICROSOFT_KO_STR}
fi



