parse_arguments() { FORCE=0 SCRIPT_OUTPUT=/proc/self/fd/1 PROGRAM_OUTPUT=/dev/null while getopts ":fhvq" o; do case $o in f) FORCE=1;; 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 MODE=manual else usage && exit fi DEVICE="$1" check_device DEVICE_SIZE=$(blockdev --getsize64 "${DEVICE}") RAM_SIZE=$(kibibytes_to_bytes $(grep MemTotal: /proc/meminfo | awk '{print $2}')) $MODE $@ } default() { MIN_SIZE=$(( $(gibibytes_to_bytes 100) + $RAM_SIZE + 2 )) BEST_SIZE=$(( $(gibibytes_to_bytes 200) + 2 * $RAM_SIZE )) if [ $DEVICE_SIZE -lt $MIN_SIZE ]; then fatal ${MINSIZE_E} "to use default mode, the disk must have at least $(bytes_to_gibibytes ${MIN_SIZE})GB". elif [ $DEVICE_SIZE -lt $BEST_SIZE ] && [ $FORCE -ne 1 ]; then fatal ${BESTSIZE_E} "to use default mode, it is reccomended that the disk have at least $(bytes_to_gibibytes ${BEST_SIZE})GB. If you know what you are doing, you can force default mode with -f". fi VM_SIZE=$(gibibytes_to_bytes 100) SWAP_SIZE=$(( $RAM_SIZE + $(gibibytes_to_bytes 1) )) FREE_SIZE=$(( ( $DEVICE_SIZE - $VM_SIZE - $SWAP_SIZE ) / 10 )) CONDOR_SIZE=$(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 4 )) TEMP_SIZE=$(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 6 )) } manual() { TEMP_SIZE=$(to_bytes $2) if [ $(($TEMP_SIZE % 512)) -ne 0 ] ; then fatal ${CHUNK_E} "size must be multiple of 512 bytes" fi CONDOR_SIZE=$(to_bytes $3) SWAP_SIZE=$(to_bytes $4) VM_SIZE=$(to_bytes $5) if [ $(( $TEMP_SIZE + $CONDOR_SIZE + $SWAP_SIZE + $VM_SIZE )) -gt $DEVICE_SIZE ]; then fatal ${MANUALSIZE_E} "can't use this sizes: ${DEVICE} has only $(bytes_to_gibibytes ${DEVICE_SIZE})G" fi } usage() { 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 }