Browse Source

Implemented q and v flags

Matteo Zeccoli Marazzini 5 years ago
parent
commit
ab56767a28
4 changed files with 97 additions and 66 deletions
  1. 0 0
      lol
  2. 64 0
      newdisk-automator
  3. 0 62
      newdisk-automator.sh
  4. 33 4
      parse-arguments.sh

+ 0 - 0
lol


+ 64 - 0
newdisk-automator

@@ -0,0 +1,64 @@
+#!/bin/bash
+
+DIR="/home/ravioli/newdisk-automator"
+PROGRAM_NAME="$0"
+
+. "${DIR}/error.sh"
+. "${DIR}/parse-arguments.sh"
+. "${DIR}/utils.sh"
+. "${DIR}/check-device.sh"
+
+LVM_SUPPRESS_FD_WARNINGS=1
+
+parse_arguments $@
+
+# removing lvm and other filesystem signatures
+if [ $LVM == 1 ]; then
+	echo "Erasing disk signatures..." >${SCRIPT_OUTPUT}
+	vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name) >${PROGRAM_OUTPUT} 2>&1 
+fi
+
+wipefs -a ${DEVICE}[[:digit:]]* >${PROGRAM_OUTPUT} 2>&1 
+wipefs -a ${DEVICE} >${PROGRAM_OUTPUT} 2>&1 
+
+echo "Partitioning the disk..." >${SCRIPT_OUTPUT}
+# partitioning the disk
+sfdisk "${DEVICE}" <<-sfdisk-script-end >${PROGRAM_OUTPUT} 2>&1 
+# Create a new partition table on the specified disk, and create a new Linux LVM partition
+#
+# partition table info
+label: gpt
+#
+# partitions info
+#start	size	type	bootable
+,	,31	,
+sfdisk-script-end
+
+# LVM
+echo "Creating physical volume ${DEVICE}1..." >${SCRIPT_OUTPUT}
+pvcreate "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 
+echo "Creating volume group localDisk..." >${SCRIPT_OUTPUT}
+vgcreate localDisk "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 
+
+if [ "${SWAP_SIZE}" != 0 ] ; then
+	echo "Creating logical volume swap..." >${SCRIPT_OUTPUT}
+	lvcreate -W n -C y -L "${SWAP_SIZE}B" localDisk -n swap >${PROGRAM_OUTPUT} 2>&1 
+	echo "Formatting swap lv..." >${SCRIPT_OUTPUT}
+	mkswap /dev/localDisk/swap >${PROGRAM_OUTPUT} 2>&1 
+fi
+if [ "${CONDOR_SIZE}" != 0 ] ; then
+	echo "Creating logical volume swap..." >${SCRIPT_OUTPUT}
+	lvcreate -W n -L "${CONDOR_SIZE}B" localDisk -n condor >${PROGRAM_OUTPUT} 2>&1 
+	echo "Formatting condor lv..." >${SCRIPT_OUTPUT}
+	mkfs.ext4 /dev/localDisk/condor >${PROGRAM_OUTPUT} 2>&1 
+fi
+if [ "${TEMP_SIZE}" != 0 ] ; then
+	echo "Creating logical volume tempdir..." >${SCRIPT_OUTPUT}
+	lvcreate -W n -L "${TEMP_SIZE}B" localDisk -n tempdir >${PROGRAM_OUTPUT} 2>&1
+	echo "Formatting tempdir lv..." >${SCRIPT_OUTPUT}
+	mkfs.ext4 /dev/localDisk/tempdir >${PROGRAM_OUTPUT} 2>&1
+fi
+if [ "${VM_SIZE}" != 0 ] ; then
+	echo "Creating logical volume calcolo..." >${SCRIPT_OUTPUT}
+	lvcreate -W n -L "${VM_SIZE}B" localDisk -n calcolo >${PROGRAM_OUTPUT} 2>&1 
+fi

+ 0 - 62
newdisk-automator.sh

@@ -1,62 +0,0 @@
-#!/bin/bash
-
-DIR="/home/ravioli/newdisk-automator"
-PROGRAM_NAME="$0"
-
-. "${DIR}/error.sh"
-. "${DIR}/parse-arguments.sh"
-. "${DIR}/utils.sh"
-. "${DIR}/check-device.sh"
-
-parse_arguments $@
-
-# removing lvm and other filesystem signatures
-if [ $LVM == 1 ]; then
-	echo "Erasing disk signatures..."
-	vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name)
-fi
-
-wipefs -a ${DEVICE}[[:digit:]]*
-wipefs -a ${DEVICE}
-
-echo "Partitioning the disk..."
-# partitioning the disk
-sfdisk "${DEVICE}" <<-sfdisk-script-end
-# Create a new partition table on the specified disk, and create a new Linux LVM partition
-#
-# partition table info
-label: gpt
-#
-# partitions info
-#start	size	type	bootable
-,	,31	,
-sfdisk-script-end
-
-# LVM
-echo "Creating physical volume ${DEVICE}1..."
-pvcreate "${DEVICE}1"
-echo "Creating volume group localDisk..."
-vgcreate localDisk "${DEVICE}1"
-
-if [ "${SWAP_SIZE}" != 0 ] ; then
-	echo "Creating logical volume swap..."
-	lvcreate -W n -C y -L "${SWAP_SIZE}B" localDisk -n swap
-	echo "Formatting swap lv..."
-	mkswap /dev/localDisk/swap
-fi
-if [ "${CONDOR_SIZE}" != 0 ] ; then
-	echo "Creating logical volume swap..."
-	lvcreate -W n -L "${CONDOR_SIZE}B" localDisk -n condor
-	echo "Formatting condor lv..."
-	mkfs.ext4 /dev/localDisk/condor
-fi
-if [ "${TEMP_SIZE}" != 0 ] ; then
-	echo "Creating logical volume tempdir..."
-	lvcreate -W n -L "${TEMP_SIZE}B" localDisk -n tempdir
-	echo "Formatting tempdir lv..."
-	mkfs.ext4 /dev/localDisk/tempdir
-fi
-if [ "${VM_SIZE}" != 0 ] ; then
-	echo "Creating logical volume calcolo..."
-	lvcreate -W n -L "${VM_SIZE}B" localDisk -n calcolo
-fi

+ 33 - 4
parse-arguments.sh

@@ -1,15 +1,19 @@
 parse_arguments()
 {
 	FORCE=0
-	while getopts ":fh" o; do
+	SCRIPT_OUTPUT=/proc/self/fd/1
+	PROGRAM_OUTPUT=/dev/null
+	while getopts ":fhvq" o; do
 		case $o in
 		f) FORCE=1;;
-		h) cat ${DIR}/helpfile && exit 0;;
+		h) help && exit 0;;
+		v) SCRIPT_OUTPUT=/proc/self/fd/1 && PROGRAM_OUTPUT=/proc/self/fd/1;;
+		q) SCRIPT_OUTPUT=/dev/null && PROGRAM_OUTPUT=/dev/null;;
 		\?) usage && exit;;
 		esac
 	done
 	shift $(( $OPTIND - 1 ))
-	
+
 	if [ $# -eq 1 ]; then
 		MODE=default
 	elif [ $# -eq 5 ] && [ $FORCE -ne 1 ]; then
@@ -57,6 +61,31 @@ manual()
 
 usage()
 {
-	echo "Usage: ${PROGRAM_NAME} [-f] device | device temp condor swap vm"
+	echo -e "Usage:\n${PROGRAM_NAME} [-qvf] device\n${PROGRAM_NAME} [-qv] device temp_size condor_size swap_size vm_size"
 	echo "Try -h for help"
 }
+
+help()
+{
+	cat <<-help-end
+newdisk automator
+This program can be used in two mode: automatic and manual.
+
+Automatic:
+newdisk-automator [-f] device
+device is partitioned according to the following scheme:
+	- calcolo: 100GB
+	- swap: ram size + 1GB
+	- free space: 10% of the total
+	- condor: 40% of remaining space
+	- tempdir: 60% of remaining space
+If the size of the disk is less than 102GB + ram size, this mode cannot be used.
+If the size of the disk is greater than the minimum size, but still less than (100GB + ram size) * 2, to use this mode the -f option must be passed.
+Be careful: in the automatic mode, calcolo and swap size are fixed, and forcing it with -f could result in having very small tempdir and condor partitions. 
+
+Manual:
+newdisk-automator device temp_size condor_size swap_size vm_size
+The partitions are assigned the size passed on the command line. b, K, M, G can be appended to the sizes for bytes, kibibytes, mebibytes and gibibytes. The default is bytes.
+If the total passed with the command line is greater than the size of the disk, the program stops.
+help-end
+}