summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Affonso Xavier de Morais2014-08-15 17:03:17 +0200
committerMichael Pereira Neves2014-10-28 14:14:49 +0100
commit6ae6bd8825c17c8354a794e77393accc58e495a2 (patch)
tree36085f4387cfc6ae10c3659192a126aef919229e
parent[partitioner] existent partitions detection working for GPT and MSDOS. TODO: ... (diff)
downloadtm-scripts-6ae6bd8825c17c8354a794e77393accc58e495a2.tar.gz
tm-scripts-6ae6bd8825c17c8354a794e77393accc58e495a2.tar.xz
tm-scripts-6ae6bd8825c17c8354a794e77393accc58e495a2.zip
[partitioner] freespace check done.
-rwxr-xr-xremote/modules/partitioner/partitioner.sh93
1 files changed, 53 insertions, 40 deletions
diff --git a/remote/modules/partitioner/partitioner.sh b/remote/modules/partitioner/partitioner.sh
index f2a7dfc3..bc7fac84 100755
--- a/remote/modules/partitioner/partitioner.sh
+++ b/remote/modules/partitioner/partitioner.sh
@@ -15,10 +15,9 @@ BLOCKSIZE=1024
# picking disk that will be used
DISKS=$(cat $PARTITIONSPATH | tr -s ' ' | cut -d ' ' -f5 | grep -e "[a-z]$")
if [ -z "$DISKS" ]; then
- dialog --msgbox "ERROR: Can't find an hard disk." 5 40
+ dialog --msgbox "ERROR: Can't find an hard disk." 10 40
exit 1
fi
-
if [ -z "$SLX_CHOOSEN_DISK" ]; then
DIALOGSTR="This computer has the following partitions:\n"
for disk in $DISKS; do
@@ -40,7 +39,6 @@ if [ -z "$SLX_CHOOSEN_DISK" ]; then
GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024/1024" | bc -l)
DIALOGSTR=$DIALOGSTR" Free $FREESPACE ($GBSIZE GB)\n\n"
done
-
if [ $(echo $DISKS | tr ' ' \\n | wc -l) -gt 1 ]; 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)
@@ -61,11 +59,10 @@ if [ -z "$SLX_CHOOSEN_DISK" ]; then
elif [ $(echo $DISKS | tr ' ' \\n | wc -l) -eq 1 ]; then
SLX_CHOOSEN_DISK=$(echo $DISKS | tr ' ' \\n | head -n1)
else
- dialog --msgbox "ERROR: Can't find an hard disk." 5 40
+ dialog --msgbox "ERROR: Can't find an hard disk." 10 40
exit 1
fi
fi
-
# if SLX_PARTITION_TABLE is set then put his content in a associative array
declare -A PARTTBL
COUNTER=1
@@ -89,17 +86,23 @@ if [ -n "$SLX_PARTITION_TABLE" ]; then
COUNTER=$(($COUNTER+1))
done
unset IFS
+else
+ dialog --msgbox "ERROR: You didn't set a valid partition table. Please check your config file." 10 40
+ exit 1
fi
# PARTTBL starts at 1 and ends at COUNTER-1
# 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
+NEEDED_SPACE=0
for (( i = 1; i < $COUNTER; i++ )); do
- PARTSSIZE=$PARTSSIZE+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}
+ if [[ $i -ne 4 ]]; then
+ NEEDED_SPACE=$(($NEEDED_SPACE+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}))
+ fi
done
-echo "$DISKSIZE -lt $(($PARTSSIZE*1024*1024*1024+$COUNTER*1024*1024))"
-if [ $DISKSIZE -lt $(($PARTSSIZE*1024*1024*1024+$COUNTER*1024*1024)) ]; then
+NEEDED_SPACE=$(($NEEDED_SPACE*1024*1024*1024+$COUNTER*1024*1024))
+echo "$DISKSIZE -lt $NEEDED_SPACE"
+if [ $DISKSIZE -lt $NEEDED_SPACE ]; then
dialog --msgbox "ERROR: Insufficient space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
exit 1
fi
@@ -118,26 +121,26 @@ if [ -z "$SLX_PARTITION_TYPE" ]; then
fi
fi
-# asking confirmation to create the partitions
-if [ $SLX_AUTOMATIC_PARTITIONING = "no" ]; then
- GBSIZE=$(echo "scale=2; $DISKSIZE/1024/1024/1024" | bc -l)
- DIALOGSTR="$SLX_CHOOSEN_DISK $DISKSIZE Bytes ($GBSIZE GB)\n"
- PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5)
- USED=0
- for PART in $PARTS; do
- PARTSIZE=$(($(cat $PARTITIONSPATH | grep -e $PART$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE))
- USED=$(($USED+$PARTSIZE))
- GBSIZE=$(echo "scale=2; $PARTSIZE/1024/1024/1024" | bc -l)
- DIALOGSTR=$DIALOGSTR" $PART $PARTSIZE ($GBSIZE GB)\n"
- done
- DIALOGSTR=$DIALOGSTR" ----------\n"
- FREESPACE=$(($DISKSIZE-$USED))
- GBSIZE=$(echo "scale=2; $USED/1024/1024/1024" | bc -l)
- DIALOGSTR=$DIALOGSTR" Used $USED ($GBSIZE GB)\n"
- GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024/1024" | bc -l)
- DIALOGSTR=$DIALOGSTR" Free $FREESPACE ($GBSIZE GB)\n\n"
- DIALOGSTR=$DIALOGSTR"All /dev/$SLX_CHOOSEN_DISK partitions will be deleted, ok?"
+GBSIZE=$(echo "scale=2; $DISKSIZE/1024/1024/1024" | bc -l)
+DIALOGSTR="$SLX_CHOOSEN_DISK $DISKSIZE Bytes ($GBSIZE GB)\n"
+PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5)
+USED=0
+for PART in $PARTS; do
+ PARTSIZE=$(($(cat $PARTITIONSPATH | grep -e $PART$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE))
+ USED=$(($USED+$PARTSIZE))
+ GBSIZE=$(echo "scale=2; $PARTSIZE/1024/1024/1024" | bc -l)
+ DIALOGSTR=$DIALOGSTR" $PART $PARTSIZE ($GBSIZE GB)\n"
+done
+DIALOGSTR=$DIALOGSTR" ----------\n"
+FREESPACE=$(($DISKSIZE-$USED))
+GBSIZE=$(echo "scale=2; $USED/1024/1024/1024" | bc -l)
+DIALOGSTR=$DIALOGSTR" Used $USED ($GBSIZE GB)\n"
+GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024/1024" | bc -l)
+DIALOGSTR=$DIALOGSTR" Free $FREESPACE ($GBSIZE GB)\n\n"
+DIALOGSTR=$DIALOGSTR"All /dev/$SLX_CHOOSEN_DISK partitions will be deleted, ok?"
+# asking confirmation to create the partitions
+if [[ $SLX_AUTOMATIC_PARTITIONING = "no" && SLX_DELETE_PARTITION_TABLE = 'yes' ]]; then
dialog --defaultno --yesno "$DIALOGSTR" 0 0
if [ $? -eq 1 ]; then
exit 1
@@ -148,10 +151,13 @@ fi
# SECTORSIZE=$(sfdisk /dev/$SLX_CHOOSEN_DISK -l -u S 2> /dev/null | grep Units | cut -d ' ' -f5)
SECTORSIZE=512
-# delete partition table
+if [[ $USED -eq 0 ]]; then
+ SLX_DELETE_PARTITION_TABLE="yes"
+fi
+
if [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then
- # :
- sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2> /dev/null
+ # delete partition table
+ sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2> /dev/null # erase all partitions
# constructing the sfdisk input file
echo "unit: sectors
@@ -178,44 +184,51 @@ if [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then
elif [ $(sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $SLX_CHOOSEN_DISK'1' | tr -s ' ' | cut -d ' ' -f7 | cut -d '=' -f2) = 'ee' ]; then
# finding existent partitions in GPT
echo 'GPT'
- PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5) # this line fix the empty PARTS error, continue from here
for PART in $PARTS; do
for (( i = 1; i < $COUNTER; i++ )); do
- echo "i=$i PART=$PART"
if [ $i -ne 4 ]; then
if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then
- echo "sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep '${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000'"
- sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000"
+ sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" > /dev/null
if [ $? -eq 0 ]; then
echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition."
PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART
+ NEEDED_SPACE=$(($NEEDED_SPACE-${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
break
fi
fi
fi
done
done
- # FREESPACE needed here
+ echo "FREESPACE="$FREESPACE
+ echo "NEEDED_SPACE="$NEEDED_SPACE
+ if [[ $FREESPACE -lt $NEEDED_SPACE ]]; then
+ dialog --msgbox "ERROR: Insufficient free space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
+ exit 1
+ fi
else
# finding existent partitions in MS-DOS
echo 'MSDOS'
- PARTS=$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK[0-9] | tr -s ' ' | cut -d ' ' -f5) # this line fix the empty PARTS error, continue from here
for PART in $PARTS; do
for (( i = 1; i < $COUNTER; i++ )); do
- echo "i=$i PART=$PART"
if [ $i -ne 4 ]; then
if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then
- echo "sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $PART | tr -s ' ' | cut -d ' ' -f7 | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"
- sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $PART | tr -s ' ' | cut -d ' ' -f7 | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}
+ sfdisk -d /dev/$SLX_CHOOSEN_DISK 2> /dev/null | grep $PART | tr -s ' ' | cut -d ' ' -f7 | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]} > /dev/null
if [ $? -eq 0 ]; then
echo "the partition $PART is the ${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]} partition."
PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART
+ NEEDED_SPACE=$(($NEEDED_SPACE-${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
break
fi
fi
fi
done
done
+ echo "FREESPACE="$FREESPACE
+ echo "NEEDED_SPACE="$NEEDED_SPACE
+ if [[ $FREESPACE -lt $NEEDED_SPACE ]]; then
+ dialog --msgbox "ERROR: Insufficient free space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
+ exit 1
+ fi
fi
DIALOGSTR="New partitions created:\n\n"