diff options
Diffstat (limited to 'bin/dnfu')
-rwxr-xr-x | bin/dnfu | 71 |
1 files changed, 49 insertions, 22 deletions
@@ -10,10 +10,29 @@ # So we'll leave it this way in case of conversion of this script to yum or extension # to be capable of both. (tl;dr no combined options because yum sucks at POSIX standards) +# LOGGING UNIT +# We are not ignoring logging frameworks like many software out there. We'll be using logger(1) to +# log what we are doing, and it's up to you to redirect it to a specific file if you need to. +# Define the name of the logging unit/tag here: +LOGUNIT="dnfu" + +# DETAILED LOG +# To not spam the logging centre with all of our debug, we will create a temporary file nonetheless. +# The script will log its destination in the end, so we can make use of mktemp(1) here. +DLOG="$(mktemp -p /tmp dnfu.XXXXXX)"||exit 1 +chmod a+r "$DLOG"||exit 1 + + + +LOGGER="$(which logger 2>/dev/null||/usr/bin/logger)" +LCMD="$LOGGER -plocal0.info -it $LOGUNIT" +LWCMD="$LOGGER -plocal0.warning -it $LOGUNIT" +LECMD="$LOGGER -plocal0.err -it $LOGUNIT" ROK="\033[666D[ \033[32mOK\033[0m ]\033[u\033[K" RWRN="\033[666D[\033[33mWARN\033[0m]\033[u\033[K" RERR="\033[666D[\033[31mFAIL\033[0m]\033[u\033[K" RINF="\033[666D[\033[37mINFO\033[0m]\033[u\033[K" +echo>"$DLOG" UPDAVAIL=1 SCMD="$(command -v snap 2>/dev/null)" @@ -71,62 +90,69 @@ function rinf { esac } function supgrade { - printf "Listing updates...:\n" - sudo "${UCMD}" -C -q check-upgrade - case "$?" in - 0|100) ;; - *) RETVAL=1;return 1;; - esac + #printf "Listing updates...:\n" + #sudo "${UCMD}" -C check-upgrade 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>"$DLOG" + #case "${PIPESTATUS[0]}" in + # 0) $LCMD "No updates found.";; + # 100) $LCMD "Updates found.";; + # *) $LECMD "check-upgrade went wrong!";RETVAL=1;return 1;; + #esac rbeg "Upgrading system packages" - sudo "${UCMD}" -q -y upgrade - case "$?" in - 0) rok;; + sudo "${UCMD}" -y upgrade 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>"$DLOG" + case "${PIPESTATUS[0]}" in + 0) $LCMD "Upgrade OK.";rok;; 1) + $LWCMD "Error on upgrade, but handled by dnf." rwrn "error occurred but was handled by dnf" case "RETVAL" in 0) RETVAL=255;; esac ;; 255) + $LWCMD "Upgrade finished, pending updates remaining." rwrn "Upgrade done but updates remaining" case "$RETVAL" in 0) RETVAL=255;; esac ;; *) + $LECMD "Upgrade failed." rerr RETVAL=1;return 1 ;; esac printf "Checking for outdated running services or necessity to reboot...:\n" - sudo "${UCMD}" needs-restarting + sudo "${UCMD}" needs-restarting -C --color true 2>&1|tee -a "$DLOG" + sudo "$UCMD" needs-restarting -r >/dev/null 2>&1 ||$LWCMD "Reboot required."||: } function snrefresh { rbeg "Refreshing snapd snaps" - sudo "${SCMD}" refresh >/dev/null 2>&1 - case "$?" in - 0) rok;; - *) rerr;RETVAL=1;return 1;; + sudo "${SCMD}" refresh 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>$DLOG + case "${PIPESTATUS[0]}" in + 0) $LCMD "Snaps refreshed.";rok;; + *) $LECMD "Error on refreshing snaps.";rerr;RETVAL=1;return 1;; esac } rbeg "Updating dnf cache" -sudo "${UCMD}" -q makecache -case "$?" in - 0) rok;; - 100) rwrn;; - *) rerr;exit 1;; +sudo "${UCMD}" makecache 2>&1|sed "s/^/$(date --rfc-3339=seconds) /" >> "$DLOG" +case "${PIPESTATUS[0]}" in + 0) $LCMD "DNF cache update OK.";rok;; + 100) $LWCMD "RC 100 on makecache.";rwrn;; + *) $LECMD "DNF cache update failed!";rerr;exit 1;; esac rbeg "Checking for upgrades" -sudo "${UCMD}" -C -q check-upgrade -case "$?" in +sudo "${UCMD}" -C check-upgrade 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>"$DLOG" +case "${PIPESTATUS[0]}" in 0) - rinf "No updates" + $LCMD "No updates found.";rinf "No updates" ;; 100) + $LCMD "Updates found." rok "Updates found" UPDAVAIL=0 ;; + *) $LECMD "check-upgrade went wrong!";rerr;exit 1;; esac if [ "$UPDAVAIL" -eq 0 ];then @@ -136,3 +162,4 @@ fi if [ ! -z "$SCMD" ];then snrefresh fi +$LCMD "Detailed logfile is located at $DLOG." |