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