genswap.sh: write swappiness to /etc/sysctl.d and fix fstab check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 14:59:00 -04:00
co-authored by Claude Opus 5.5
parent 54becce5df
commit 58319695dc
+3 -5
View File
@@ -5,7 +5,7 @@ SWAPNAME="swapfile"
TOTALRAM=$(free -m | gawk '/Mem:/{print $2}') TOTALRAM=$(free -m | gawk '/Mem:/{print $2}')
SWAPPINESS="10" SWAPPINESS="10"
SYSCTLCONF="sysctl.conf" SYSCTLCONF="sysctl.conf"
SYSCTLDIR="sysctl.conf.d" SYSCTLDIR="sysctl.d"
VERSION="0.1.0" VERSION="0.1.0"
BUILDDATE="2018-06-05" BUILDDATE="2018-06-05"
@@ -57,7 +57,7 @@ function autoSwap(){
read markswap read markswap
if [ "${markswap}" = "n" ] || [ "${markswap}" = "N" ];then if [ "${markswap}" = "n" ] || [ "${markswap}" = "N" ];then
echo -e "\n${LCYAN}Not making ${SWAPPATH}/${SWAPFILE} as swap...${NC}\n" echo -e "\n${LCYAN}Not making ${SWAPPATH}${SWAPNAME} as swap...${NC}\n"
else else
echo -e "\n${LCYAN}Marking ${SWAPPATH}${SWAPNAME} as swap...\n\n${NC}" echo -e "\n${LCYAN}Marking ${SWAPPATH}${SWAPNAME} as swap...\n\n${NC}"
@@ -80,9 +80,7 @@ function autoSwap(){
echo -e "${LCYAN}Adding ${SWAPPATH}${SWAPNAME} to /etc/fstab ..\n${NC}" echo -e "${LCYAN}Adding ${SWAPPATH}${SWAPNAME} to /etc/fstab ..\n${NC}"
echo "${SWAPPATH}${SWAPNAME} none swap sw 0 0" | sudo tee -a /etc/fstab echo "${SWAPPATH}${SWAPNAME} none swap sw 0 0" | sudo tee -a /etc/fstab
fi fi
CHECKFSTAB=$(cat /etc/fstab | grep "swap" | gawk '/swap/{print $1}') if ! gawk -v f="${SWAPPATH}${SWAPNAME}" '$1 == f && $3 == "swap" {found=1} END {exit !found}' /etc/fstab;then
if [ "${CHECKFSTAB}" != "/swapfile" ];then
echo -e "${LRED}Swap line does not exist in /etc/fstab, please manually check this.${NC}\n" echo -e "${LRED}Swap line does not exist in /etc/fstab, please manually check this.${NC}\n"
else else