Skip to content

Commit

Permalink
Merge branch 'release-0.12.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodesn committed Mar 9, 2019
2 parents 6aa044b + d2aa755 commit 408ac35
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion auter
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 28 additions & 8 deletions auter.aptModule
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand All @@ -48,28 +51,33 @@ 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
logit "ERROR: DOWNLOADOPTION set to 'yes' but the '--downloadonly' option is not available in the current version of ${PACKAGE_MANAGER}"
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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
}
8 changes: 7 additions & 1 deletion auter.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -101,9 +101,15 @@ exit 0
%endif

%changelog
* Tue Mar 05 2019 Nick Rhodes <[email protected]> 0.12.3-1
- #214 Log a machine readable status to the last-{prep,apply} output files

* Tue Feb 12 2019 Nick Rhodes <[email protected]> 0.12.2-1
- #207 check for process matching PID file content

+* Thu Jan 31 2019 Fedora Release Engineering <[email protected]> - 0.12.1-2
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Tue Dec 11 2018 Nick Rhodes <[email protected]> 0.12.1-1
- Add max-delay option to override MAXDLAY via command line
- Redirect stderr to stdout and capture in APPLYOUTPUT variable
Expand Down
30 changes: 23 additions & 7 deletions auter.yumdnfModule
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -79,21 +79,26 @@ 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
logit "ERROR: DOWNLOADOPTION set to 'yes' but the '--downloadonly' option is not available in the current version of ${PACKAGE_MANAGER}"
quit 3
else
logit "WARNING: downloadonly option is not available"
PREPOUTPUT+="\\nSTATUS:FAILED:Download only not available"
fi
fi
else
Expand Down Expand Up @@ -140,31 +145,38 @@ 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

for SCRIPT in "${PREAPPLYSCRIPTDIR}"/*; do
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)

Expand All @@ -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
}

0 comments on commit 408ac35

Please sign in to comment.