diff options
author | Lucas Affonso Xavier de Morais | 2014-07-03 15:06:13 +0200 |
---|---|---|
committer | Michael Pereira Neves | 2014-10-28 14:14:49 +0100 |
commit | a7a2202d9a09f0c9b3a49972eb633980aaba1485 (patch) | |
tree | 563ddfe831fc29bde235494de8d74419774c1e23 /remote/modules | |
parent | Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts (diff) | |
download | tm-scripts-a7a2202d9a09f0c9b3a49972eb633980aaba1485.tar.gz tm-scripts-a7a2202d9a09f0c9b3a49972eb633980aaba1485.tar.xz tm-scripts-a7a2202d9a09f0c9b3a49972eb633980aaba1485.zip |
[partitioner] testing dialog function for graphical mode.
Diffstat (limited to 'remote/modules')
-rw-r--r-- | remote/modules/partitioner/config | 15 | ||||
-rwxr-xr-x | remote/modules/partitioner/dialog.sh | 38 | ||||
-rwxr-xr-x | remote/modules/partitioner/partitioner.sh | 156 | ||||
-rw-r--r-- | remote/modules/partitioner/partitions | 17 |
4 files changed, 226 insertions, 0 deletions
diff --git a/remote/modules/partitioner/config b/remote/modules/partitioner/config new file mode 100644 index 00000000..e8a31fe2 --- /dev/null +++ b/remote/modules/partitioner/config @@ -0,0 +1,15 @@ +#PARTITIONER + +CHOSENDISK=sda + +SCRATCHID=44 +SCRATCHSIZE=1 + +HOMEID=45 +HOMESIZE=2 + +DNBD3ID=46 +DNBD3SIZE=3 + +BOOTID=47 +BOOTSIZE=4
\ No newline at end of file diff --git a/remote/modules/partitioner/dialog.sh b/remote/modules/partitioner/dialog.sh new file mode 100755 index 00000000..c4bff5d2 --- /dev/null +++ b/remote/modules/partitioner/dialog.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +PARTITIONSPATH="/proc/partitions" +CONFIGPATH="./config" +DEFPARTSIZE=5 #in GB +DEFSCRATCHID=44 +DEFHOMEID=45 +DEFDNBD3ID=46 +DEFBOOTID=47 + +. $CONFIGPATH +# picking disk that will be used +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" + 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" + 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" + done + STR=$STR" ----------\n" + FREESPACE=$(($DISKSIZE-$USED)) + GBSIZE=$(echo "scale=2; $USED/1024/1024" | bc -l) + STR=$STR" Used $USED ($GBSIZE GB)\n" + GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024" | bc -l) + 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 diff --git a/remote/modules/partitioner/partitioner.sh b/remote/modules/partitioner/partitioner.sh new file mode 100755 index 00000000..9acb3d9d --- /dev/null +++ b/remote/modules/partitioner/partitioner.sh @@ -0,0 +1,156 @@ +#!/bin/sh + +PARTITIONSPATH="/proc/partitions" +CONFIGPATH="./config" +DEFPARTSIZE=5 #in GB +DEFSCRATCHID=44 +DEFHOMEID=45 +DEFDNBD3ID=46 +DEFBOOTID=47 + +. $CONFIGPATH +# picking disk that will be used +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" + 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" + 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" + done + STR=$STR" ----------\n" + FREESPACE=$(($DISKSIZE-$USED)) + GBSIZE=$(echo "scale=2; $USED/1024/1024" | bc -l) + STR=$STR" Used $USED ($GBSIZE GB)\n" + GBSIZE=$(echo "scale=2; $FREESPACE/1024/1024" | bc -l) + STR=$STR" 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) + echo $DISKS | tr ' ' \\n | grep -e ^$CHOSENDISK$ > /dev/null 2>/dev/null + while [ $? -ne 0 ]; do + echo "Invalid Option, try again." + read CHOSENDISK + 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 + return 1 + fi +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 + return 1 +fi + +echo "Wiping /dev/$CHOSENDISK" +echo "unit: sectors + +/dev/"$CHOSENDISK"1 : start= 0, size= 0, Id= 0 +/dev/"$CHOSENDISK"2 : start= 0, size= 0, Id= 0 +/dev/"$CHOSENDISK"3 : start= 0, size= 0, Id= 0 +/dev/"$CHOSENDISK"4 : start= 0, size= 0, Id= 0 +" > /tmp/emptydisk.tmp +sfdisk -q /dev/$CHOSENDISK < /tmp/emptydisk.tmp > /dev/null +rm -f /tmp/emptydisk.tmp + + +echo "Creating new partitions" +LASTPARTITION=1 # in megabytes + +echo "Scratch:" +test $SCRATCHID +if [ $? -eq 1 ]; then + SCRATCHID=$DEFSCRATCHID +fi +echo "\tID: $SCRATCHID" +test $SCRATCHSIZE +if [ $? -eq 1 ]; then + GBSIZE=$DEFPARTSIZE + SCRATCHSIZE=$(($DEFPARTSIZE*1024*1024)) +else + GBSIZE=$SCRATCHSIZE + SCRATCHSIZE=$(($SCRATCHSIZE*1024*1024)) +fi +echo "\tSize: $SCRATCHSIZE Bytes ($GBSIZE GB)" +echo "\tCreating Scratch partiton..." +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 + +echo "Home:" +test $HOMEID +if [ $? -eq 1 ]; then + HOMEID=$DEFHOMEID +fi +echo "\tID: $HOMEID" +test $HOMESIZE +if [ $? -eq 1 ]; then + GBSIZE=$DEFPARTSIZE + HOMESIZE=$(($DEFPARTSIZE*1024*1024)) +else + GBSIZE=$HOMESIZE + HOMESIZE=$(($HOMESIZE*1024*1024)) +fi +echo "\tSize: $HOMESIZE Bytes ($GBSIZE GB)" +echo "\tCreating Home partiton..." +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 + +echo "dnbd3:" +test $DNBD3ID +if [ $? -eq 1 ]; then + DNBD3ID=$DEFDNBD3ID +fi +echo "\tID: $DNBD3ID" +test $DNBD3SIZE +if [ $? -eq 1 ]; then + GBSIZE=$DEFPARTSIZE + DNBD3SIZE=$(($DEFPARTSIZE*1024*1024)) +else + GBSIZE=$DNBD3SIZE + DNBD3SIZE=$(($DNBD3SIZE*1024*1024)) +fi +echo "\tSize: $DNBD3SIZE Bytes ($GBSIZE GB)" +echo "\tCreating dnbd3 partiton..." +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 + +echo "Boot:" +test $BOOTID +if [ $? -eq 1 ]; then + BOOTID=$DEFBOOTID +fi +echo "\tID: $BOOTID" +test $BOOTSIZE +if [ $? -eq 1 ]; then + GBSIZE=$DEFPARTSIZE + BOOTSIZE=$(($DEFPARTSIZE*1024*1024)) +else + GBSIZE=$BOOTSIZE + BOOTSIZE=$(($BOOTSIZE*1024*1024)) +fi +echo "\tSize: $BOOTSIZE Bytes ($GBSIZE GB)" +echo "\tCreating boot partiton..." +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 diff --git a/remote/modules/partitioner/partitions b/remote/modules/partitioner/partitions new file mode 100644 index 00000000..8ec007ff --- /dev/null +++ b/remote/modules/partitioner/partitions @@ -0,0 +1,17 @@ +major minor #blocks name + + 8 0 488386584 sda + 8 1 1 sda1 + 8 2 27343872 sda2 + 8 3 45898437 sda3 + 8 4 52928512 sda4 + 8 5 345713664 sda5 + 8 6 8226816 sda6 + 11 0 1048575 sr0 + 8 0 386584 sdb + 8 1 1 sdb1 + 8 2 343872 sdb2 + 8 3 45898437 sdb3 + 8 0 1838584 vda + 8 1 1 vda1 + 8 2 27343872 vda2
\ No newline at end of file |