summaryrefslogtreecommitdiffstats
path: root/server/modules/partitioner/opt/openslx/scripts/partitioner
diff options
context:
space:
mode:
Diffstat (limited to 'server/modules/partitioner/opt/openslx/scripts/partitioner')
-rwxr-xr-xserver/modules/partitioner/opt/openslx/scripts/partitioner358
1 files changed, 0 insertions, 358 deletions
diff --git a/server/modules/partitioner/opt/openslx/scripts/partitioner b/server/modules/partitioner/opt/openslx/scripts/partitioner
deleted file mode 100755
index a7ba064a..00000000
--- a/server/modules/partitioner/opt/openslx/scripts/partitioner
+++ /dev/null
@@ -1,358 +0,0 @@
-#!/bin/bash
-
-# set -e
-
-PARTITIONSPATH="/proc/partitions"
-CONFIGPATH="/opt/openslx/config"
-
-# BLOCKSIZE=$(sfdisk -l /dev/$SLX_CHOOSEN_DISK | grep -o -e "blocks of [0-9]* bytes" | cut -d ' ' -f3)
-BLOCKSIZE=1024
-
-. $CONFIGPATH
-# testing if the sizes and ID's of the disk is defined in the config file
-
-# 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." 10 40
- exit 1
-fi
-if [ -z "$SLX_CHOOSEN_DISK" ]; then
- if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
- dialog --msgbox "ERROR: You didn' define any hard disk in your configuration file." 10 40
- exit 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)*$BLOCKSIZE))
- PARTS=$(cat $PARTITIONSPATH | grep -e $disk[0-9] | tr -s ' ' | cut -d ' ' -f5)
- GBSIZE=$(echo "scale=2; $DISKSIZE/1024/1024/1024" | bc -l)
- 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)*1024))
- 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"
- 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)
- if [ $? -eq 1 ]; then
- 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
- exit 1;
- fi
- echo $DISKS | tr ' ' \\n | grep -e ^$SLX_CHOOSEN_DISK$ > /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
- SLX_CHOOSEN_DISK=$(echo $DISKS | tr ' ' \\n | head -n1)
- else
- dialog --msgbox "ERROR: Can't find an hard disk." 10 40
- exit 1
- fi
-fi
-if [ -z "$SLX_PARTITION_TABLE" ]; then
- if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
- SLX_PARTITION_TABLE='
- 44,10G,/tmp
- 45,10G,/var/scratch'
- else
- dialog --msgbox "ERROR: You didn't set a valid partition table. Please check your config file." 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
-for PARTITION in $SLX_PARTITION_TABLE; do
- IFS=,
- set $PARTITION
- if [ $COUNTER -eq 4 ]; then
- COUNTER=$(($COUNTER+1))
- fi
- echo "id: $1"
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/id"]=$1
- shift
- echo "size: $1"
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/size"]=$(echo $1 | egrep -o "[0-9]*")
- shift
- if [ -n $1 ]; then
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/mountpoint"]=$1
- fi
- shift
- if [[ "$*" == *bootable* ]]; then
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=1
- else
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/bootable"]=0
- fi
- # set the partitions to non-existents
- PARTTBL["$SLX_CHOOSEN_DISK$COUNTER/exists"]=0
- COUNTER=$(($COUNTER+1))
-done
-unset IFS
-# 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))
-NEEDED_SPACE=0
-for (( i = 1; i < $COUNTER; i++ )); do
- if [[ $i -ne 4 ]]; then
- NEEDED_SPACE=$(($NEEDED_SPACE+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}))
- fi
-done
-NEEDED_SPACE=$(($NEEDED_SPACE*1024*1024*1024+$COUNTER*1024*1024))
-if [ $DISKSIZE -lt $NEEDED_SPACE ]; then
- dialog --msgbox "ERROR: Insufficient space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
- exit 1
-fi
-
-# choosing the partition type (MSDOS or GPT) if it wasn't set in config file
-if [ -z "$SLX_PARTITION_TYPE" ] && [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then
- if [ $SLX_AUTOMATIC_PARTITIONING = "yes" ]; then
- SLX_PARTITION_TYPE=msdos
- else
- 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
- exit 1
- fi
- if [ $ANS -eq 1 ]; then
- SLX_PARTITION_TYPE=msdos
- else
- SLX_PARTITION_TYPE=GPT
- fi
- fi
-fi
-
-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
- fi
-fi
-
-# pick the size of a sector (usually 512 bytes)
-# SECTORSIZE=$(sfdisk /dev/$SLX_CHOOSEN_DISK -l -u S 2> /dev/null | grep Units | cut -d ' ' -f5)
-SECTORSIZE=512
-
-if [[ $USED -eq 0 ]]; then
- SLX_DELETE_PARTITION_TABLE="yes"
-fi
-
-if [ $SLX_DELETE_PARTITION_TABLE = "yes" ]; then
- # delete partition table
- sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2> /dev/null # erase all partitions
-
- if [ $SLX_PARTITION_TYPE = 'GPT' ]; then
- DIALOGSTR="Creating Partitions...\n\n"
- echo "0" | dialog --gauge "$DIALOGSTR" 0 0 0
- for (( i = 1; i < $COUNTER; i++ )); do # loop that will create each GPT partition, change GUIDS, change names, and set bootable flags.
- if [ $i -ne 4 ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -n $i:0:+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}G 2> /dev/null > /dev/null
- # dialog --msgbox "$DIALOGSTR" 0 0
- if [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "82" ] || [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "83" ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -t $i:${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}00
- else
- sgdisk /dev/$SLX_CHOOSEN_DISK -t $i:${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}000000-0000-0000-0000-000000000000\
- sgdisk /dev/$SLX_CHOOSEN_DISK -c $i:\"${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}\" >/dev/null 2>/dev/null
- fi
- if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/bootable"]} -eq 1 ]; then
- # set the bootable flag
- sgdisk /dev/$SLX_CHOOSEN_DISK -A $i:set:2 >/dev/null 2>/dev/null
- fi
- SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
- ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}
- MOUNTPOINT=${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}
- DIALOGSTR=$DIALOGSTR$MOUNTPOINT" (/dev/"$SLX_CHOOSEN_DISK$i")\n"
- if [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "82" ]; then
- DIALOGSTR=$DIALOGSTR" GUID: 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n"
- elif [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "83" ]; then
- DIALOGSTR=$DIALOGSTR" GUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n"
- else
- DIALOGSTR=$DIALOGSTR" GUID: "$ID"000000-0000-0000-0000-000000000000\n"
- fi
- DIALOGSTR=$DIALOGSTR" Size: "$SIZE" Bytes ("${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}" GB)\n"
- echo $(( $i*100/($COUNTER-1) )) | dialog --gauge "$DIALOGSTR" 0 0 0
- fi
- done
- else
- # 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
- 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= "$(($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 2> /dev/null
- # rm -f /tmp/partitiontable.tmp
-
- DIALOGSTR="Creating Partitions...\n\n"
- for (( i = 1; i < $COUNTER; i++ )); do
- if [ $i -lt 4 ]; then
- SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
- ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}
- MOUNTPOINT=${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}
- DIALOGSTR=$DIALOGSTR$MOUNTPOINT" (/dev/"$SLX_CHOOSEN_DISK$i")\n"
- DIALOGSTR=$DIALOGSTR" Type: Primary\n"
- DIALOGSTR=$DIALOGSTR" ID: "$ID"\n"
- DIALOGSTR=$DIALOGSTR" Size: "$SIZE" Bytes ("${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}" GB)\n"
- elif [ $i -gt 4 ]; then
- SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
- ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}
- MOUNTPOINT=${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}
- DIALOGSTR=$DIALOGSTR$MOUNTPOINT" (/dev/"$SLX_CHOOSEN_DISK$i")\n"
- DIALOGSTR=$DIALOGSTR" Type: Logical\n"
- DIALOGSTR=$DIALOGSTR" ID: "$ID"\n"
- DIALOGSTR=$DIALOGSTR" Size: "$SIZE" Bytes ("${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}" GB)\n"
- fi
- done
- fi
-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'
- NONEXISTENT_PARTITIONS=0
- for (( i = 1; i < $COUNTER; i++ )); do
- if [ $i -ne 4 ]; then
- for PART in $PARTS; do
- if [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "82" ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} 2> /dev/null | grep "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F" > /dev/null
- elif [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "83" ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} 2> /dev/null | grep "0FC63DAF-8483-4772-8E79-3D69D8477DE4" > /dev/null
- else
- sgdisk /dev/$SLX_CHOOSEN_DISK -i ${PART:3} 2> /dev/null | grep ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}"000000-0000-0000-0000-000000000000" > /dev/null
- fi
- if [ $? -eq 0 ]; then
- PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$PART
- NEEDED_SPACE=$(($NEEDED_SPACE-${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
- break
- fi
- done
- if [[ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = "0" ]]; then
- NONEXISTENT_PARTITIONS=$(($NONEXISTENT_PARTITIONS+1))
- fi
- fi
- done
- # checking if there's sufficient space for the new partitions.
- if [[ $FREESPACE -lt $NEEDED_SPACE ]]; then
- dialog --msgbox "ERROR: Insufficient free space in disk /dev/$SLX_CHOOSEN_DISK." 6 40
- exit 1
- fi
- if [[ $NONEXISTENT_PARTITIONS -eq 0 ]]; then
- DIALOGSTR="All your requested partitions already exists.\n\n"
- DIALOGSTR=$DIALOGSTR"Partition ID\n"
- for (( i = 1; i < $COUNTER; i++ )); do
- if [[ $i -ne 4 ]]; then
- DIALOGSTR=$DIALOGSTR"${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} ${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}\n"
- fi
- done
- else
- DIALOGSTR="Creating partitions...\n\n"
- echo "0" | dialog --gauge "$DIALOGSTR" 0 0 0
- CREATED=0
- for (( i = 1; i < $COUNTER; i++ )); do
- j=1
- if [[ $i -ne 4 ]]; then
- if [[ "${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]}" = "0" ]]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -n $j:0:+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}G 2> /dev/null > /dev/null
- while [[ $? -eq 4 ]]; do
- j=$(($j+1))
- sgdisk /dev/$SLX_CHOOSEN_DISK -n $j:0:+${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}G 2> /dev/null > /dev/null
- done
- PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]=$SLX_CHOOSEN_DISK$j
- SIZE=$((${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}*1024*1024*1024))
- ID=${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}
- MOUNTPOINT=${PARTTBL["$SLX_CHOOSEN_DISK$i/mountpoint"]}
- DIALOGSTR=$DIALOGSTR$MOUNTPOINT" (/dev/"${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]}")\n"
- if [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "82" ]; then
- DIALOGSTR=$DIALOGSTR" GUID: 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n"
- elif [ "${PARTTBL["$SLX_CHOOSEN_DISK$i/id"]}" = "83" ]; then
- DIALOGSTR=$DIALOGSTR" GUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n"
- else
- sgdisk /dev/$SLX_CHOOSEN_DISK -t $j:$ID"000000-0000-0000-0000-000000000000" -c $j:$MOUNTPOINT >/dev/null 2>/dev/null
- DIALOGSTR=$DIALOGSTR" GUID: "$ID"000000-0000-0000-0000-000000000000\n"
- fi
- DIALOGSTR=$DIALOGSTR" Size: "$SIZE" Bytes ("${PARTTBL["$SLX_CHOOSEN_DISK$i/size"]}" GB)\n"
- CREATED=$(($CREATED+1))
- echo $(( $CREATED*100/($NONEXISTENT_PARTITIONS) )) | dialog --gauge "$DIALOGSTR" 0 0 0
- fi
- if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/bootable"]} -eq 1 ]; then
- sgdisk /dev/$SLX_CHOOSEN_DISK -A $j:set:2 >/dev/null 2>/dev/null
- fi
- fi
- done
- fi
-else
-# finding existent partitions in MS-DOS
- echo 'MSDOS'
- for PART in $PARTS; do
- for (( i = 1; i < $COUNTER; i++ )); do
- if [ $i -ne 4 ]; then
- if [ ${PARTTBL["$SLX_CHOOSEN_DISK$i/exists"]} = 0 ]; then
- 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=${DIALOGSTR/Creating Partitions.../New partitions created:}
-dialog --msgbox "$DIALOGSTR" 0 0