check_large_files.bash: adds lots of disk size logic, WIP

This commit is contained in:
Jed Reynolds
2020-12-18 16:56:32 -08:00
parent 4193b54e5c
commit e11cb78bd1

View File

@@ -32,14 +32,14 @@ function contains () {
echo "contains wants ARRAY and ITEM arguments: if contains name joe; then... }$" echo "contains wants ARRAY and ITEM arguments: if contains name joe; then... }$"
exit 1 exit 1
fi fi
for item in "${$1[@]}"; do local zarray="${1}[@]"
for item in "${zarray[@]}"; do
echo $item echo $item
[[ "$2" = "$item" ]] && return 0 [[ "$2" = "$item" ]] && return 0
done done
return 1 return 1
} }
# these are default selections # these are default selections
selections=() selections=()
deletion_targets=() deletion_targets=()
@@ -120,6 +120,16 @@ declare -A totals=(
[r]=0 [r]=0
[t]=0 [t]=0
) )
declare -A desc=(
[b]="kernel files"
[c]="core files"
[d]="lf downloads"
[k]="lf/ath10 files"
[l]="/var/log"
[m]="/mnt/lf files"
[r]="lf/report_data"
[t]="/var/tmp"
)
declare -A surveyors_map=( declare -A surveyors_map=(
[b]="survey_kernel_files" [b]="survey_kernel_files"
[c]="survey_core_files" [c]="survey_core_files"
@@ -154,6 +164,7 @@ survey_core_files() {
cd / cd /
mapfile -t core_files < <(ls /core* /home/lanforge/core* 2>/dev/null) mapfile -t core_files < <(ls /core* /home/lanforge/core* 2>/dev/null)
totals[c]=$(du -hc "${core_files[@]}" | awk '/total/{print $1}') totals[c]=$(du -hc "${core_files[@]}" | awk '/total/{print $1}')
[[ x${totals[c]} = x ]] && totals[c]=0
} }
# downloads # downloads
@@ -162,20 +173,31 @@ survey_lf_downloads() {
cd /home/lanforge/Downloads || return 1 cd /home/lanforge/Downloads || return 1
mapfile -t downloads < <(ls *gz *z2 *-Installer.exe *firmware* kinst_* *Docs* 2>/dev/null) mapfile -t downloads < <(ls *gz *z2 *-Installer.exe *firmware* kinst_* *Docs* 2>/dev/null)
totals[d]=$(du -hc "${downloads[@]}" | awk '/total/{print $1}') totals[d]=$(du -hc "${downloads[@]}" | awk '/total/{print $1}')
[[ x${totals[d]} = x ]] && totals[d]=0
} }
# Find ath10k crash residue # Find ath10k crash residue
ath10_files=() ath10_files=()
survey_ath10_files() { survey_ath10_files() {
mapfile -t ath10_files < <(ls /home/lanforge/ath10* 2>/dev/null) mapfile -t ath10_files < <(ls /home/lanforge/ath10* 2>/dev/null)
totals[k]=$(du -sh "${ath10_files}" 2>/dev/null) totals[k]=$(du -hc "${ath10_files}" 2>/dev/null | awk '/total/{print $1}')
[[ x${totals[k]} = x ]] && totals[k]=0
} }
# stuff in var log # stuff in var log
var_log_files=() var_log_files=()
survey_var_log() { survey_var_log() {
mapfile -t var_log_files < <(ls /var/log/* 2>/dev/null) mapfile -t var_log_files < <(find /var/log -type f -size +10M 2>/dev/null)
totals[l]=$(du -sh "${var_log_files}" 2>/dev/null) totals[l]=$(du -hc "${var_log_files}" 2>/dev/null | awk '/total/{print $1}' )
[[ x${totals[l]} = x ]] && totals[l]=0
}
# stuff in var tmp
var_tmp_files=()
survey_var_tmp() {
mapfile -t var_tmp_files < <(find /var/tmp -type f 2>/dev/null)
totals[t]=$(du -sh "${var_tmp_files}" 2>/dev/null | awk '/total/{print $1}' )
[[ x${totals[t]} = x ]] && totals[t]=0
} }
# Find size of /mnt/lf that is not mounted # Find size of /mnt/lf that is not mounted
@@ -183,7 +205,8 @@ mnt_lf_files=()
survey_mnt_lf_files() { survey_mnt_lf_files() {
[ ! -d /mnt/lf ] && return 0 [ ! -d /mnt/lf ] && return 0
mapfile -t mnt_lf_files < <(find /mnt/lf -type f --one_filesystem) mapfile -t mnt_lf_files < <(find /mnt/lf -type f --one_filesystem)
totals[m]=$(du -xhc "${mnt_lf_files[@]}") totals[m]=$(du -xhc "${mnt_lf_files[@]}" 2>/dev/null | awk '/total/{print $1}')
[[ x${totals[m]} = x ]] && totals[m]=0
} }
## Find size of /lib/modules ## Find size of /lib/modules
@@ -202,26 +225,47 @@ survey_report_data() {
} }
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
# gather usage areas
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
survey_areas() {
local area
echo -n "surveying..."
for area in "${!surveyors_map[@]}"; do
echo -n "#"
${surveyors_map[$area]}
done
echo ""
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- # # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
# report sizes here # # report sizes here #
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- # # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
if (( ${#core_files[@]} > 0 )); then disk_usage_report() {
echo "Core Files:" for k in "${!totals[@]}"; do
hr echo -e "\t${desc[$k]}:\t${totals[$k]}"
printf ' %s\n' "${core_files[@]}" done
hr }
fi survey_areas
disk_usage_report
exit
#if (( ${#core_files[@]} > 0 )); then
# echo "Core Files:"
# hr
# printf ' %s\n' "${core_files[@]}"
# hr
#fi
echo "Usage of /mnt: $usage_mnt" #echo "Usage of /mnt: $usage_mnt"
echo "Usage of /lib/modules: $usage_libmod" #echo "Usage of /lib/modules: $usage_libmod"
echo "Boot usage: $boot_usage" #echo "Boot usage: $boot_usage"
if (( ${#boot_kernels[@]} > 1 )); then #if (( ${#boot_kernels[@]} > 1 )); then
echo "Boot ramdisks:" # echo "Boot ramdisks:"
hr # hr
printf ' %s\n' "${boot_kernels[@]}" # printf ' %s\n' "${boot_kernels[@]}"
hr # hr
fi #fi
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- # # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
# delete extra things now # # delete extra things now #
@@ -233,6 +277,12 @@ sleep 1
# ask to remove if we are interactive # # ask to remove if we are interactive #
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- # # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- #
if contains "selections" "a" ; then
for z in "${selections[@]}"; do
echo "will execute $z"
done
exit 0
fi
choice="" choice=""
while [[ $choice != q ]]; do while [[ $choice != q ]]; do