diff --git a/auter b/auter index 1b44b60..9f59371 100755 --- a/auter +++ b/auter @@ -19,7 +19,7 @@ # -declare -r -x AUTERVERSION="0.12.2" +declare -r -x AUTERVERSION="0.12.3" declare -r -x SCRIPTDIR="/etc/auter" declare -r -x DATADIR="/var/lib/auter" declare -r -x LOCKFILE="${DATADIR}/enabled" diff --git a/auter.aptModule b/auter.aptModule index 1346c8e..c0d7120 100644 --- a/auter.aptModule +++ b/auter.aptModule @@ -23,12 +23,15 @@ function prepare_updates() { run_script "${SCRIPT}" "Pre-Prep" done + PREPOUTPUT="$(date '+%F %T')\\n" if [[ "${PREDOWNLOADUPDATES}" == "yes" ]]; then if [[ $(man "${PACKAGE_MANAGER}" | grep -c download-only) -gt 0 ]]; then ${PACKAGE_MANAGER} update &>/dev/null # Check if there are any errors when checking for updates local ERROR_COUNT local AVAILABLE_PACKAGE_COUNT + + ERROR_COUNT=$("${PACKAGE_MANAGER}" -u upgrade --assume-no "${PACKAGEMANAGEROPTIONS[@]}" | grep -c '^[WE]:') AVAILABLE_PACKAGE_COUNT=$("${PACKAGE_MANAGER}" -u upgrade --assume-no "${PACKAGEMANAGEROPTIONS[@]}" | awk '/upgraded,.*newly installed,/ {sum=$1+$3} END {print sum}') @@ -48,14 +51,18 @@ function prepare_updates() { PREPOUTPUT=$("${PACKAGE_MANAGER}" "${PACKAGEMANAGEROPTIONS[@]}" "${DOWNLOADOPTION[@]}" --download-only dist-upgrade -y 2>&1) if [[ $(echo "${PREPOUTPUT}" | grep -c '^[WE]:') -gt 0 ]]; then logit "ERROR: There were errors returned by \`${PACKAGE_MANAGER} ${PACKAGEMANAGEROPTIONS[*]} ${DOWNLOADOPTION[*]} --download-only dist-upgrade -y\`. Exiting." + PREPOUTPUT+="\\nSTATUS:FAILED:Errors returned by package manager" else logit "INFO: Updates downloaded${DOWNLOADLOGMSG}" + PREPOUTPUT+="\\nSTATUS:SUCCESS:Package download complete" fi else [[ "${AVAILABLE_PACKAGE_COUNT}" -eq 0 ]] logit "INFO: No updates are available to be downloaded." + PREPOUTPUT+="STATUS:SUCCESS:No updates available" fi else logit "ERROR: There were errors returned by \`${PACKAGE_MANAGER} -u upgrade --assume-no ${PACKAGEMANAGEROPTIONS[*]}\`. Exiting." + PREPOUTPUT+="\\nSTATUS:FAILED:Errors returned by package manager" fi else if [[ "${ONLYINSTALLFROMPREP}" == "yes" ]]; then @@ -63,13 +70,14 @@ function prepare_updates() { quit 3 else logit "WARNING: downloadonly option is not available" + PREPOUTPUT+="\\nSTATUS:Download only not available" fi fi else - PREPOUTPUT=$("${PACKAGE_MANAGER}" "${PACKAGEMANAGEROPTIONS[@]}" -s dist-upgrade 2>&1) + PREPOUTPUT+=$("${PACKAGE_MANAGER}" "${PACKAGEMANAGEROPTIONS[@]}" -s dist-upgrade 2>&1) fi rotate_file "${DATADIR}/last-prep-output-${CONFIGSET}" - [[ "${PREPOUTPUT}" ]] && echo "${PREPOUTPUT}" > "${DATADIR}/last-prep-output-${CONFIGSET}" + [[ "${PREPOUTPUT}" ]] && echo -e "${PREPOUTPUT}" > "${DATADIR}/last-prep-output-${CONFIGSET}" # Run any post-prep scripts for SCRIPT in "${POSTPREPSCRIPTDIR}"/*; do @@ -82,6 +90,7 @@ function apply_updates() { # Prevent dialog box as we are not running the update in interactive mode declare -x DEBIAN_FRONTEND=noninteractive + APPLYOUTPUT="$(date '+%F %T')\\n" # Set the list of debs to be installed if [[ "${ONLYINSTALLFROMPREP}" == "yes" ]]; then local AVAILABLE_PACKAGES @@ -111,28 +120,35 @@ function apply_updates() { if [[ "${AVAILABLE_PACKAGE_COUNT}" -gt 0 ]]; then local PACKAGES_BEFORE local PACKAGES_AFTER - for SCRIPT in "${PREAPPLYSCRIPTDIR}"/*; do - run_script "${SCRIPT}" "Pre-Apply" - done + # Sleep before running pre-scripts and updates SLEEP_DELAY=$((RANDOM % MAXDELAY)) [[ ${SLEEP_DELAY} -gt 1 ]] && logit "INFO: Sleeping for ${SLEEP_DELAY} seconds" sleep ${SLEEP_DELAY} + + for SCRIPT in "${PREAPPLYSCRIPTDIR}"/*; do + run_script "${SCRIPT}" "Pre-Apply" + done + logit "INFO: Applying updates" PACKAGES_BEFORE=$(dpkg --list) # We don't want to allow the user to interrupt a yum/dnf/apt transaction or Bad Things Happen. echo "Trying to update" trap '' SIGINT SIGTERM - RUN_OUTPUT=$("${PACKAGE_MANAGER}" "${UPDATEACTION}" "${PACKAGEMANAGEROPTIONS[@]}" -y "${DEBS[@]}" 2>&1) + if APPLYOUTPUT=$("${PACKAGE_MANAGER}" "${UPDATEACTION}" "${PACKAGEMANAGEROPTIONS[@]}" -y "${DEBS[@]}" 2>&1); then + APPLYOUTPUT+="\\nSTATUS:SUCCESS:Package updates applied" + else + APPLYOUTPUT+="\\nSTATUS:FAILED:Package updates failed" + fi rotate_file "${DATADIR}/last-apply-output-${CONFIGSET}" - echo "${RUN_OUTPUT}" &>"${DATADIR}/last-apply-output-${CONFIGSET}" + echo -e "${APPLYOUTPUT}" &>"${DATADIR}/last-apply-output-${CONFIGSET}" default_signal_handling PACKAGES_AFTER=$(dpkg --list) if [[ "${PACKAGES_BEFORE}" == "${PACKAGES_AFTER}" ]]; then - logit "WARNING: No updates were applied. $(echo "${RUN_OUTPUT}" | grep 'upgraded,.*installed,')" + logit "WARNING: No updates were applied. $(echo "${APPLYOUTPUT}" | grep 'upgraded,.*installed,')" quit 3 fi @@ -149,10 +165,14 @@ function apply_updates() { else logit "INFO: No updates are available to be applied." + APPLYOUTPUT+="\\nSTATUS:SUCCESS:No updates available" + echo -e "$APPLYOUTPUT" > "${DATADIR}/last-apply-output-${CONFIGSET}" log_last_run fi else logit "ERROR: Exit status ${RC} returned by \`${PACKAGE_MANAGER} -u upgrade --assume-no ${PACKAGEMANAGEROPTIONS[*]}\`. Exiting." + APPLYOUTPUT+="\\nSTATUS:FAILED:Updates failed with status $RC" + echo -e "$APPLYOUTPUT" > "${DATADIR}/last-apply-output-${CONFIGSET}" quit 3 fi } diff --git a/auter.spec b/auter.spec index 13bb40f..a175df2 100644 --- a/auter.spec +++ b/auter.spec @@ -1,5 +1,5 @@ Name: auter -Version: 0.12.2 +Version: 0.12.3 Release: 1%{?dist} Summary: Prepare and apply updates License: ASL 2.0 @@ -101,9 +101,15 @@ exit 0 %endif %changelog +* Tue Mar 05 2019 Nick Rhodes 0.12.3-1 +- #214 Log a machine readable status to the last-{prep,apply} output files + * Tue Feb 12 2019 Nick Rhodes 0.12.2-1 - #207 check for process matching PID file content ++* Thu Jan 31 2019 Fedora Release Engineering - 0.12.1-2 ++- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + * Tue Dec 11 2018 Nick Rhodes 0.12.1-1 - Add max-delay option to override MAXDLAY via command line - Redirect stderr to stdout and capture in APPLYOUTPUT variable diff --git a/auter.yumdnfModule b/auter.yumdnfModule index 1119014..e2109ef 100644 --- a/auter.yumdnfModule +++ b/auter.yumdnfModule @@ -52,7 +52,7 @@ function prepare_updates() { # Remove the old RPMS from the auter cache [[ "${ONLYINSTALLFROMPREP}" == "yes" ]] && rm -f "${DOWNLOADDIR}"/"${CONFIGSET}"/*.rpm - PREPOUTPUT+=$("${PACKAGE_MANAGER}" check-update "${PACKAGEMANAGEROPTIONS[@]}") + PREPOUTPUT+=$("${PACKAGE_MANAGER}" check-update "${PACKAGEMANAGEROPTIONS[@]}" 2>&1) RC=$? # If check-update has an exit code of 100, updates are available. @@ -79,14 +79,18 @@ function prepare_updates() { find /var/cache/dnf -name "*.rpm" -exec mv {} "${DOWNLOADDIR}/${CONFIGSET}" \; fi logit "INFO: Updates downloaded${DOWNLOADLOGMSG}" + PREPOUTPUT+="\\nSTATUS:SUCCESS:Package download complete" else logit "ERROR: Updates could not be pre-downloaded${DOWNLOADLOGMSG}. See the ${DATADIR}/last-prep-output-${CONFIGSET} file for details." + PREPOUTPUT+="\\nSTATUS:FAILED:Package download failed" fi elif [[ "${RC}" -eq 1 ]]; then logit "ERROR: Exit status ${RC} returned by \`${PACKAGE_MANAGER} ${PACKAGEMANAGEROPTIONS[*]} ${DOWNLOADOPTION[*]} update --downloadonly -y\`. Exiting." + PREPOUTPUT+="\\nSTATUS:FAILED:Yum failed with status $RC" else logit "INFO: No updates are available to be downloaded." + PREPOUTPUT+="\\nSTATUS:SUCCESS:No updates available" fi else if [[ "${ONLYINSTALLFROMPREP}" == "yes" ]]; then @@ -94,6 +98,7 @@ function prepare_updates() { quit 3 else logit "WARNING: downloadonly option is not available" + PREPOUTPUT+="\\nSTATUS:FAILED:Download only not available" fi fi else @@ -140,12 +145,18 @@ function apply_updates() { # installed (i.e. dependencies of other packages). Instead we need to use install. UPDATEACTION="install" else - RC=$("${PACKAGE_MANAGER}" check-update "${PACKAGEMANAGEROPTIONS[@]}" &>/dev/null; echo $?) + APPLYOUTPUT+=$("${PACKAGE_MANAGER}" check-update "${PACKAGEMANAGEROPTIONS[@]}" 2>&1) + RC=$? UPDATEACTION="update" fi # If check-update has an exit code of 100, updates are available. if [[ "${RC}" -eq 100 ]]; then + # Sleep before continuing with pre-scripts and updates + SLEEP_DELAY=$((RANDOM % MAXDELAY)) + [[ ${SLEEP_DELAY} -gt 1 ]] && logit "INFO: Sleeping for ${SLEEP_DELAY} seconds" + sleep ${SLEEP_DELAY} + # Check for yum.lock file check_package_manager_lock @@ -153,18 +164,19 @@ function apply_updates() { run_script "${SCRIPT}" "Pre-Apply" done - SLEEP_DELAY=$((RANDOM % MAXDELAY)) - [[ ${SLEEP_DELAY} -gt 1 ]] && logit "INFO: Sleeping for ${SLEEP_DELAY} seconds" - sleep ${SLEEP_DELAY} logit "INFO: Applying updates" HISTORY_BEFORE=$(${PACKAGE_MANAGER} history list) # We don't want to allow the user to interrupt a yum/dnf transaction or Bad Things Happen. trap '' SIGINT SIGTERM rotate_file "${DATADIR}/last-apply-output-${CONFIGSET}" - APPLYOUTPUT+=$("${PACKAGE_MANAGER}" "${UPDATEACTION}" -y "${PACKAGEMANAGEROPTIONS[@]}" "${RPMS[@]}" 2>&1) + if APPLYOUTPUT+=$("${PACKAGE_MANAGER}" "${UPDATEACTION}" -y "${PACKAGEMANAGEROPTIONS[@]}" "${RPMS[@]}" 2>&1); then + APPLYOUTPUT+="\\nSTATUS:SUCCESS:Package updates applied" + else + APPLYOUTPUT+="\\nSTATUS:FAILED:Package updates failed" + fi default_signal_handling - echo -e "$APPLYOUTPUT" &>"${DATADIR}/last-apply-output-${CONFIGSET}" + echo -e "$APPLYOUTPUT" > "${DATADIR}/last-apply-output-${CONFIGSET}" HISTORY_AFTER=$(${PACKAGE_MANAGER} history list) @@ -191,9 +203,13 @@ function apply_updates() { elif [[ "${RC}" -eq 0 ]]; then logit "INFO: No updates are available to be applied." + APPLYOUTPUT+="\\nSTATUS:SUCCESS:No updates available" + echo -e "$APPLYOUTPUT" > "${DATADIR}/last-apply-output-${CONFIGSET}" log_last_run else logit "ERROR: Exit status ${RC} returned by \`${PACKAGE_MANAGER} check-update ${PACKAGEMANAGEROPTIONS[*]}\`. Exiting." + APPLYOUTPUT+="\\nSTATUS:FAILED:Yum failed with status $RC" + echo -e "$APPLYOUTPUT" > "${DATADIR}/last-apply-output-${CONFIGSET}" quit 3 fi }