diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-11-22 10:53:38 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-11-22 10:53:38 +0000 |
commit | 4389bab0c47e42cf6444056b310bcdc3c5f67114 (patch) | |
tree | e34ffa2eb395fc77826c668696b7b02ff574d72a /usr.sbin/syspatch/syspatch.sh | |
parent | b3b8cfe170abbef6bf1272fe1fb1de10dcc8e953 (diff) |
Allow passing an explicit return code to sp_err() in case we don't want to exit
right away.
Factorise some common stuff.
Be consistent in variables subtitution.
Diffstat (limited to 'usr.sbin/syspatch/syspatch.sh')
-rw-r--r-- | usr.sbin/syspatch/syspatch.sh | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/usr.sbin/syspatch/syspatch.sh b/usr.sbin/syspatch/syspatch.sh index a85551bb4ac..564ce1298fa 100644 --- a/usr.sbin/syspatch/syspatch.sh +++ b/usr.sbin/syspatch/syspatch.sh @@ -1,6 +1,6 @@ #!/bin/ksh # -# $OpenBSD: syspatch.sh,v 1.58 2016/11/21 16:27:36 ajacoutot Exp $ +# $OpenBSD: syspatch.sh,v 1.59 2016/11/22 10:53:37 ajacoutot Exp $ # # Copyright (c) 2016 Antoine Jacoutot <ajacoutot@openbsd.org> # @@ -20,7 +20,7 @@ set -e sp_err() { - echo "${@}" 1>&2 && return 1 + echo "${1}" 1>&2 && return ${2:-1} } usage() @@ -30,7 +30,7 @@ usage() apply_patch() { - local _explodir _file _files _patch=$1 + local _explodir _file _files _patch=$1 _ret=0 [[ -n ${_patch} ]] _explodir=${_TMP}/${_patch} @@ -42,18 +42,18 @@ apply_patch() create_rollback ${_patch} "${_files}" for _file in ${_files}; do + [[ ${_ret} == 0 ]] || break if [[ ${_file} == @(bsd|bsd.mp) ]]; then - if ! install_kernel ${_explodir}/${_file}; then - rollback_patch - sp_err "Failed to apply ${_patch} (/${_file})" - fi + install_kernel ${_explodir}/${_file} || _ret=$? else - if ! install_file ${_explodir}/${_file} /${_file}; then - rollback_patch - sp_err "Failed to apply ${_patch} (/${_file})" - fi + install_file ${_explodir}/${_file} /${_file} || _ret=$? fi done + + if [[ ${_ret} != 0 ]]; then + sp_err "Failed to apply ${_patch} (/${_file})" 0 + rollback_patch; return ${_ret} + fi } apply_patches() @@ -89,7 +89,7 @@ checkfs() eval $(cd / && stat -qf "_dev=\"\${_dev} %Sd\" %Sd=\"\${%Sd:+\${%Sd}\+}%Uz\"" \ - ${_files}) || true # ignore nonexistent files + ${_files}) || true # ignore nonexistent files for _d in $(printf '%s\n' ${_dev} | sort -u); do mount | grep -v read-only | grep -q "^/dev/${_d} " || @@ -231,13 +231,13 @@ ls_missing() rollback_patch() { - local _explodir _file _files _patch _rbpatch + local _explodir _file _files _patch _rbpatch _ret=0 _patch="$(ls_installed | sort -V | tail -1)" [[ -n ${_patch} ]] _rbpatch=${_patch#syspatch${_RELINT}-}.rollback.tgz - _explodir=${_TMP}/${_rbpatch} + _explodir=${_TMP}/${_rbpatch%.tgz} echo "Reverting ${_patch}" mkdir -p ${_explodir} @@ -246,16 +246,19 @@ rollback_patch() checkfs ${_files} for _file in ${_files}; do + [[ ${_ret} == 0 ]] || break if [[ ${_file} == @(bsd|bsd.mp) ]]; then - install_kernel ${_explodir}/${_file} || - sp_err "Failed to revert ${_patch} (/${_file})" + install_kernel ${_explodir}/${_file} || _ret=$? else - install_file ${_explodir}/${_file} /${_file} || - sp_err "Failed to revert ${_patch} (/${_file})" + install_file ${_explodir}/${_file} /${_file} || _ret=$? fi done - rm ${_PDIR}/${_REL}/{${_rbpatch},${_rbpatch%rollback.tgz}patch.sig} + # `-f' in case we failed to install *.patch.sig + rm -f ${_PDIR}/${_REL}/${_patch#syspatch${_RELINT}-}.patch.sig + + rm ${_PDIR}/${_REL}/${_rbpatch} && [[ ${_ret} == 0 ]] || + sp_err "Failed to revert ${_patch}" ${_ret} sp_cleanup } @@ -267,7 +270,7 @@ sp_cleanup() # remove non matching release /var/syspatch/ content for _d in ${_PDIR}/*; do [[ -e ${_d} ]] || continue - [[ ${_d:##*/} == ${_REL} ]] || rm -r ${_d} + [[ ${_d##*/} == ${_REL} ]] || rm -r ${_d} done # remove non matching release backup kernel @@ -313,7 +316,7 @@ set -A _KERNV -- $(sysctl -n kern.version | # XXX to be discussed; check for $ARCH? [[ -d ${PATCH_PATH} ]] && PATCH_PATH="file://$(readlink -f ${PATCH_PATH})" -[[ ${PATCH_PATH:%%://*} == @(file|ftp|http|https) ]] || +[[ ${PATCH_PATH%%://*} == @(file|ftp|http|https) ]] || sp_err "No valid PATCH_PATH set" [[ $(sysctl -n hw.ncpufound) -gt 1 ]] && _BSDMP=true || _BSDMP=false |