summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-11-01 20:46:03 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-11-01 20:46:03 +0000
commit2043308216d6d3802967d721b839949a281604a1 (patch)
treec80260f04661149f8f69f4a97a83526d621dcd28 /usr.sbin
parentd03f49c6c388456a59205f8ac256f5282ab6d6e4 (diff)
Tap SIGINT while install(1)ing so that we can properly rollback and not
be left in an inconsistent state.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/syspatch/syspatch.sh69
1 files changed, 38 insertions, 31 deletions
diff --git a/usr.sbin/syspatch/syspatch.sh b/usr.sbin/syspatch/syspatch.sh
index cfda172e78f..a78d989ab01 100644
--- a/usr.sbin/syspatch/syspatch.sh
+++ b/usr.sbin/syspatch/syspatch.sh
@@ -1,6 +1,6 @@
#!/bin/ksh
#
-# $OpenBSD: syspatch.sh,v 1.23 2016/11/01 18:12:44 ajacoutot Exp $
+# $OpenBSD: syspatch.sh,v 1.24 2016/11/01 20:46:02 ajacoutot Exp $
#
# Copyright (c) 2016 Antoine Jacoutot <ajacoutot@openbsd.org>
#
@@ -44,6 +44,7 @@ apply_patch()
_files="$(tar xvzphf ${_TMP}/${_patch}.tgz -C ${_explodir})"
create_rollback ${_patch} "${_files}"
+ trap "" 2
for _file in ${_files}; do
if [[ ${_file} == @(bsd|bsd.mp) ]]; then
if ! install_kernel ${_explodir}/${_file}; then
@@ -57,6 +58,7 @@ apply_patch()
fi
fi
done
+ trap - 2
}
apply_patches()
@@ -87,6 +89,7 @@ create_rollback()
_rbfiles="${_rbfiles} ${_file}"
done
+ trap "" 2
if ! (cd / &&
# GENERIC.MP: substitute bsd.mp->bsd and bsd.sp->bsd
if ${_BSDMP} &&
@@ -102,6 +105,7 @@ create_rollback()
rm ${_PDIR}/${_REL}/rollback-${_patch}.tgz
sp_err "Failed to create rollback for ${_patch}"
fi
+ trap - 2
}
fetch_and_verify()
@@ -186,33 +190,6 @@ ls_missing()
done
}
-sp_cleanup()
-{
- local _d _k
-
- # remove non matching release /var/syspatch/ content
- cd ${_PDIR} && set -- *
- for _d; do
- [[ -e ${_d} ]] || continue
- [[ ${_d} == ${_REL} ]] || rm -r ${_d}
- done
-
- # remove non matching release rollback kernel
- set -- /bsd.rollback*
- for _k; do
- [[ -f ${_k} ]] || continue
- [[ ${_k} == /bsd.rollback${_RELINT} ]] || rm ${_k}
- done
-
- # remove rollback kernel if all kernel syspatches have been reverted
- cmp -s /bsd /bsd.rollback${_RELINT} && rm /bsd.rollback${_RELINT}
-
- # non-fatal: the syspatch|rollback tarball should have correct perms
- for _m in 4.4BSD BSD.x11; do
- mtree -qdef /etc/mtree/${_m}.dist -p / -U >/dev/null || true
- done
-}
-
rollback_patch()
{
needs_root
@@ -227,6 +204,7 @@ rollback_patch()
_files="$(tar xvzphf ${_PDIR}/${_REL}/rollback-${_patch}.tgz -C \
${_explodir})"
+ trap "" 2
for _file in ${_files}; do
if [[ ${_file} == @(bsd|bsd.mp) ]]; then
install_kernel ${_explodir}/${_file} ||
@@ -237,9 +215,38 @@ rollback_patch()
fi
done
- sp_cleanup
rm ${_PDIR}/${_REL}/rollback-${_patch}.tgz \
${_PDIR}/${_REL}/${_patch#syspatch-${_RELINT}-}.patch.sig
+ trap - 2
+
+ sp_cleanup
+}
+
+sp_cleanup()
+{
+ local _d _k
+
+ # remove non matching release /var/syspatch/ content
+ cd ${_PDIR} && set -- *
+ for _d; do
+ [[ -e ${_d} ]] || continue
+ [[ ${_d} == ${_REL} ]] || rm -r ${_d}
+ done
+
+ # remove non matching release rollback kernel
+ set -- /bsd.rollback*
+ for _k; do
+ [[ -f ${_k} ]] || continue
+ [[ ${_k} == /bsd.rollback${_RELINT} ]] || rm ${_k}
+ done
+
+ # remove rollback kernel if all kernel syspatches have been reverted
+ cmp -s /bsd /bsd.rollback${_RELINT} && rm /bsd.rollback${_RELINT}
+
+ # non-fatal: the syspatch|rollback tarball should have correct perms
+ for _m in 4.4BSD BSD.x11; do
+ mtree -qdef /etc/mtree/${_m}.dist -p / -U >/dev/null || true
+ done
}
# only run on release (not -current nor -stable)
@@ -250,7 +257,7 @@ set -A _KERNV -- $(sysctl -n kern.version |
# check args
[[ $@ == @(|-[[:alpha:]]) ]] || usage
-# XXX to be discussed
+# XXX to be discussed; check for $ARCH?
[[ -n ${PATCH_PATH} ]]
[[ -d ${PATCH_PATH} ]] && PATCH_PATH="file://$(readlink -f ${PATCH_PATH})"
@@ -264,7 +271,7 @@ _TMP=$(mktemp -d -p /tmp syspatch.XXXXXXXXXX)
readonly _BSDMP _FETCH _PDIR _REL _RELINT _TMP
[[ -n ${_REL} && -n ${_RELINT} ]]
-trap "rm -rf ${_TMP}; exit 1" 2 3 9 13 15 ERR
+trap "rm -rf ${_TMP}; exit 1" 3 9 13 15 ERR
while getopts clr arg; do
case ${arg} in