summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Affonso Xavier de Morais2014-07-03 17:25:01 +0200
committerMichael Pereira Neves2014-10-28 14:14:49 +0100
commitfb4100e11a421112328b8609a5fdd96aa2195359 (patch)
tree94cd3345bff5114236c2bb057fb77b5fa9448108
parent[partitioner] testing dialog function for graphical mode. (diff)
downloadtm-scripts-fb4100e11a421112328b8609a5fdd96aa2195359.tar.gz
tm-scripts-fb4100e11a421112328b8609a5fdd96aa2195359.tar.xz
tm-scripts-fb4100e11a421112328b8609a5fdd96aa2195359.zip
[partitioner] using dialog to print messages.
-rwxr-xr-xremote/modules/partitioner/dialog.sh4
-rwxr-xr-xremote/modules/partitioner/partitioner.sh100
2 files changed, 66 insertions, 38 deletions
diff --git a/remote/modules/partitioner/dialog.sh b/remote/modules/partitioner/dialog.sh
index c4bff5d2..45b122c5 100755
--- a/remote/modules/partitioner/dialog.sh
+++ b/remote/modules/partitioner/dialog.sh
@@ -34,5 +34,5 @@ if [ $? -eq 1 ]; then
STR=$STR" Free $FREESPACE ($GBSIZE GB)\n\n"
done
fi
-
-dialog --no-collapse --cr-wrap --inputbox "$STR" 0 0 $(echo $DISKS | cut -f1) \ No newline at end of file
+# echo $STR
+CHOSENDISK=$(dialog --no-collapse --cr-wrap --inputbox "$STR" 0 0 $(echo $DISKS | cut -f1) 3>&1 1>&2 2>&3)
diff --git a/remote/modules/partitioner/partitioner.sh b/remote/modules/partitioner/partitioner.sh
index 9acb3d9d..6c81e13d 100755
--- a/remote/modules/partitioner/partitioner.sh
+++ b/remote/modules/partitioner/partitioner.sh
@@ -13,41 +13,52 @@ DEFBOOTID=47
test $CHOSENDISK
if [ $? -eq 1 ]; then
DISKS=$(cat $PARTITIONSPATH | tr -s ' ' | cut -d ' ' -f5 | grep -e "[a-z]$")
- STR="This computer has the following partitions:\n"
+ test $DISKS
+ if [ $? -eq 1 ]; then
+ dialog --msgbox "ERROR: Can't find an hard disk." 5 40
+ return 1
+ fi
+ DIALOGSTR="This computer has the following partitions:\n"
for disk in $DISKS; do
DISKSIZE=$(cat $PARTITIONSPATH | grep -e $disk$ | tr -s ' ' | cut -d ' ' -f4)
PARTS=$(cat $PARTITIONSPATH | grep -e $disk[0-9] | tr -s ' ' | cut -d ' ' -f5)
GBSIZE=$(echo "scale=2; $DISKSIZE/1024/1024" | bc -l)
- STR=$STR"$disk $DISKSIZE Bytes ($GBSIZE GB)\n"
+ DIALOGSTR=$DIALOGSTR"$disk $DISKSIZE Bytes ($GBSIZE GB)\n"
USED=0
for PART in $PARTS; do
PARTSIZE=$(cat $PARTITIONSPATH | grep -e $PART$ | tr -s ' ' | cut -d ' ' -f4)
USED=$(($USED+$PARTSIZE))
GBSIZE=$(echo "scale=2; $PARTSIZE/1024/1024" | bc -l)
- STR=$STR" $PART $PARTSIZE ($GBSIZE GB)\n"
+ DIALOGSTR=$DIALOGSTR" $PART $PARTSIZE ($GBSIZE GB)\n"
done
- STR=$STR" ----------\n"
+ DIALOGSTR=$DIALOGSTR" ----------\n"
FREESPACE=$(($DISKSIZE-$USED))
GBSIZE=$(echo "scale=2; $USED/1024/1024" | bc -l)
- STR=$STR" Used $USED ($GBSIZE GB)\n"
+ DIALOGSTR=$DIALOGSTR" Used $USED ($GBSIZE GB)\n"
GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024" | bc -l)
- STR=$STR" Free $FREESPACE ($GBSIZE GB)\n\n"
+ DIALOGSTR=$DIALOGSTR" Free $FREESPACE ($GBSIZE GB)\n\n"
done
if [ $(echo $DISKS | tr ' ' \\n | wc -l) -gt 1 ]; then
- STR=$STR"Which of these disks you want to use?\n"
- dialog --no-collapse --cr-wrap --inputbox "$STR" 0 0 $(echo $DISKS | cut -d ' ' -f1)
+ DIALOGSTR=$DIALOGSTR"Which of these disks you want to use?\n"
+ CHOSENDISK=$(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;
+ fi
echo $DISKS | tr ' ' \\n | grep -e ^$CHOSENDISK$ > /dev/null 2>/dev/null
while [ $? -ne 0 ]; do
- echo "Invalid Option, try again."
- read CHOSENDISK
+ dialog --msgbox "Invalid option.\nTry again." 0 0
+ CHOSENDISK=$(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;
+ fi
echo $DISKS | tr ' ' \\n | grep -e ^$CHOSENDISK$ > /dev/null 2>/dev/null
done
# ask a confirmation (all your data will be lost etc)
elif [ $(echo $DISKS | tr ' ' \\n | wc -l) -eq 1 ]; then
CHOSENDISK=$(echo $DISKS | tr ' ' \\n | head -n1)
else
- echo "ERROR: Can't find an Hard Disk." 1>&2
+ dialog --msgbox "ERROR: Can't find an hard disk." 5 40
return 1
fi
fi
@@ -55,16 +66,12 @@ fi
DISKSIZE=$(cat $PARTITIONSPATH | grep -e $CHOSENDISK$ | tr -s ' ' | cut -d ' ' -f4)
echo "The disk $CHOSENDISK has $DISKSIZE Bytes of total."
echo "The /dev/$CHOSENDISK will be wiped, ok? (y/n)"
-read ANSWER
-while [ $ANSWER != 'y' ] && [ $ANSWER != 'n' ]; do
- echo "Please type 'y' or 'n'."
- read ANSWER
-done
-if [ $ANSWER = 'n' ]; then
+dialog --defaultno --yesno "The disk $CHOSENDISK has $DISKSIZE Bytes ($(echo "scale=2; $DISKSIZE/1024/1024" | bc -l) GB) of total space.\nAll /dev/$CHOSENDISK partitions will be deleted, ok?" 0 0
+if [ $? -eq 1 ]; then
return 1
fi
-
-echo "Wiping /dev/$CHOSENDISK"
+DIALOGSTR="Wiping /dev/$CHOSENDISK\n\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 30
echo "unit: sectors
/dev/"$CHOSENDISK"1 : start= 0, size= 0, Id= 0
@@ -76,15 +83,19 @@ sfdisk -q /dev/$CHOSENDISK < /tmp/emptydisk.tmp > /dev/null
rm -f /tmp/emptydisk.tmp
-echo "Creating new partitions"
+DIALOGSTR=$DIALOGSTR"Creating new partitions\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
LASTPARTITION=1 # in megabytes
-echo "Scratch:"
+# SCRATCH
+DIALOGSTR=$DIALOGSTR"SCRATCH\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $SCRATCHID
if [ $? -eq 1 ]; then
SCRATCHID=$DEFSCRATCHID
fi
-echo "\tID: $SCRATCHID"
+DIALOGSTR=$DIALOGSTR" ID: $SCRATCHID\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $SCRATCHSIZE
if [ $? -eq 1 ]; then
GBSIZE=$DEFPARTSIZE
@@ -93,17 +104,22 @@ else
GBSIZE=$SCRATCHSIZE
SCRATCHSIZE=$(($SCRATCHSIZE*1024*1024))
fi
-echo "\tSize: $SCRATCHSIZE Bytes ($GBSIZE GB)"
-echo "\tCreating Scratch partiton..."
+DIALOGSTR=$DIALOGSTR" Size: $SCRATCHSIZE Bytes ($GBSIZE GB)\n Creating SCRATCH partiton...\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
parted -s /dev/$CHOSENDISK mkpart primary $LASTPARTITION"m" $(($LASTPARTITION+$SCRATCHSIZE/1024))m && LASTPARTITION=$(($LASTPARTITION+$SCRATCHSIZE/1024))
sfdisk --change-id /dev/$CHOSENDISK 1 $SCRATCHID > /dev/null
+DIALOGSTR=$DIALOGSTR"Done.\n\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
-echo "Home:"
+# HOME
+DIALOGSTR=$DIALOGSTR"HOME\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $HOMEID
if [ $? -eq 1 ]; then
HOMEID=$DEFHOMEID
fi
-echo "\tID: $HOMEID"
+DIALOGSTR=$DIALOGSTR" ID: $HOMEID\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $HOMESIZE
if [ $? -eq 1 ]; then
GBSIZE=$DEFPARTSIZE
@@ -112,17 +128,22 @@ else
GBSIZE=$HOMESIZE
HOMESIZE=$(($HOMESIZE*1024*1024))
fi
-echo "\tSize: $HOMESIZE Bytes ($GBSIZE GB)"
-echo "\tCreating Home partiton..."
+DIALOGSTR=$DIALOGSTR" Size: $HOMESIZE Bytes ($GBSIZE GB)\n Creating HOME partiton...\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
parted -s /dev/$CHOSENDISK mkpart primary $LASTPARTITION"m" $(($LASTPARTITION+$HOMESIZE/1024))m && LASTPARTITION=$(($LASTPARTITION+$HOMESIZE/1024))
sfdisk --change-id /dev/$CHOSENDISK 2 $HOMEID > /dev/null
+DIALOGSTR=$DIALOGSTR"Done.\n\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
-echo "dnbd3:"
+# DNBD3
+DIALOGSTR=$DIALOGSTR"DNBD3\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $DNBD3ID
if [ $? -eq 1 ]; then
DNBD3ID=$DEFDNBD3ID
fi
-echo "\tID: $DNBD3ID"
+DIALOGSTR=$DIALOGSTR" ID: $DNBD3ID\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $DNBD3SIZE
if [ $? -eq 1 ]; then
GBSIZE=$DEFPARTSIZE
@@ -131,17 +152,22 @@ else
GBSIZE=$DNBD3SIZE
DNBD3SIZE=$(($DNBD3SIZE*1024*1024))
fi
-echo "\tSize: $DNBD3SIZE Bytes ($GBSIZE GB)"
-echo "\tCreating dnbd3 partiton..."
+DIALOGSTR=$DIALOGSTR" Size: $DNBD3SIZE Bytes ($GBSIZE GB)\n Creating DNBD3 partiton...\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
parted -s /dev/$CHOSENDISK mkpart primary $LASTPARTITION"m" $(($LASTPARTITION+$DNBD3SIZE/1024))m && LASTPARTITION=$(($LASTPARTITION+$DNBD3SIZE/1024))
sfdisk --change-id /dev/$CHOSENDISK 3 $DNBD3ID > /dev/null
+DIALOGSTR=$DIALOGSTR"Done.\n\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
-echo "Boot:"
+# BOOT
+DIALOGSTR=$DIALOGSTR"BOOT\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $BOOTID
if [ $? -eq 1 ]; then
BOOTID=$DEFBOOTID
fi
-echo "\tID: $BOOTID"
+DIALOGSTR=$DIALOGSTR" ID: $BOOTID\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
test $BOOTSIZE
if [ $? -eq 1 ]; then
GBSIZE=$DEFPARTSIZE
@@ -150,7 +176,9 @@ else
GBSIZE=$BOOTSIZE
BOOTSIZE=$(($BOOTSIZE*1024*1024))
fi
-echo "\tSize: $BOOTSIZE Bytes ($GBSIZE GB)"
-echo "\tCreating boot partiton..."
+DIALOGSTR=$DIALOGSTR" Size: $BOOTSIZE Bytes ($GBSIZE GB)\n Creating BOOT partiton...\n"
+dialog --keep-window --infobox "$DIALOGSTR" 30 50
parted -s /dev/$CHOSENDISK mkpart primary $LASTPARTITION"m" $(($LASTPARTITION+$BOOTSIZE/1024))m set 4 boot on && LASTPARTITION=$(($LASTPARTITION+$BOOTSIZE/1024))
sfdisk --change-id /dev/$CHOSENDISK 4 $BOOTID > /dev/null
+DIALOGSTR=$DIALOGSTR"Done.\n\n"
+dialog --and-widget --msgbox "$DIALOGSTR" 30 50 \ No newline at end of file