Add and use functions for simpler and more readable logging.

This commit is contained in:
2025-10-09 12:38:56 -07:00
parent 08a7a22dde
commit df8b330893

View File

@@ -803,24 +803,31 @@
echo "*** '$BACKUP' not found! ***"
fi
}
function_log: |
function log {
echo -e "$1"
}
function blog {
echo -e "\n\n$1\n\n"
}
function_debian_upgrade: |
function debian-upgrade {
typeset -l OLD NEW
OLD="$1"
NEW="$2"
echo "*** Upgrading from '$OLD' to '$NEW' ***"
blog "*** Upgrading from '$OLD' to '$NEW' ***"
if [[ -z "$OLD" || -z "$NEW" ]]; then
echo -n "ERROR: Please pass the OLD and NEW version names"
echo ", such as 'debian-upgrade bookworm trixie'. "
return 1
fi
echo "*** Running 'backup' before starting upgrade. ***"
blog "*** Running 'backup' before starting upgrade. ***"
sleep 1
backup
echo "*** Listing the current apt listing for '$OLD' ***"
blog "*** Listing the current apt listing for '$OLD' ***"
sudo grep "$OLD" /etc/apt/sources.list /etc/apt/sources.list.d/*
echo -en "\nAre these the entries you'd like changed to '$NEW'? (y/N) "
@@ -828,12 +835,12 @@
read confirm_change
if [[ -z "$confirm_change" || "$confirm_change" == "N"* ]]; then
echo "*** Aborting upgrade, change rejected. ***"
blog "*** Aborting upgrade, change rejected. ***"
return 1
fi
unset confirm_change
echo "*** Continuing with upgrade. ***"
blog "*** Continuing with upgrade. ***"
sudo sed -i "s/$OLD/$NEW/g" /etc/apt/sources.list
find /etc/apt/sources.list.d/ -name "*.list" \
-exec sudo sed -i "s/$OLD/$NEW/g" {} \;
@@ -848,27 +855,27 @@
read confirm_correct
if [[ -z "$confirm_correct" || "$confirm_correct" == "N"* ]]; then
echo "*** Aborting upgrade, confirmation rejected. ***"
blog "*** Aborting upgrade, confirmation rejected. ***"
return 1
fi
unset confirm_correct
echo "*** Starting the upgrade. ***"
blog "*** Starting the upgrade. ***"
sleep 1
sudo apt update
sudo apt upgrade --without-new-pkgs
echo "*** Upgrades complete, now add new packages. ***"
blog -e "*** Upgrades complete, now add new packages. ***"
sleep 1
sudo apt full-upgrade
echo "*** New packages complete, clean apt files. ***"
blog "*** New packages complete, clean apt files. ***"
sleep 1
sudo apt autoremove --purge
sudo apt clean
echo "*** All done! '$OLD' is now '$NEW'. Please reboot. ***"
blog "*** All done! '$OLD' is now '$NEW'. Please reboot. ***"
sleep 1
unset OLD NEW
}
@@ -952,6 +959,7 @@
{{ alias_ansible_facts }}
{{ function_now }}
{{ function_backup }}
{{ function_log }}
{{ function_debian_upgrade }}
{{ function_ebook_convert }}