genswap.sh: fix prompts and output
This commit is contained in:
parent
981f24ec8e
commit
4a51a06fae
51
genswap.sh
51
genswap.sh
@ -57,28 +57,29 @@ function autoSwap(){
|
|||||||
read markswap
|
read markswap
|
||||||
|
|
||||||
if [ "${markswap}" = "n" ] || [ "${markswap}" = "N" ];then
|
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
|
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}"
|
echo -e -n "\n${YELLOW}Do you want to add swapfile to fstab?(Y/n): ${NC}"
|
||||||
read addfstab
|
read addfstab
|
||||||
|
|
||||||
if [ "${addfstab}" = "n" ];then
|
if [ "${addfstab}" = "n" ] || [[ "${addfstab}" = "N" ]];then
|
||||||
echo -e "\n${LCYAN} Not adding ${SWAPPATH}${SWAPNAME} to fstab${NC}\n"
|
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
|
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}')
|
CHECKFSTAB=$(cat /etc/fstab | grep "swap" | gawk '/swap/{print $1}')
|
||||||
|
|
||||||
if [ "${CHECKFSTAB}" != "/swapfile" ];then
|
if [ "${CHECKFSTAB}" != "/swapfile" ];then
|
||||||
@ -87,18 +88,8 @@ function autoSwap(){
|
|||||||
else
|
else
|
||||||
echo -e "${LGREEN}Swap successfully added to /etc/fstab! Reboot to verify success...${NC}\n"
|
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}"
|
echo -e "\n${LGREEN}Swapfile setup complete, setting swappiness level...${NC}\n"
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +167,7 @@ liveSwappiness(){
|
|||||||
echo -e "${LGREEN}${CURRENTSWAPPINESS}${NC}\n"
|
echo -e "${LGREEN}${CURRENTSWAPPINESS}${NC}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
function help(){
|
function helpFile(){
|
||||||
echo -e "\nUsage: $0 [-a] [--auto] [-s] [--swappiness]\n\n"
|
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 "-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"
|
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
|
esac
|
||||||
|
Loading…
x
Reference in New Issue
Block a user