From 554d9739455c289b9f54a413b543ccaecffdc0d7 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Mon, 3 Jan 2022 16:18:05 -0300 Subject: [PATCH] Refactor --- install.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index 68ca95d..33e1c13 100755 --- a/install.sh +++ b/install.sh @@ -23,10 +23,6 @@ updateSystemClock() { timedatectl set-ntp true } -logStep() { - echo ${1} > CocoASAIS.log -} - logAndExit() { str="${1} Therefore, the installation process will stop, but you can continue where you left off by running:\n\nsh CocoASAIS" newlines=$(printf "$str" | grep -c $'\n') @@ -36,7 +32,7 @@ logAndExit() { printf "%d", (x == int(x)) ? x : int(x) + 1 }') whiptail --msgbox "$str" $((5+height)) 60 - logStep "${2}" + echo ${1} > CocoASAIS.log exit 1 } @@ -85,18 +81,14 @@ partDisks() { else whiptail --yesno "Do you want to create a swapfile?" 0 0 if [ $? -eq 0 ]; then - sizeStr=$(whiptail --inputbox "Enter the size of the swapfile (in GB)." 0 0 3>&1 1>&2 2>&3) - exitIfCancel "You must enter a size." "partDisks" - size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }') + size=$(getSize "swapfile") createSwapfile $size fi fi else whiptail --yesno "Do you want to create a swapfile?" 0 0 if [ $? -eq 0 ]; then - sizeStr=$(whiptail --inputbox "Enter the size of the swapfile (in GB)." 0 0 3>&1 1>&2 2>&3) - exitIfCancel "You must enter a size." "partDisks" - size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }') + size=$(getSize "swapfile") createSwapfile $size fi fi @@ -109,9 +101,7 @@ partDisks() { if [ $? -eq 0 ]; then result=$(whiptail --title "Select the swap space." --menu "" 0 0 0 "Partition" "" "Swapfile" "" 3>&1 1>&2 2>&3) exitIfCancel "You must select a swap space." "partDisks" - sizeStr=$(whiptail --inputbox "Enter the size of the ${result} (in GB)." 0 0 3>&1 1>&2 2>&3) - exitIfCancel "You must enter a size." "partDisks" - size=$(echo $sizeStr | awk -F'[^0-9]+' '{ print $1 }') + size=$(getSize "${result:l}") if [ "$result" = "Partition" ]; then swapPart=${disk}2 rootPart=${disk}3 @@ -127,6 +117,12 @@ partDisks() { mountPart } +getSize() { + sizeStr=$(whiptail --inputbox "Enter the size of the ${1} (in GB)." 0 0 3>&1 1>&2 2>&3) + exitIfCancel "You must enter a size." "partDisks" + echo "$sizeStr" | awk -F'[^0-9]+' '{ print $1 }' +} + createSwapfile() { swapfile=/mnt/swapfile dd if=/dev/zero of=$swapfile bs=1M count=$1 status=progress