From 038da756dd3eea69189975b1f6098b5b132417fe Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Tue, 6 Aug 2013 10:27:57 +0200 Subject: [PATCH] Redo the way we do dry runs to output the command that would have been run. Simplify some stuffs while here. Bump version. --- openup | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/openup b/openup index 6c4661e..4d5b039 100755 --- a/openup +++ b/openup @@ -28,7 +28,7 @@ PKG_CERT_REGEX='M:Tier Ltd. OpenBSD Stable Updates' ### end of user defined variables # do not change this!!! -OPENUP_VERSION=0 +OPENUP_VERSION=1 OPENUP_MINREL=53 error() { @@ -52,7 +52,7 @@ check_unsup() { } get_cert() { - local _CERT + local _CERT _CMD if [ -r /etc/ssl/pkgca.pem ]; then openssl x509 -noout -in /etc/ssl/pkgca.pem -issuer 2>/dev/null | \ @@ -61,40 +61,58 @@ get_cert() { echo "===> Downloading certificate" _CERT=$(mktemp -p ${TMPDIR:=/tmp} pkg_cert.XXXXXXXXXX) || exit 1 - ftp -Vo ${_CERT} ${PKG_CERT_URL} - if [ $? -ne 0 ]; then - error "XXX could not download certificate; it's a no-no" - rm -f ${_CERT} - exit 1 + _CMD="ftp -Vo ${_CERT} ${PKG_CERT_URL}" + if [ -z "${DRYRUN}" ]; then + ${_CMD} + if [ $? -ne 0 ]; then + error "XXX could not download certificate; it's a no-no" + rm -f ${_CERT} + exit 1 + fi + else + echo "dry run mode: ${_CMD}" fi echo "===> Installing certificate" - [[ -z ${DRYRUN} ]] && cat ${_CERT} >>/etc/ssl/pkgca.pem - [ $? -eq 0 ] && echo "successfully added certificate to /etc/ssl/pkgca.pem" + _CMD="cat ${_CERT} >>/etc/ssl/pkgca.pem" + if [ -z "${DRYRUN}" ]; then + ${_CMD} + if [ $? -eq 0 ]; then + echo "successfully installed certificate into /etc/ssl/pkgca.pem" + fi + else + echo "dry run mode: ${_CMD}" + fi rm -f ${_CERT} } update_self() { - local _F _N + local _CMD _F _N echo "===> Checking for openup(8) update" _F=$(mktemp -p ${TMPDIR:=/tmp} pkg_cert.XXXXXXXXXX) || exit 1 - ftp -Vo ${_F} ${OPENUP_URL} - if [ $? -ne 0 ]; then - error "XXX could not check for openup update; it's a no-no (non-fatal)" - return 1 + _CMD="ftp -Vo ${_F} ${OPENUP_URL}" + if [ -z "${DRYRUN}" ]; then + ${_CMD} + if [ $? -ne 0 ]; then + error "XXX could not check for openup update; it's a no-no (non-fatal)" + fi + else + echo "dry run mode: ${_CMD}" + echo "dry run mode: will not try to update itself" fi _N=$(grep -Eo '^OPENUP_VERSION=.*' ${_F} | awk -F '=' '{ print $2 }') [[ -n "${_N}" ]] && \ if [ "${OPENUP_VERSION}" -lt "${_N}" ]; then echo "===> Updating openup(8) from version ${OPENUP_VERSION} to version ${_N}" - [[ -z "${DRYRUN}" ]] && cat ${_F} >${MEESA} - [ $? -eq 0 ] && \ + cat ${_F} >${MEESA} + if [ $? -eq 0 ]; then rm -f ${_F} - echo "successfully updated openup(8) to version ${_N}, restarting myself" && \ + echo "successfully updated openup(8) to version ${_N}, restarting myself" ${MEESA} -U $@ exit $? + fi fi rm -f ${_F} }