Grub-install script

From Rescatux Wiki

Jump to: navigation, search
  1. Just check the source code of the page
  1. !/bin/bash
  2. set -x
  3. set -v
  1. Ahora ya podemos seleccionar particion bien
  2. TODO: Que te detecte discos duros a partir particiones y te deje elegir
  3. TODO: Habilitar de nuevo la instalacion del grub
  4. TODO: Chequeo de programas (copiar de bootinfoscript)


  1. PROC_PARTITIONS_FILE=/tmp/partitions

PROC_PARTITIONS_FILE=/proc/partitions


TARGET_PARTITIONS=$(awk '{print $4}' ${PROC_PARTITIONS_FILE} | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d')

echo $TARGET_PARTITIONS

SBIN_GRUB_PARTITIONS="" RESCATUX_ROOT_MNT=/mnt/rescatux

  1. GRUB_INSTALL_BINARY=/etc/issue

GRUB_INSTALL_BINARY=/usr/sbin/grub-install

for n_partition in ${TARGET_PARTITIONS}; do TMP_MNT_PARTITION=${RESCATUX_ROOT_MNT}/${n_partition} TMP_DEV_PARTITION=/dev/${n_partition} mkdir --parents ${TMP_MNT_PARTITION} if $(mount -t auto ${TMP_DEV_PARTITION} ${TMP_MNT_PARTITION} 2> /dev/null) ; then #echo -e -n "Detectada particion: ${n_partition}\n"; if [[ -e ${TMP_MNT_PARTITION}${GRUB_INSTALL_BINARY} ]] ; then #echo -e -n "Detectado grub-install en particion: ${n_partition}\n" SBIN_GRUB_PARTITIONS="${SBIN_GRUB_PARTITIONS} ${n_partition}" fi umount ${TMP_MNT_PARTITION}; fi done

echo -e -n "Detected grub-install partitions: ${SBIN_GRUB_PARTITIONS}\n"

function etc_issue() {

 local ETC_ISSUE_PATH="/etc/issue"
 local PARTITION_TO_MOUNT=$1
 local n_partition=${PARTITION_TO_MOUNT}
       TMP_MNT_PARTITION=${RESCATUX_ROOT_MNT}/${n_partition}
       TMP_DEV_PARTITION=/dev/${n_partition}
       mkdir --parents ${TMP_MNT_PARTITION}
       if $(mount -t auto ${TMP_DEV_PARTITION} ${TMP_MNT_PARTITION} 2> /dev/null) ; then
               #echo -e -n "Detectada particion: ${n_partition}\n";
               if [[ -e ${TMP_MNT_PARTITION}${ETC_ISSUE_PATH} ]] ; then
                 #echo -e -n "Detectado grub-install en particion: ${n_partition}\n"

echo $(sed -e 's/\\. //g' -e 's/\\.//g' -e 's/^[ \t]*//' ${TMP_MNT_PARTITION}${ETC_ISSUE_PATH}) else echo "Not detected"

               fi
               umount ${TMP_MNT_PARTITION};
       fi


} # function etc_issue() end



  1. Select one of the partitions TODO - BEGIN

n=0 LIST_VALUES="" DESC_VALUES="" for n_partition in ${SBIN_GRUB_PARTITIONS}; do

 issue_value=`etc_issue ${n_partition}`
 issue_value=$(echo $issue_value | sed 's/\ /\-/')
 issue_value=$(echo $issue_value | sed 's/ /\-/')
 
 if  n -eq 0  ; then
   LIST_VALUES="TRUE ${n_partition} ${issue_value}"
 else
   LIST_VALUES="${LIST_VALUES} FALSE ${n_partition} ${issue_value}"
 fi

let n=n+1 done

echo -e -n "a: $LIST_VALUES\n"

ans=$(zenity --list --text "Which partition is your main Linux?" --radiolist --column "Select" --column "Partition" --column "Desc" ${LIST_VALUES}); echo $ans

  1. Lets suppose that selected partition is: sda3

SELECTED_PARTITION="$ans"

  1. Select one of the partitions TODO - END
  1. Select one of the hard disks TODO - BEGIN
  1. Lets suppose that selected hard disk is: sda

SELECTED_HARD_DISK="sda"

  1. Select one of the hard disks TODO - END
  1. TODO: TO BE IMPROVED WITH A FUNCTION

SELECTED_HARD_DISK_DEV="/dev/${SELECTED_HARD_DISK}" n_partition=${SELECTED_PARTITION}

TMP_MNT_PARTITION=${RESCATUX_ROOT_MNT}/${n_partition}

       TMP_DEV_PARTITION=/dev/${n_partition}
       mkdir --parents ${TMP_MNT_PARTITION}
       if $(mount -t auto ${TMP_DEV_PARTITION} ${TMP_MNT_PARTITION} 2> /dev/null) ; then
               #echo -e -n "Detectada particion: ${n_partition}\n";
               if [[ -e ${TMP_MNT_PARTITION}${GRUB_INSTALL_BINARY} ]] ; then

echo "${GRUB_INSTALL_BINARY} ${SELECTED_HARD_DISK_DEV} > /tmp/hey.txt" > ${TMP_MNT_PARTITION}/tmp/$$.sh chmod +x ${TMP_MNT_PARTITION}/tmp/$$.sh #if $(chroot ${TMP_MNT_PARTITION} /bin/bash /tmp/$$.sh) ; then # echo -e -n "Grub was installed OK! :)"; #else # echo -e -n "There was some problem when installing GRUB :("; #fi rm ${TMP_MNT_PARTITION}/tmp/$$.sh

               fi
               umount ${TMP_MNT_PARTITION};
       fi


Personal tools