diff options
author | Lucas Affonso Xavier de Morais | 2014-08-07 17:10:23 +0200 |
---|---|---|
committer | Michael Pereira Neves | 2014-10-28 14:14:49 +0100 |
commit | b90c258cb83a2e7e859b6bfe262b0cb039f3363e (patch) | |
tree | 8f4662a81b40a1d64da03b34a12ce39d830acc73 /remote/modules | |
parent | [partitioner] lacking NO_OVERRIDE option and AUTOMATIC_PARTITIONING (diff) | |
download | tm-scripts-b90c258cb83a2e7e859b6bfe262b0cb039f3363e.tar.gz tm-scripts-b90c258cb83a2e7e859b6bfe262b0cb039f3363e.tar.xz tm-scripts-b90c258cb83a2e7e859b6bfe262b0cb039f3363e.zip |
[partitioner]implementing the detection of existing partitions.
Diffstat (limited to 'remote/modules')
-rwxr-xr-x | remote/modules/partitioner/partitioner.sh | 111 |
1 files changed, 72 insertions, 39 deletions
diff --git a/remote/modules/partitioner/partitioner.sh b/remote/modules/partitioner/partitioner.sh index f03a8b76..05160630 100755 --- a/remote/modules/partitioner/partitioner.sh +++ b/remote/modules/partitioner/partitioner.sh @@ -14,10 +14,9 @@ BLOCKSIZE=1024 # picking disk that will be used DISKS=$(cat $PARTITIONSPATH | tr -s ' ' | cut -d ' ' -f5 | grep -e "[a-z]$") -test $DISKS 2> /dev/null -if [ $? -eq 1 ]; then +if [ -z "$DISKS" ]; then dialog --msgbox "ERROR: Can't find an hard disk." 5 40 - return 1 + exit 1 fi if [ -z "$SLX_CHOOSEN_DISK" ]; then @@ -46,14 +45,15 @@ if [ -z "$SLX_CHOOSEN_DISK" ]; then DIALOGSTR=$DIALOGSTR"Which of these disks you want to use?\n" SLX_CHOOSEN_DISK=$(dialog --no-collapse --cr-wrap --inputbox "$DIALOGSTR" 0 0 $(echo $DISKS | cut -d ' ' -f1) 3>&1 1>&2 2>&3) if [ $? -eq 1 ]; then - return 1; + exit 1; fi + # verify if the choosen disk is a valid disk echo $DISKS | tr ' ' \\n | grep -e ^$SLX_CHOOSEN_DISK$ > /dev/null 2>/dev/null while [ $? -ne 0 ]; do dialog --msgbox "Invalid option.\nTry again." 0 0 SLX_CHOOSEN_DISK=$(dialog --no-collapse --cr-wrap --inputbox "$DIALOGSTR" 0 0 $(echo $DISKS | cut -d ' ' -f1) 3>&1 1>&2 2>&3) if [ $? -eq 1 ]; then - return 1; + exit 1; fi echo $DISKS | tr ' ' \\n | grep -e ^$SLX_CHOOSEN_DISK$ > /dev/null 2>/dev/null done @@ -62,10 +62,11 @@ if [ -z "$SLX_CHOOSEN_DISK" ]; then SLX_CHOOSEN_DISK=$(echo $DISKS | tr ' ' \\n | head -n1) else dialog --msgbox "ERROR: Can't find an hard disk." 5 40 - return 1 + exit 1 fi fi +# if SLX_PARTITION_TABLE is set then put his content in a associative array declare -A PARTTBL COUNTER=1 if [ -n "$SLX_PARTITION_TABLE" ]; then @@ -83,22 +84,22 @@ if [ -n "$SLX_PARTITION_TABLE" ]; then else PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=1 fi + PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=0 COUNTER=$(($COUNTER+1)) done fi unset IFS - +# check if the choosen disk is greater than the new partition table size. DISKSIZE=$(($(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE)) PARTSSIZE=0 for (( i = 1; i < $COUNTER; i++ )); do PARTSSIZE=$PARTSSIZE+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]} done - echo "$DISKSIZE -lt $(($PARTSSIZE*1024*1024*1024+$COUNTER*1024*1024))" if [ $DISKSIZE -lt $(($PARTSSIZE*1024*1024*1024+$COUNTER*1024*1024)) ]; then dialog --msgbox "ERROR: Insufficient space in disk /dev/$SLX_CHOOSEN_DISK." 6 40 - return 1 + exit 1 fi # choosing the partition type (MSDOS or GPT) if it wasn't set in config file @@ -106,7 +107,7 @@ if [ -z "$SLX_PARTITION_TYPE" ]; then SLX_PARTITION_TYPE=msdos ANS=$(dialog --no-tags --menu "Choose the partitions type" 0 0 0 "1" " MSDOS " "2" " GPT " 3>&1 1>&2 2>&3) if [ $? -eq 1 ]; then - return 1 + exit 1 fi if [ $ANS -eq 1 ]; then SLX_PARTITION_TYPE=msdos @@ -137,7 +138,7 @@ if [ $SLX_AUTOMATIC_PARTITIONING = "no" ]; then dialog --defaultno --yesno "$DIALOGSTR" 0 0 if [ $? -eq 1 ]; then - return 1 + exit 1 fi fi @@ -146,41 +147,73 @@ fi SECTORSIZE=512 # delete partition table -if [ $SLX_OVERRIDE_PARTITIONS = "yes" ]; then - : - # sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2> /dev/null -fi +if [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then + # : + sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2> /dev/null -# constructing the sfdisk input file -echo "unit: sectors -"> /tmp/partitiontable.tmp + # constructing the sfdisk input file + echo "unit: sectors + "> /tmp/partitiontable.tmp -START=$((1*1024*1024/$SECTORSIZE)) -for (( i = 1; i < $COUNTER; i++ )); do - if [ $i -ne 4 ]; then - SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024/$SECTORSIZE)) - ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]} - if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/bootable"]} -eq 1 ]; then - echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$SIZE", Id= "$ID", bootable " >> /tmp/partitiontable.tmp + START=$((1*1024*1024/$SECTORSIZE)) + for (( i = 1; i < $COUNTER; i++ )); do + if [ $i -ne 4 ]; then + SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024/$SECTORSIZE)) + ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]} + if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/bootable"]} -eq 1 ]; then + echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$SIZE", Id= "$ID", bootable " >> /tmp/partitiontable.tmp + else + echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$SIZE", Id= "$ID >> /tmp/partitiontable.tmp + fi + START=$(($START+$SIZE+1*1024*1024/$SECTORSIZE)) else - echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$SIZE", Id= "$ID >> /tmp/partitiontable.tmp + echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$(($DISKSIZE/$SECTORSIZE-1))", Id= 5" >> /tmp/partitiontable.tmp + START=$(($START+1*1024*1024/$SECTORSIZE)) fi - START=$(($START+$SIZE+1*1024*1024/$SECTORSIZE)) - else - echo "/dev/"$SLX_CHOOSEN_DISK$i" : start= "$START", size= "$(($DISKSIZE/$SECTORSIZE-1))", Id= 5" >> /tmp/partitiontable.tmp - START=$(($START+1*1024*1024/$SECTORSIZE)) - fi -done -# sfdisk -q -f /dev/$SLX_CHOOSEN_DISK < /tmp/partitiontable.tmp > /dev/null -rm -f /tmp/partitiontable.tmp + done + sfdisk -q -f /dev/$SLX_CHOOSEN_DISK < /tmp/partitiontable.tmp > /dev/null + rm -f /tmp/partitiontable.tmp +# stopped here!!! +elif [ $(sfdisk -d /dev/$SLX_CHOOSEN_DISK | grep $SLX_CHOOSEN_DISK'1' | tr -s ' ' | cut -d ' ' -f7 | cut -d '=' -f2) = 'ee' ]; then +# finding existent partitions in GPT + for PART in $PARTS; do + for (( i = 1; i < $(($COUNTER-1)); i++ )); do + if [ $i -ne 4 ]; then + if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists?"]} -ne 1 ]; then + sgdisk /dev/$SLX_CHOOSEN_DISK -i $i | grep "unique GUID" | cut -d ' ' -f4 | grep '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000' + if [ $? -eq 0 ]; then + echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition." + PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=1 + break; + fi + fi + fi + i=$(($i+1)) + done + done +else +# finding existent partitions in MS-DOS + for PART in $PARTS; do + for (( i = 1; i < $(($COUNTER-1)); i++ )); do + if [ $i -ne 4 ]; then + [ sfdisk -d /dev/$SLX_CHOOSEN_DISK | grep $PART | tr -s ' ' | cut -d ' ' -f7 | cut -d '=' -f2 = '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}' ] + if [ $? -eq 0 ]; then + PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists?"]=1 + break; + fi + fi + i=$(($i+1)) + done + done +fi DIALOGSTR="New partitions created:\n\n" if [ $SLX_PARTITION_TYPE = GPT ]; then - # sgdisk -g /dev/$SLX_CHOOSEN_DISK\ - # -t 1:"$SCRATCHID"000000-0000-0000-0000-000000000000\ - # -t 2:"$HOMEID"000000-0000-0000-0000-000000000000\ - # -t 3:"$DNBD3ID"000000-0000-0000-0000-000000000000\ - # -t 4:"$BOOTID"000000-0000-0000-0000-000000000000 > /dev/null + sgdisk -g /dev/$SLX_CHOOSEN_DISK\ + -t 1:"$SCRATCHID"000000-0000-0000-0000-000000000000\ + -t 2:"$HOMEID"000000-0000-0000-0000-000000000000\ + -t 3:"$DNBD3ID"000000-0000-0000-0000-000000000000\ + -t 4:"$BOOTID"000000-0000-0000-0000-000000000000 > /dev/null for (( i = 1; i < $COUNTER; i++ )); do if [ $i -ne 4 ]; then |