From 87b08c6235299a372a1ae4b736042e031c0e4d51 Mon Sep 17 00:00:00 2001 From: mollusk Date: Tue, 18 Dec 2018 22:22:22 -0700 Subject: [PATCH] include swappiness prompt in auto option Former-commit-id: 4b5b2774df4c368d35ecc58d69a948550f717440 Former-commit-id: ff7742940ee611123e976c348d276e21548bd50b --- genswap.sh | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/genswap.sh b/genswap.sh index 2734df3..e7161e1 100755 --- a/genswap.sh +++ b/genswap.sh @@ -48,11 +48,11 @@ function autoSwap(){ sleep 1 - echo -e -n "\n${YELLOW}Do you want to mark ${SWAPPATH}${SWAPNAME} as swap?(Y/n): ${NC}" + echo -e -n "\n${YELLOW}Do you want to mark ${SWAPPATH}${SWAPNAME} as swap now?(Y/n): ${NC}" read markswap if [ "${markswap}" = "n" ] || [ "${markswap}" = "N" ];then - exit 0 + echo "\n${LCYAN}Not making ${SWAPPATH}/${SWAPFILE} as swap...${NC}\n" fi echo -e "\n${LCYAN}Marking ${SWAPPATH}${SWAPNAME} as swap...\n\n${NC}" @@ -65,7 +65,7 @@ function autoSwap(){ read addfstab if [ "${addfstab}" = "n" ];then - exit 0 + echo -e "\n${LCYAN} Not adding ${SWAPPATH}${SWAPNAME} to fstab${NC}\n" fi echo -e "\n${LCYAN}Creating backup of /etc/fstab ...\n${NC}" @@ -76,9 +76,8 @@ function autoSwap(){ CHECKFSTAB=$(cat /etc/fstab | grep "swap" | gawk '/swap/{print $2}') - if [ $CHECKFSTAB != "swap" ];then + if [ "${CHECKFSTAB}" != "swap" ];then echo -e "${LRED}Swap line does not exist in /etc/fstab, please manually check this.${NC}\n" - exit 1 else echo -e "${LGREEN}Swap successfully added to /etc/fstab! Reboot to verify success...${NC}\n" @@ -93,12 +92,12 @@ function autoSwap(){ sudo reboot else - exit 0 + echo -e "\n${LGREEN}Swapfile setup complete, setting swappiness level...${NC}\n" fi fi } -function swappiness(){ +function setSwappinessLvl(){ echo -e -n "\n${YELLOW}Enter a number for swappiness (0-100)[default=10]: ${NC}" @@ -177,6 +176,22 @@ case "${1}" in -a|--auto) autoSwap + + while true;do + echo -e "\n${YELLOW}Do you want to set the swappiness level?(y/n):${NC} " + read swappinessLevel + + if [ "${swappinessLevel}" = "y" ];then + setSwappinessLvl + break && exit 0; + + elif [ "${swappinessLevel}" = "n" ];then + break && exit 0; + + else + echo -e "\n${LRED}Please enter 'y' or 'n'${NC}\n" + fi + done ;; -v|version|--version) @@ -184,7 +199,7 @@ case "${1}" in ;; -s|--swappiness) - swappiness + setSwappinessLvl ;; *)