From 3099a6c9fb339b44e4b2f2fd895e6b98e3760ece Mon Sep 17 00:00:00 2001 From: Cameron Ryder Date: Thu, 8 Jun 2023 11:45:32 -0400 Subject: [PATCH 1/2] feat: add free disk space startup check (#331) --- kiauh.sh | 1 + scripts/utilities.sh | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/kiauh.sh b/kiauh.sh index c0fed70..7863171 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -86,6 +86,7 @@ function kiauh_update_dialog() { } check_euid +check_free_space init_logfile set_globals kiauh_update_dialog diff --git a/scripts/utilities.sh b/scripts/utilities.sh index b3293ff..05d0106 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -26,6 +26,14 @@ function check_euid() { fi } +function check_free_space() { + local gb_req=5 + if [[ $(df -Pk ${HOME} | sed 1d | grep -v used | awk '{ print $4 "\t" }') -lt $((1048576*$gb_req)) ]]; then + echo -e "${red}Free disk space in ${yellow}${HOME}${red} is less than ${gb_req}GB, abort${white}" + exit 1 + fi +} + #================================================# #============= MESSAGE FORMATTING ===============# #================================================# From 08786d64e8e514ccb81578757d8ffe3eb8a207c9 Mon Sep 17 00:00:00 2001 From: Cameron Ryder Date: Wed, 28 Jun 2023 14:37:28 -0400 Subject: [PATCH 2/2] fix: don't block user and check more than home --- scripts/utilities.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 3d0456d..fe68b0a 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -29,11 +29,26 @@ function check_euid() { } function check_free_space() { - local gb_req=5 - if [[ $(df -Pk ${HOME} | sed 1d | grep -v used | awk '{ print $4 "\t" }') -lt $((1048576*$gb_req)) ]]; then - echo -e "${red}Free disk space in ${yellow}${HOME}${red} is less than ${gb_req}GB, abort${white}" - exit 1 - fi + local mount_free mb_rec=2048 + local mount_check_regex='^/($|bin|etc|home|lib|mnt|opt|root|sbin|tmp|usr|var)' # all root dirs possibly relevant to software install + for mount_check in $(cat /etc/mtab | grep '^/dev' | cut -d ' ' -f 2 | grep -E '${mount_check_regex}'); do + mount_free=$(($(df -Pk ${mount_check} | sed 1d | grep -v used | awk '{ print $4 "\t" }')/1024)) + if [[ ${mount_free} -lt ${mb_req} ]]; then + local yn + while true; do + echo -e "${yellow}Heads up! Free disk space in ${white}${mount_check}${yellow} is only ${white}${mount_free} MB${yellow}.${white}" + read -p "${yellow}You may run into errors installing or updating software that uses this mountpoint. Proceed? (y|N): ${white}" yn + case "${yn}" in + Y|y|Yes|yes) + break;; + N|n|No|no|"") + exit 1;; + *) + echo -e "${red}Please answer "y" or "n"${white}";; + esac + done + fi + done } #================================================#