From 4a51a06fae10cd31563397c7fcb57a89228b8875 Mon Sep 17 00:00:00 2001 From: mollusk Date: Fri, 14 Aug 2020 12:20:06 -0700 Subject: [PATCH] genswap.sh: fix prompts and output --- genswap.sh | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/genswap.sh b/genswap.sh index 10cfc6b..2b3b4ee 100755 --- a/genswap.sh +++ b/genswap.sh @@ -57,28 +57,29 @@ function autoSwap(){ read markswap if [ "${markswap}" = "n" ] || [ "${markswap}" = "N" ];then - echo "\n${LCYAN}Not making ${SWAPPATH}/${SWAPFILE} as swap...${NC}\n" + echo -e "\n${LCYAN}Not making ${SWAPPATH}/${SWAPFILE} as swap...${NC}\n" + else + + echo -e "\n${LCYAN}Marking ${SWAPPATH}${SWAPNAME} as swap...\n\n${NC}" + mkswap ${SWAPPATH}${SWAPNAME} + + echo -e "${LCYAN}Enabling Swap file for use...${NC}\n" + swapon ${SWAPPATH}${SWAPNAME} fi - - echo -e "\n${LCYAN}Marking ${SWAPPATH}${SWAPNAME} as swap...\n\n${NC}" - mkswap ${SWAPPATH}${SWAPNAME} - - echo -e "${LCYAN}Enabling Swap file for use...${NC}\n" - swapon ${SWAPPATH}${SWAPNAME} - echo -e -n "\n${YELLOW}Do you want to add swapfile to fstab?(Y/n): ${NC}" read addfstab - if [ "${addfstab}" = "n" ];then + if [ "${addfstab}" = "n" ] || [[ "${addfstab}" = "N" ]];then echo -e "\n${LCYAN} Not adding ${SWAPPATH}${SWAPNAME} to fstab${NC}\n" + else + + echo -e "\n${LCYAN}Creating backup of /etc/fstab ...\n${NC}" + cp -v /etc/fstab /etc/fstab.bak + + + echo -e "${LCYAN}Adding ${SWAPPATH}${SWAPNAME} to /etc/fstab ..\n${NC}" + echo "${SWAPPATH}${SWAPNAME} none swap sw 0 0" | sudo tee -a /etc/fstab fi - - echo -e "\n${LCYAN}Creating backup of /etc/fstab ...\n${NC}" - cp -v /etc/fstab /etc/fstab.bak - - echo -e "${LCYAN}Adding ${SWAPPATH}${SWAPNAME} to /etc/fstab ..\n${NC}" - echo "${SWAPPATH}${SWAPNAME} none swap sw 0 0" | sudo tee -a /etc/fstab - CHECKFSTAB=$(cat /etc/fstab | grep "swap" | gawk '/swap/{print $1}') if [ "${CHECKFSTAB}" != "/swapfile" ];then @@ -87,18 +88,8 @@ function autoSwap(){ else echo -e "${LGREEN}Swap successfully added to /etc/fstab! Reboot to verify success...${NC}\n" - echo -e "${YELLOW}Do you want to reboot your system now?(n/Y): ${NC}" - read rebootCheck - - if [ "${rebootCheck}" = "y" ] || [ "${rebootCheck}" = "Y" ];then - echo -e "${LRED}Rebooting system in 3 seconds...${NC}\n" - - sleep 3 - - sudo reboot - else - echo -e "\n${LGREEN}Swapfile setup complete, setting swappiness level...${NC}\n" - fi + echo -e "\n${LGREEN}Swapfile setup complete, setting swappiness level...${NC}\n" + fi } @@ -176,7 +167,7 @@ liveSwappiness(){ echo -e "${LGREEN}${CURRENTSWAPPINESS}${NC}\n" } -function help(){ +function helpFile(){ echo -e "\nUsage: $0 [-a] [--auto] [-s] [--swappiness]\n\n" echo -e "-a | --auto Automatically create and size swapfile based on physical memory\n" echo -e "-ss | --set-swappiness Set the swappiness value to minimize swap usage\n\n" @@ -222,6 +213,6 @@ case "${1}" in ;; *) - help + helpFile ;; esac