os-upgrade.sh: changes on script output.

This commit is contained in:
Christoph 2021-02-03 16:59:48 +01:00
parent 30239c495b
commit d24558027b

View File

@ -56,54 +56,71 @@ echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n " $*\\c" 1>&2
echo -e -n "[ \033[5m\033[1m...\033[m ]\033[13G$*\\c" 1>&2
else
echo -e -n " $*" 1>&2
echo -e -n "[ \033[5m\033[1m...\033[m ]\033[13G$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
#echo_print_command() {
# if $terminal ; then
# echo X\\c > /tmp/shprompt$$
# if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
# echo -e -n "\033[60G - \033[1m$*\\c\033[m" 1>&2
# else
# echo -e -n "\033[60G - \033[1m$*\033[m" 1>&2
# fi
# rm /tmp/shprompt$$
# fi
#}
echo_print_command() {
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "\033[60G - \033[1m$*\\c\033[m" 1>&2
echo -e -n "\n\033[13G\033[1m$*\\c\033[m" 1>&2
else
echo -e -n "\033[60G - \033[1m$*\033[m" 1>&2
echo -e -n "\n\033[13G\033[1m$*\033[m" 1>&2
fi
rm /tmp/shprompt$$
fi
}
echo_done() {
if $terminal ; then
echo -e "\033[85G[ \033[32mdone\033[m ]"
echo -e "\033[1G[ \033[1;32mdone\033[m ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[85G[ \033[32mok\033[m ]"
echo -e "\033[1G[ \033[1;32mok\033[m ]"
fi
}
echo_ignore() {
if $terminal ; then
echo -e "\033[85G[ \033[33mignore\033[m ]"
echo -e "\033[1G[ \033[1;33mignore\033[m ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[85G[ \033[33m\033[1mwarn\033[m ]"
echo -e "\033[1G[ \033[1;33m\033[1mwarn\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[85G[ \033[1;31mfailed\033[m ]"
echo -e "\033[1G[ \033[1;31mfail\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[85G[ \033[37mskipped\033[m ]"
echo -e "\033[1G[ \033[1;37mskip\033[m ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[1G[ \033[5m\033[1m...\033[m ]"
fi
}
fatal (){
blank_line
@ -122,7 +139,9 @@ error(){
if $terminal ; then
echo -e " [ \033[31m\033[1mFehler\033[m ]: $*"
else
echo "Error: $*"
echo ""
echo "[ Error ]: $*"
echo ""
fi
blank_line
}
@ -190,29 +209,48 @@ fi
if $terminal ; then
echo ""
echo -e "\033[32m\033[1mUpgrade Packages with a 'smart' conflict resolution system\033[m"
echo ""
echo -e "\033[13G\033[33mUpgrade Packages with a 'smart' conflict resolution system\033[m"
echo ""
fi
blank_line
echononl "Resynchronize the package index files"
echo_print_command "apt-get update"
if $terminal; then
echo -e "\033[2A"
fi
apt-get -y update > $log_file 2>&1
if [[ $? -gt 0 ]]; then
echo_failed
if ! $terminal ; then
error "Command \"apt-get update\" failed!"
fi
fatal "$(cat $log_file)"
else
echo_done
fi
if $terminal ; then
echo -e "\033[2B"
fi
# - get list of upgradable packages
#
packages_updated="$(apt-get -V -s dist-upgrade | grep -E "^ .*=>.*" | awk '{print$1}')"
#blank_line
#echononl "Upgrade Packages"
#echo_print_command "apt full-upgrade"
#if $terminal; then
# echo -e "\033[2A"
#fi
#if [[ -n "$packages_updated" ]]; then
# apt full-upgrade -y > $log_file 2>&1
# if [[ $? -gt 0 ]]; then
# echo_failed
# if ! $terminal ; then
# error "Command \"apt full-upgrade\" failed!"
# fi
# fatal "$(cat $log_file)"
# else
# echo_done
@ -226,13 +264,24 @@ packages_updated="$(apt-get -V -s dist-upgrade | grep -E "^ .*=>.*" | awk '{pr
#else
# echo_skipped
#fi
#if $terminal ; then
# echo -e "\033[2B"
#fi
blank_line
echononl "Upgrade Packages"
echo_print_command "apt-get dist-upgrade"
if $terminal; then
echo -e "\033[2A"
fi
if [[ -n "$packages_updated" ]]; then
apt-get dist-upgrade -y > $log_file 2>&1
if [[ $? -gt 0 ]]; then
echo_failed
if ! $terminal ; then
error "Command \"apt-get dist-upgrade\" failed!"
fi
fatal "$(cat $log_file)"
else
echo_done
@ -240,7 +289,11 @@ if [[ -n "$packages_updated" ]]; then
echo " This packages have been updated:"
echo "[ $(date +%Y-%d-%m" "%H:%M) ] This packages have been updated:" >> "$updated_packages_log"
for _package in $packages_updated ; do
echo -e " \033[1m$_package\033[m"
if $terminal ; then
echo -e " \033[1m$_package\033[m"
else
echo -e " $_package\033[m"
fi
echo " $_package" >> "$updated_packages_log"
done
echo ""
@ -251,26 +304,49 @@ if [[ -n "$packages_updated" ]]; then
else
echo_skipped
fi
if $terminal ; then
echo -e "\033[2B"
fi
blank_line
echononl "Remove unused Packages"
echo_print_command "apt-get autoremove"
apt-get autoremove -y > $log_file 2>&1
if $terminal; then
echo -e "\033[2A"
fi
if [[ $? -gt 0 ]]; then
echo_failed
if ! $terminal ; then
error "Command \"apt-get autoremove\" failed!"
fi
fatal "$(cat $log_file)"
else
echo_done
fi
if $terminal ; then
echo -e "\033[2B"
fi
blank_line
echononl "Clear out the local repository of retrieved package files"
echo_print_command "apt-get clean"
apt-get clean -y > $log_file 2>&1
if $terminal; then
echo -e "\033[2A"
fi
if [[ $? -gt 0 ]]; then
echo_failed
if ! $terminal ; then
error "Command \"apt-get clean\" failed!"
fi
fatal "$(cat $log_file)"
else
echo_done
fi
if $terminal ; then
echo -e "\033[2B"
fi
# - Get list of packages with onlx config files present
# -
@ -278,13 +354,17 @@ rc_packages="$(dpkg --list | awk '/^rc/ { print $2 }')"
blank_line
if $terminal; then
echo -e " Remove (purge) packages with only config files installed ((rc):"
echo -en " \033[1mapt-get purge \$(dpkg --list | awk '/^rc/ { print $2 }')\033[m"
echo -e "\033[13GRemove (purge) packages with only config files installed (rc):"
echo -en "\033[13G\033[1mapt-get purge \$(dpkg --list | awk '/^rc/ { print $2 }')\033[m"
echo -e "\033[2A"
fi
if [[ -n "$rc_packages" ]] ; then
apt-get purge -y $(dpkg --list | awk '/^rc/ { print $2 }') > $log_file 2>&1
if [[ $? -gt 0 ]]; then
echo_failed
if ! $terminal ; then
error "Command \"apt-get purge -y \$(dpkg --list | awk '/^rc/ { print \$2 }')\" failed!"
fi
fatal "$(cat $log_file)"
else
echo_done
@ -305,6 +385,10 @@ else
echo_skipped
fi
if $terminal ; then
echo -e "\033[2B"
fi
if [[ -f "/var/run/reboot-required" ]]; then