#!/bin/bash
# Rescapp Winmbr 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

# Compute Hybrid MBR CHS on a GPT partition
# From the chosen hard disk

function rtux_Hybridmbr_CHS_Compute () {

  local EXIT_VALUE=1 # Error by default
  local SELECTED_HARD_DISK="$1"

  sgdisk -C /dev/${SELECTED_HARD_DISK}

  EXIT_VALUE=$?
  return ${EXIT_VALUE}

} # function rtux_Grub_Install ()



# MAIN PROGRAM


GPT_HYBRID_CHS_COMPUTED_OK_STR="The hybrid MBR CHS was recomputed OK! :)"
GPT_HYBRID_CHS_NOT_COMPUTED_STR="The hybrid MBR was not recomputed. Something went wrong! :("
GPT_HYBRID_CHS_COMPUTED_RUNNING_STR="Recomputing the hybrid MBR CHS"
WHICH_HARD_DISK_CHS_COMPUTE_HYBRIDMBR_STR="Which hard drive do you wish to recompute its hybrid MBR CHS on?"
GPT_HYBRID_CHS_HARD_DISK_NOT_FOUND="No drives were found or chosen."

SELECTED_HARD_DISK=$(rtux_Choose_Hard_Disk "${WHICH_HARD_DISK_CHS_COMPUTE_HYBRIDMBR_STR}");

if [ "x${SELECTED_HARD_DISK}" != "x" ] ; then
  if rtux_Run_Show_Progress "${GPT_HYBRID_CHS_COMPUTED_RUNNING_STR}" rtux_Hybridmbr_CHS_Compute ${SELECTED_HARD_DISK} ; then
    rtux_Message_Success ${GPT_HYBRID_CHS_COMPUTED_OK_STR}
  else
    rtux_Message_Failure ${GPT_HYBRID_CHS_NOT_COMPUTED_STR}
  fi
else
  rtux_Message_Warning ${GPT_HYBRID_CHS_HARD_DISK_NOT_FOUND}
  rtux_Message_Failure ${GPT_HYBRID_CHS_NOT_COMPUTED_STR}
fi


