feat(deck): Enhance and fix zram and deckswap scripts (#512)

* fix(resize-zram/deckswap): Prevent multiple sizes from being defined

Replaces whatever value is there with the new value

* fix(deckswap): Enable/disable instantaneously

No need to reboot

* feat(resize-zram/deckswap): Resize instantaneously without reboots
This commit is contained in:
RJ Trujillo 2023-11-07 12:38:19 -07:00 committed by GitHub
parent d64047146e
commit 01ecbaf524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,8 +276,8 @@ deckswap-on:
#!/usr/bin/env bash
STATUS=$(systemctl status deckswap.service)
if grep -q 'inactive' <<< ${STATUS}; then
systemctl enable deckswap.service
echo 'deckswap enabled. Please reboot.'
systemctl enable --now deckswap.service
echo 'deckswap enabled.'
else
echo 'deckswap is already enabled.'
fi
@ -287,8 +287,8 @@ deckswap-off:
#!/usr/bin/env bash
STATUS=$(systemctl status deckswap.service)
if grep -qv 'inactive' <<< ${STATUS}; then
systemctl disable deckswap.service
echo 'deckswap disabled. Please reboot.'
systemctl disable --now deckswap.service
echo 'deckswap disabled.'
else
echo 'deckswap is already disabled.'
fi
@ -305,12 +305,13 @@ resize-deckswap:
NEW_SIZE=1
fi
if ((${NEW_SIZE} >= 1 && ${NEW_SIZE} <= 16)); then
sudo sed -i 's/SWAP_SIZE='${CURRENT_SIZE}'G/SWAP_SIZE='${NEW_SIZE}'G/g' ${CONFIG}
echo 'Current size: '${NEW_SIZE}'G. Please reboot.'
sudo sed -i 's/SWAP_SIZE=.*/SWAP_SIZE='${NEW_SIZE}'G/g' ${CONFIG}
echo 'Current size: '${NEW_SIZE}'G.'
else
echo 'Error: Input out of range (1-16). Running again.'
ujust resize-deckswap
fi
systemctl restart deckswap.service
else
echo 'Error: Input is not an integer. Running again.'
ujust resize-deckswap
@ -361,11 +362,13 @@ resize-zram:
fi
if ((${NEW_SIZE} >= 512 && ${NEW_SIZE} <= 4096)); then
if grep -q "zram-size" <<< $(cat ${CONFIG}); then
sudo sed -i 's/zram-size='${CURRENT_SIZE}'/zram-size='${NEW_SIZE}'/g' ${CONFIG}
sudo sed -i 's/zram-size=.*/zram-size='${NEW_SIZE}'/g' ${CONFIG}
else
sudo echo "zram-size=${NEW_SIZE}" >> ${CONFIG}
fi
echo 'Current size: '${NEW_SIZE}'. Please reboot.'
systemctl daemon-reload
systemctl start /dev/zram0
zramctl
else
echo 'Error: Input out of range (512-4096). Running again.'
ujust resize-zram