discord.sh now displays to console as well by default, and a lot of cleanup

This commit is contained in:
2025-05-16 13:12:29 -04:00
parent b45bd31954
commit be02666464
22 changed files with 171 additions and 351 deletions
-33
View File
@@ -1,33 +0,0 @@
#!/usr/bin/env bash
backupDir="$1"
backupType="$2"
# load in defaults from config
scriptRoot="$(dirname "$0")/.."
configFile="$scriptRoot/config.sh"
if [[ -f "$configFile" ]]; then
source "$configFile"
if [[ -z "$backupDir" ]]; then
backupDir="$BACKUP_DIRECTORY"
fi
if [[ -z "$backupType" ]]; then
backupType="$PRUNE_TYPE"
fi
fi
if [[ "$backupType" = "<DIR>" ]]; then
backups=$(find "$backupDir" -maxdepth 1 -type d | grep -v "^$backupDir$" | sort | xargs du -h --summarize)
hashes=""
else
backups=$(find "$backupDir" -type f -name "$backupType" | sort | xargs du -h)
hashes=$(find "$backupDir" -type f -name "$backupType" | sort | xargs md5sum --tag)
fi
echo "$backups"
if [[ -n "$hashes" ]]; then
echo "$hashes"
fi
"$scriptRoot/discord.sh" -c "mint" -t "Backup Status" "$backups" "$hashes"
-67
View File
@@ -1,67 +0,0 @@
#!/usr/bin/env bash
# prune the directory of matching files or subfolders,
# until we only have the desired number of backups remaining.
# assumes backups are named with something like datestamp,
# as we want to keep the bottom of the file list wheb sorted.
# pulls from config, but can take overrides:
# prune-old-backups.sh "where-to-look" "what-to-find" "how-many-to-keep"
LOCATION=`dirname "$0"`
source "${LOCATION}/../config.sh"
# directory to prune
pruneDir="$PRUNE_DIRECTORY"
# what to prune from that directory
pruneType="$PRUNE_TYPE"
# how many to keep
keepCount="$PRUNE_DOWN_TO"
if [ -n "$1" ]; then
pruneDir="$1"
fi
if [ -n "$2" ]; then
pruneType=""$2
fi
if [ -n "$3" ]; then
keepCount="$3"
fi
if (( "${keepCount}" > "0" )); then
removeCount=0
# find direct subfolders to remove
if [ "${pruneType}" = "<DIR>" ]; then
# notice the grep to remove the pruneDir from the results
# head given a negative number will stop that much short from the bottom, so we keep those matches
while read -r dirToRemove; do
if [ -z "${dirToRemove}" ]; then break; fi
removeCount=$((removeCount+1))
echo "Removing: ${dirToRemove}"
rm -r "${dirToRemove}"
done <<< `find "${pruneDir}" -maxdepth 1 -type d | grep -v "^${pruneDir}$" | sort | head -n "-${keepCount}"`
else
# head given a negative number will stop that much short from the bottom, so we keep those matches
while read -r fileToRemove; do
if [ -z "${fileToRemove}" ]; then break; fi
removeCount=$((removeCount+1))
echo "Removing: ${fileToRemove}"
rm "${fileToRemove}"
done <<< `find "${pruneDir}" -type f -name "${pruneType}" | sort | head -n "-${keepCount}"`
fi
if (( $removeCount > 0 )); then
echo "Successfully removed ${removeCount} extra backups."
else
echo 'Nothing to do, we do not have too many backups.'
fi
else
echo 'Nothing to do, you said keep everything.'
fi
+14 -14
View File
@@ -4,11 +4,11 @@ locations="$@"
# load in defaults from config
scriptRoot="$(dirname "$0")/.."
configFile="$scriptRoot/config.sh"
if [[ -f "$configFile" ]]; then
source "$configFile"
configFile="${scriptRoot}/config.sh"
if [[ -f "${configFile}" ]]; then
source "${configFile}"
if [[ -z "$locations" ]]; then
if [[ -z "${locations}" ]]; then
locations=${STORAGE_MONITOR[@]}
fi
fi
@@ -16,22 +16,22 @@ fi
warn=false
messages=()
for index in "${!STORAGE_ALERT[@]}"; do
storage=$("$scriptRoot/storage.sh" "$index" "${STORAGE_ALERT[$index]}")
storage=$("${scriptRoot}/storage.sh" "${index}" "${STORAGE_ALERT[$index]}")
alert="$?"
if [[ "0" != "$alert" ]]; then
if [[ '0' != "${alert}" ]]; then
warn=true
messages+=("$storage is below threshold ${STORAGE_ALERT[$index]}G")
messages+=("${storage} is below threshold ${STORAGE_ALERT[$index]}G")
else
messages+=("$storage is above threshold ${STORAGE_ALERT[$index]}G")
messages+=("${storage} is above threshold ${STORAGE_ALERT[$index]}G")
fi
done
title="Storage Update"
if [[ "$warn" = true ]]; then
purple="purple"
title="Storage Alert"
title='Storage Update'
if [[ "${warn}" = true ]]; then
purple='purple'
title='Storage Alert'
fi
printf "%s\n" "${messages[@]}"
printf "%s\n" "${messages[@]}" | "$scriptRoot/discord.sh" -c "${purple-blue}" -d "Storage Alert" -t "$title"
printf "%s\n" "${messages[@]}" | "${scriptRoot}/discord.sh" -c "${purple-blue}" -d 'Storage Alert' -t "${title}"
+5 -5
View File
@@ -4,14 +4,14 @@ locations="$@"
# load in defaults from config
scriptRoot="$(dirname "$0")/.."
configFile="$scriptRoot/config.sh"
if [[ -f "$configFile" ]]; then
source "$configFile"
configFile="${scriptRoot}/config.sh"
if [[ -f "${configFile}" ]]; then
source "${configFile}"
if [[ -z "$locations" ]]; then
if [[ -z "{$locations}" ]]; then
locations=${STORAGE_MONITOR[@]}
fi
fi
"$scriptRoot/df-custom.sh" $locations | "$scriptRoot/discord.sh" -c "blue" -t "Storage Status"
"${scriptRoot}/df.sh" $locations | "${scriptRoot}/discord.sh" -c 'blue' -t 'Storage Status'
+13 -13
View File
@@ -6,27 +6,27 @@ alertLevel="$1"
# load in defaults from config
scriptRoot="$(dirname "$0")/.."
configFile="$scriptRoot/config.sh"
if [[ -f "$configFile" ]]; then
source "$configFile"
if [[ -f "${configFile}" ]]; then
source "${configFile}"
if [[ -z "$alertLevel" ]]; then
alertLevel="$THERMAL_ALERT"
if [[ -z "${alertLevel}" ]]; then
alertLevel="${THERMAL_ALERT}"
fi
fi
# get current status
thermal=$("$scriptRoot/thermal.sh" "$alertLevel")
thermal=$("$scriptRoot/thermal.sh" "${alertLevel}")
alert="$?"
if [[ "0" -ne "$alert" ]]; then
if [[ '0' -ne "${alert}" ]]; then
# if currently in an alert status
alertLevelF=`echo "scale=1 ; $alertLevel * 9 / 5 + 32" | bc -l`
"$scriptRoot/discord.sh" -c "red" -t "Thermal Alert" "$thermal" $'\n' "above threshold $alertLevel C ($alertLevelF F)"
touch "$HOME/.thermal.alert"
elif [[ -f "$HOME/.thermal.alert" ]]; then
alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l)
"${scriptRoot}/discord.sh" -c red -t 'Thermal Alert' "${thermal}" $'\n' "above threshold ${alertLevel} C (${alertLevelF} F)"
touch "${HOME}/.thermal.alert"
elif [[ -f "${HOME}/.thermal.alert" ]]; then
# if previously in an alert status
alertLevelF=`echo "scale=1 ; $alertLevel * 9 / 5 + 32" | bc -l`
"$scriptRoot/discord.sh" -c "orange" -t "Thermal Alert" "$thermal" $'\n' "previously above threshold $alertLevel C ($alertLevelF F)"
rm "$HOME/.thermal.alert"
alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l)
"${scriptRoot}/discord.sh" -c orange -t 'Thermal Alert' "${thermal}" $'\n' "previously above threshold ${alertLevel} C (${alertLevelF} F)"
rm "${HOME}/.thermal.alert"
fi
+1 -1
View File
@@ -2,5 +2,5 @@
scriptRoot="$(dirname "$0")/.."
"$scriptRoot/thermal.sh" | "$scriptRoot/discord.sh" -c "yellow" -t "Thermal Status"
"${scriptRoot}/thermal.sh" | "${scriptRoot}/discord.sh" -c yellow -t 'Thermal Status'