parse_arguments() { FORCE=0 while getopts ":fh" o; do case $o in f) FORCE=1;; h) help && exit 0;; \?) 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 )) echo "min size: $MIN_SIZE" BEST_SIZE=$(( $(gibibytes_to_bytes 200) + 2 * $RAM_SIZE )) echo "best size: $BEST_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=$(gibibytes_to_bytes $2) CONDOR_SIZE=$(gibibytes_to_bytes $3) SWAP_SIZE=$(gibibytes_to_bytes $4) VM_SIZE=$(gibibytes_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 }