|
@@ -3,6 +3,8 @@ parse_arguments()
|
|
|
FORCE=0
|
|
|
SCRIPT_OUTPUT=/proc/self/fd/1
|
|
|
PROGRAM_OUTPUT=/dev/null
|
|
|
+
|
|
|
+ # Parse options
|
|
|
while getopts ":fhvq" o; do
|
|
|
case $o in
|
|
|
f) FORCE=1;;
|
|
@@ -14,6 +16,9 @@ parse_arguments()
|
|
|
done
|
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
|
|
+ # The 1st argument is the device. If no other argument is passed, the default mode is used.
|
|
|
+ # If other 4 arguments are passed, the manual mode is used (the arguments are the sizes of the partitions)
|
|
|
+ # Otherwise, the script exits
|
|
|
if [ $# -eq 1 ]; then
|
|
|
MODE=default
|
|
|
elif [ $# -eq 5 ] && [ $FORCE -ne 1 ]; then
|
|
@@ -23,26 +28,26 @@ parse_arguments()
|
|
|
fi
|
|
|
DEVICE="$1"
|
|
|
check_device
|
|
|
- DEVICE_SIZE=$(blockdev --getsize64 "${DEVICE}")
|
|
|
- RAM_SIZE=$(kibibytes_to_bytes $(grep MemTotal: /proc/meminfo | awk '{print $2}'))
|
|
|
+ DEVICE_SIZE=$(blockdev --getsz "${DEVICE}")
|
|
|
+ RAM_SIZE=$(to_sectors $(grep MemTotal: /proc/meminfo | awk '{print $2}')K)
|
|
|
$MODE $@
|
|
|
}
|
|
|
|
|
|
default()
|
|
|
{
|
|
|
- MIN_SIZE=$(( $(gibibytes_to_bytes 100) + $RAM_SIZE + 2 ))
|
|
|
- BEST_SIZE=$(( $(gibibytes_to_bytes 200) + 2 * $RAM_SIZE ))
|
|
|
+ MIN_SIZE=$(( $(to_sectors 100G) + $RAM_SIZE + $(to_sectors 2G) ))
|
|
|
+ BEST_SIZE=$(( $(to_sectors 200G) + 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".
|
|
|
+ fatal ${MINSIZE_E} "to use default mode, the disk must have at least $(sectors_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".
|
|
|
+ fatal ${BESTSIZE_E} "to use default mode, it is reccomended that the disk have at least $(sectors_to_gibibytes ${BEST_SIZE})GB. If you know what you are doing, you can force default mode with -f".
|
|
|
fi
|
|
|
VM_SIZE=$(to_sectors 100G)
|
|
|
- SWAP_SIZE=$(to_sectors $(( $RAM_SIZE + $(gibibytes_to_bytes 1) )) )
|
|
|
+ SWAP_SIZE=$(( $RAM_SIZE + $(to_sectors 1G) ))
|
|
|
FREE_SIZE=$(( ( $DEVICE_SIZE - $VM_SIZE - $SWAP_SIZE ) / 10 ))
|
|
|
- CONDOR_SIZE=$(to_sectors $(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 4 )) )
|
|
|
- TEMP_SIZE=$(to_sectors $(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 6 )) )
|
|
|
+ CONDOR_SIZE=$(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 4 ))
|
|
|
+ TEMP_SIZE=$(( ( $DEVICE_SIZE - $FREE_SIZE ) / 10 * 6 ))
|
|
|
}
|
|
|
|
|
|
manual()
|
|
@@ -51,8 +56,8 @@ manual()
|
|
|
CONDOR_SIZE=$(to_sectors $3)
|
|
|
SWAP_SIZE=$(to_sectors $4)
|
|
|
VM_SIZE=$(to_sectors $5)
|
|
|
- if [ $(( $TEMP_SIZE + $CONDOR_SIZE + $SWAP_SIZE + $VM_SIZE )) -gt $(to_sectors $DEVICE_SIZE) ]; then
|
|
|
- fatal ${MANUALSIZE_E} "can't use this sizes: ${DEVICE} has only $(bytes_to_gibibytes ${DEVICE_SIZE})G"
|
|
|
+ if [ $(( $TEMP_SIZE + $CONDOR_SIZE + $SWAP_SIZE + $VM_SIZE )) -gt $DEVICE_SIZE ]; then
|
|
|
+ fatal ${MANUALSIZE_E} "can't use this sizes: ${DEVICE} has only $(sectors_to_gibibytes ${DEVICE_SIZE})G"
|
|
|
fi
|
|
|
}
|
|
|
|