From 0710ca3feb4e9774eb38db057656f7e667f7fe90 Mon Sep 17 00:00:00 2001 From: RJ Trujillo Date: Tue, 25 Jul 2023 10:39:42 -0600 Subject: [PATCH] fix(just): Address issues with memory resizing - Recursive invokations need to be done with --unstable - Add zram-size declaration if it doesn't exist - Only fetch the current size, not the entire file contents --- .../deck/usr/share/ublue-os/just/custom.just | 22 +++++++++++++------ .../usr/share/ublue-os/just/custom.just | 16 ++++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/system_files/deck/usr/share/ublue-os/just/custom.just b/system_files/deck/usr/share/ublue-os/just/custom.just index 5ac44200..69ef4c9c 100644 --- a/system_files/deck/usr/share/ublue-os/just/custom.just +++ b/system_files/deck/usr/share/ublue-os/just/custom.just @@ -81,7 +81,7 @@ deckswap-off: resize-deckswap: #!/usr/bin/env bash CONFIG='/etc/default/deckswap' - CURRENT_SIZE=$(cat "${CONFIG}" | sed 's/SWAP_SIZE=//g') + CURRENT_SIZE=$(cat "${CONFIG}" | grep "SWAP_SIZE" | sed 's/SWAP_SIZE=//g') echo 'Current size: '${CURRENT_SIZE} read -p 'Enter new size (1-16) in gigabytes (1G): ' NEW_SIZE if [ -z "${NEW_SIZE//[0-9]}" ]; then @@ -93,11 +93,11 @@ resize-deckswap: echo 'Current size: '${NEW_SIZE}'G. Please reboot.' else echo 'Error: Input out of range (1-16). Running again.' - just resize-deckswap + just --unstable resize-deckswap fi else echo 'Error: Input is not an integer. Running again.' - just resize-deckswap + just --unstable resize-deckswap fi enable-duperemove: @@ -130,7 +130,11 @@ zram-off: resize-zram: #!/usr/bin/env bash CONFIG='/etc/systemd/zram-generator.conf' - CURRENT_SIZE=$(cat "${CONFIG}" | sed 's/zram-size=//g') + if grep "zram-size" <<< $(cat ${CONFIG}); then + CURRENT_SIZE=$(cat "${CONFIG}" | grep "zram-size" | sed 's/zram-size=//g') + else + CURRENT_SIZE=1024 + fi echo 'Current size: '${CURRENT_SIZE} read -p 'Enter new size (512-4096) in megabytes (1024): ' NEW_SIZE if [ -z "${NEW_SIZE//[0-9]}" ]; then @@ -138,15 +142,19 @@ resize-zram: NEW_SIZE=1024 fi if ((${NEW_SIZE} >= 512 && ${NEW_SIZE} <= 4096)); then - sudo sed -i 's/zram-size='${CURRENT_SIZE}'/zram-size='${NEW_SIZE}'/g' ${CONFIG} + if grep "zram-size" <<< $(cat ${CONFIG}); then + sudo sed -i 's/zram-size='${CURRENT_SIZE}'/zram-size='${NEW_SIZE}'/g' ${CONFIG} + else + sudo -A echo "zram-size=${NEW_SIZE}" >> ${CONFIG} + fi echo 'Current size: '${NEW_SIZE}'. Please reboot.' else echo 'Error: Input out of range (512-4096). Running again.' - just resize-zram + just --unstable resize-zram fi else echo 'Error: Input is not an integer. Running again.' - just resize-zram + just --unstable resize-zram fi hide-grub: diff --git a/system_files/desktop/usr/share/ublue-os/just/custom.just b/system_files/desktop/usr/share/ublue-os/just/custom.just index c0d7ff5a..5d36b8ec 100644 --- a/system_files/desktop/usr/share/ublue-os/just/custom.just +++ b/system_files/desktop/usr/share/ublue-os/just/custom.just @@ -69,7 +69,11 @@ zram-off: resize-zram: #!/usr/bin/env bash CONFIG='/etc/systemd/zram-generator.conf' - CURRENT_SIZE=$(cat "${CONFIG}" | sed 's/zram-size=//g') + if grep "zram-size" <<< $(cat ${CONFIG}); then + CURRENT_SIZE=$(cat "${CONFIG}" | grep "zram-size" | sed 's/zram-size=//g') + else + CURRENT_SIZE=1024 + fi echo 'Current size: '${CURRENT_SIZE} read -p 'Enter new size (512-4096) in megabytes (1024): ' NEW_SIZE if [ -z "${NEW_SIZE//[0-9]}" ]; then @@ -77,15 +81,19 @@ resize-zram: NEW_SIZE=1024 fi if ((${NEW_SIZE} >= 512 && ${NEW_SIZE} <= 4096)); then - sudo sed -i 's/zram-size='${CURRENT_SIZE}'/zram-size='${NEW_SIZE}'/g' ${CONFIG} + if grep "zram-size" <<< $(cat ${CONFIG}); then + sudo sed -i 's/zram-size='${CURRENT_SIZE}'/zram-size='${NEW_SIZE}'/g' ${CONFIG} + else + sudo -A echo "zram-size=${NEW_SIZE}" >> ${CONFIG} + fi echo 'Current size: '${NEW_SIZE}'. Please reboot.' else echo 'Error: Input out of range (512-4096). Running again.' - just resize-zram + just --unstable resize-zram fi else echo 'Error: Input is not an integer. Running again.' - just resize-zram + just --unstable resize-zram fi hide-grub: