summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Pereira Neves2014-10-13 21:53:42 +0200
committerMichael Pereira Neves2014-10-28 14:16:29 +0100
commit8ee20e54090b49ee50303d09ce482f9db8c43550 (patch)
tree57fa75646bc13ce119e19391047017b72a7b3397
parent[partitioner] updated default partition table for partitioner and setup-parti... (diff)
downloadtm-scripts-8ee20e54090b49ee50303d09ce482f9db8c43550.tar.gz
tm-scripts-8ee20e54090b49ee50303d09ce482f9db8c43550.tar.xz
tm-scripts-8ee20e54090b49ee50303d09ce482f9db8c43550.zip
[partitioner] Create function for warning and error messages
-rwxr-xr-xserver/modules/partitioner/opt/openslx/scripts/systemd-partitioner133
1 files changed, 70 insertions, 63 deletions
diff --git a/server/modules/partitioner/opt/openslx/scripts/systemd-partitioner b/server/modules/partitioner/opt/openslx/scripts/systemd-partitioner
index ac1875d8..f8b7b819 100755
--- a/server/modules/partitioner/opt/openslx/scripts/systemd-partitioner
+++ b/server/modules/partitioner/opt/openslx/scripts/systemd-partitioner
@@ -14,11 +14,33 @@
#############################################################################
-. /opt/openslx/config || { echo "Could not source config."; exit 23; }
+perror () {
+ echo "ERROR: $@" 1>&2
+ if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
+ dialog --title "ERROR" --stdout --msgbox "$@" 15 60
+ else
+ dialog --title "ERROR" --no-cancel --stdout --pause "$@\n\nReboot in:" 15 60 600
+ reboot
+ fi
+ exit 1
+}
+
+pwarning () {
+ echo "WARNING: $@" 1>&2
+ if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
+ dialog --title "WARNING" --stdout --msgbox "$@" 15 60
+ else
+ dialog --title "WARNING" --stdout --infobox "$@" 15 60
+ sleep 5
+ fi
+}
+
+. /opt/openslx/config || perror "Could not source config."
#set -x
#exec > /log 2>&1
+
#--------------------------------------------------------------------------------------
#Gathering partition information
@@ -36,12 +58,7 @@ PARTITIONSPATH="/proc/partitions"
# picking disk that will be used
DISKS=$(cat $PARTITIONSPATH | tr -s ' ' | cut -d ' ' -f5 | grep -e "[a-z]$")
if [ -z "$DISKS" ]; then
- if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog --title "ERROR" --stdout --msgbox "Can't find an hard disk." 10 40
- else
- echo "ERROR: Can't find an hard disk." 1>&2
- fi
- exit 1
+ perror "Can't find an hard disk."
fi
#--------------------------------------------------------------------------------------
@@ -51,10 +68,7 @@ define_partition_table() {
44,10G,/tmp
45,10G,/var/scratch
82,4G'
- echo "INFO: You didn't define a partition table in config. Using default partition table:\n$SLX_PARTITION_TABLE" 1>&2
- if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog --title "INFO" --stdout --msgbox "You didn't define a partition table in config. Using default partition table:\n$SLX_PARTITION_TABLE" 10 40
- fi
+ pwarning "You didn't define a partition table in config. Using default partition table:\n$SLX_PARTITION_TABLE"
fi
}
@@ -72,13 +86,12 @@ choose_disk() {
local disk_number=$(echo $DISKS | tr ' ' \\n | wc -l)
if [ "$SLX_AUTOMATIC_PARTITIONING" = "yes" ]; then
if [ -n "$SLX_CHOOSEN_DISK" ]; then
- echo $DISKS | grep -wq "$SLX_CHOOSEN_DISK" || { echo "ERROR: Automatic partitioning enabled, but in config specified $SLX_CHOOSEN_DISK was not found." 1>&2; return 1; }
+ echo $DISKS | grep -wq "$SLX_CHOOSEN_DISK" || perror "ERROR: Automatic partitioning enabled, but in config specified $SLX_CHOOSEN_DISK was not found."
elif [ "$disk_number" -eq 1 ]; then
SLX_CHOOSEN_DISK=$DISKS
- echo "INFO: Automatic partitioning enabled, but SLX_CHOOSEN_DISK not specified in config. Choosing only existing disk: $DISKS for partitioning." 1>&2
+ pwarning "Automatic partitioning enabled, but SLX_CHOOSEN_DISK not specified in config. Choosing only existing disk: $DISKS for partitioning."
else
- echo "ERROR: Automatic partitioning enabled, but SLX_CHOOSEN_DISK not specified in config. More than one disk exists, please specify disk in config and run again." 1>&2
- return 1
+ perror "Automatic partitioning enabled, but SLX_CHOOSEN_DISK not specified in config. More than one disk exists, please specify disk in config and run again."
fi
else
local dialog_string="Existing disks with partition tables:\n\n"
@@ -111,12 +124,11 @@ choose_disk() {
if [ $(echo $DISKS | tr ' ' \\n | wc -l) -gt 0 ]; then
SLX_CHOOSEN_DISK=$(echo $options | xargs dialog --title "Choose a disk to partition:" --no-tags --cr-wrap --no-collapse --stdout --menu "${dialog_string}" 0 0 0)
if [ -z $SLX_CHOOSEN_DISK ]; then
- echo "INFO: Partitioning aborted by user." 1>&2
- return 1
+ pwarning "Partitioning aborted by user."
+ exit 1
fi
else
- dialog --title "ERROR" --stdout --msgbox "Can't find a hard disk." 10 40
- return 2
+ perror "Can't find a hard disk."
fi
fi
CHOOSEN_DISK_SIZE=$(echo "$(cat $PARTITIONSPATH | grep -e $SLX_CHOOSEN_DISK$ | tr -s ' ' | cut -d ' ' -f4)*$BLOCKSIZE" | bc)
@@ -130,11 +142,7 @@ check_disk_size() {
NEEDED_DISK_SPACE=$(echo "$part_space*1024*1024*1024+$part_number*1024*1024" | bc)
if [ $(echo "$CHOOSEN_DISK_SIZE<$NEEDED_DISK_SPACE" | bc) -eq 1 ]; then
- echo "ERROR: Insufficient space on disk /dev/$SLX_CHOOSEN_DISK\n DISK SIZE: $(size_conv $CHOOSEN_DISK_SIZE)\n REQUIRED SIZE: $(size_conv $NEEDED_DISK_SPACE)" 1>&2
- if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog --title "ERROR" --stdout --msgbox "Insufficient space on disk /dev/$SLX_CHOOSEN_DISK\n DISK SIZE: $(size_conv $CHOOSEN_DISK_SIZE)\n REQUIRED SIZE: $(size_conv $NEEDED_DISK_SPACE) " 6 40
- fi
- return 1
+ perror "Insufficient space on disk /dev/$SLX_CHOOSEN_DISK\n DISK SIZE: $(size_conv $CHOOSEN_DISK_SIZE)\n REQUIRED SIZE: $(size_conv $NEEDED_DISK_SPACE)"
fi
}
@@ -142,13 +150,13 @@ select_partition_type() {
# choosing the partition type (MSDOS or GPT) if it wasn't set in config file
if [ -z "$SLX_PARTITION_TYPE" ]; then
if [ "$SLX_AUTOMATIC_PARTITIONING" = "yes" ]; then
- echo "INFO: SLX_PARTITION_TYPE not defined in config, using default: msdos" 1>&2
+ pwarning "SLX_PARTITION_TYPE not defined in config, using default: msdos"
SLX_PARTITION_TYPE=msdos
else
SLX_PARTITION_TYPE=$(dialog --no-tags --title "Choose a partition type:" --menu --stdout "Partitions types:" 0 0 0 "msdos" " MSDOS " "GPT" " GPT ")
if [ -z $SLX_PARTITION_TYPE ]; then
- echo "INFO: Partitioning aborted by user." 1>&2
- return 1
+ pwarning "Partitioning aborted by user."
+ exit 1
fi
fi
fi
@@ -211,21 +219,19 @@ confirm_partitioning() {
# asking confirmation to create the partitions
dialog --title "WARNING" --stdout --defaultno --yesno "$dialog_string" 0 0
if [ $? -eq 1 ]; then
- echo "INFO: Partitioning aborted by user." 1>&2
- return 1
+ pwarning "Partitioning aborted by user."
+ exit 1
fi
}
# function to create gpt type partition tables (uses sgdisk)
partition_disk_gpt() {
# delete partition table
- sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2>&1 # erase all partitions
+ sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2>&1 || perror "Error erasing old partition table"
#set dialog
- if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog_string="New partitions created:\n\n"
- echo "0" | dialog --stdout --gauge "$dialog_string" 0 0 0
- fi
+ dialog_string="Partitions created:\n\n"
+ echo "0" | dialog --title "Partitioner" --stdout --gauge "$dialog_string" 0 0 0
# loop that will create each GPT partition, change GUIDS, change names, and set bootable flags.
local counter=1
@@ -250,51 +256,49 @@ partition_disk_gpt() {
esac
#set size of partition
- sgdisk /dev/${SLX_CHOOSEN_DISK} -n ${counter}:0:+${size}G 1>&2
+ sgdisk /dev/${SLX_CHOOSEN_DISK} -n ${counter}:0:+${size}G 1>&2 || perror "Error setting size of GPT partition ${SLX_CHOOSEN_DISK}${counter}"
#set id of partition
if [ "${id}" = "82" ] || [ "${id}" = "83" ]; then
- sgdisk /dev/${SLX_CHOOSEN_DISK} -t ${counter}:${id}00 1>&2
+ sgdisk /dev/${SLX_CHOOSEN_DISK} -t ${counter}:${id}00 1>&2 || perror "Error setting id ${id} of GPT partition ${SLX_CHOOSEN_DISK}${counter}"
else
- sgdisk /dev/${SLX_CHOOSEN_DISK} -t ${counter}:${id}000000-0000-0000-0000-000000000000 -c ${counter}:\"${mountpoint}\" 1>&2
+ sgdisk /dev/${SLX_CHOOSEN_DISK} -t ${counter}:${id}000000-0000-0000-0000-000000000000 -c ${counter}:\"${mountpoint}\" 1>&2 || perror "Error setting id ${id} of GPT partition ${SLX_CHOOSEN_DISK}${counter}"
fi
#set boot flag
if [ "$bootable" -eq 1 ]; then
- sgdisk /dev/${SLX_CHOOSEN_DISK} -A ${counter}:set:2 1>&2
+ sgdisk /dev/${SLX_CHOOSEN_DISK} -A ${counter}:set:2 1>&2 || perror "Error setting boot flag for GPT partition ${SLX_CHOOSEN_DISK}${counter}"
fi
- if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- #update dialog status
- [ "$id" = "82" ] && mountpoint="swap"
- dialog_string="${dialog_string}${mountpoint} (/dev/"${SLX_CHOOSEN_DISK}${counter}")\n"
- if [ "${id}" = "82" ]; then
- dialog_string="${dialog_string} GUID: 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n"
- elif [ "${id}" = "83" ]; then
- dialog_string="${dialog_string} GUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n"
- else
- dialog_string="${dialog_string} GUID: "$id"000000-0000-0000-0000-000000000000\n"
- fi
- dialog_string="${dialog_string} Size: "$size" GB\n"
- echo $(echo "(100/$part_number)*$counter" | bc) | dialog --stdout --gauge "${dialog_string}" 0 0 0
+ #update dialog status
+ [ "$id" = "82" ] && mountpoint="swap"
+ dialog_string="${dialog_string}${mountpoint} (/dev/"${SLX_CHOOSEN_DISK}${counter}")\n"
+ if [ "${id}" = "82" ]; then
+ dialog_string="${dialog_string} GUID: 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n"
+ elif [ "${id}" = "83" ]; then
+ dialog_string="${dialog_string} GUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4\n"
+ else
+ dialog_string="${dialog_string} GUID: "$id"000000-0000-0000-0000-000000000000\n"
fi
+ dialog_string="${dialog_string} Size: "$size" GB\n"
+ echo $(echo "(100/$part_number)*$counter" | bc) | dialog --title "Partitioner" --stdout --gauge "${dialog_string}" 0 0 0
counter=$(($counter+1))
done
unset IFS
if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog --title "Creating partitions..." --stdout --msgbox "$dialog_string" 0 0
+ dialog --title "Partitioner" --stdout --msgbox "$dialog_string" 0 0
fi
}
#function to create msdos type partition tables (uses sfdisk)
partition_disk_msdos(){
# delete partition table
- sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2>&1 # erase all partitions
+ sgdisk -Z /dev/$SLX_CHOOSEN_DISK > /dev/null 2>&1 || perror "Error erasing old partition table"
#set dialog
- dialog_string="New partitions created:\n\n"
+ dialog_string="Partitions created:\n\n"
# constructing the sfdisk input file
echo "unit: sectors"> /tmp/partitiontable.tmp
@@ -350,27 +354,30 @@ partition_disk_msdos(){
done
unset IFS
- sfdisk -q --no-reread -f /dev/${SLX_CHOOSEN_DISK} < /tmp/partitiontable.tmp 1>&2
+ sfdisk -q --no-reread -f /dev/${SLX_CHOOSEN_DISK} < /tmp/partitiontable.tmp 1>&2 || return 0
# rm -f /tmp/partitiontable.tmp
if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- dialog --title "Creating partitions..." --stdout --msgbox "$dialog_string" 0 0
+ dialog --title "Partitioner" --stdout --msgbox "$dialog_string" 0 0
+ else
+ dialog --title "Partitioner" --stdout --infobox "$dialog_string" 0 0
+ sleep 5
fi
}
-define_partition_table || exit 1;
-choose_disk || exit 1;
-select_partition_type || exit 1;
+define_partition_table
+choose_disk
+select_partition_type
if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then
- confirm_partitioning || exit 1;
+ confirm_partitioning
fi
-check_disk_size || exit 1;
+check_disk_size
if [ $SLX_PARTITION_TYPE = 'GPT' ]; then
- partition_disk_gpt || { echo "Error while writing GPT partition table to disk" 1>&2; exit 1; }
+ partition_disk_gpt
else
- partition_disk_msdos || { echo "Error while writing msdos partition table to disk" 1>&2; exit 1; }
+ partition_disk_msdos
fi
if [ "$SLX_AUTOMATIC_PARTITIONING" != "yes" ]; then