summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-11-01 15:51:05 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2016-11-01 15:51:05 +0000
commit62a0fb547115c58233b69553aa4df992c0eb2090 (patch)
tree74f546e72ceab9139d53e458db7e873ee3b537ae
parent89d4649151f19336a35cd9f1c4391275f54ea5cc (diff)
Add a cleanup function to remove non matching release content from
/var/syspatch and the rollback kernel if all kernel syspatches have been reverted. While here, make sure _RELINT and _REL are declared properly.
-rw-r--r--usr.sbin/syspatch/syspatch.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/usr.sbin/syspatch/syspatch.sh b/usr.sbin/syspatch/syspatch.sh
index 9e3b16b5889..8ed5d82298e 100644
--- a/usr.sbin/syspatch/syspatch.sh
+++ b/usr.sbin/syspatch/syspatch.sh
@@ -1,6 +1,6 @@
#!/bin/ksh
#
-# $OpenBSD: syspatch.sh,v 1.19 2016/11/01 14:45:46 ajacoutot Exp $
+# $OpenBSD: syspatch.sh,v 1.20 2016/11/01 15:51:04 ajacoutot Exp $
#
# Copyright (c) 2016 Antoine Jacoutot <ajacoutot@openbsd.org>
#
@@ -62,7 +62,6 @@ apply_patch()
apply_patches()
{
needs_root
- # XXX cleanup old rollback patches and sig (installer should as well)
local _m _patch _patches="$(ls_missing)"
[[ -n ${_patches} ]] || return 0 # nothing to do
@@ -145,7 +144,7 @@ install_kernel()
local _bsd=/bsd _kern=$1
[[ -n ${_kern} ]]
- # we only save the original release kernel once
+ # only save the original release kernel once
[[ -f /bsd.rollback${_RELINT} ]] ||
install -FSp /bsd /bsd.rollback${_RELINT}
@@ -190,6 +189,21 @@ ls_missing()
done
}
+sp_cleanup()
+{
+ local _d
+
+ # remove non matching release /var/syspatch/ content
+ cd ${_PDIR} && set -- *
+ for _d; do
+ [[ -e ${_d} ]] || continue
+ [[ ${_d} == ${_REL} ]] || rm -r ${_d}
+ done
+
+ # remove rollback kernel if all kernel syspatches have been reverted
+ cmp -s /bsd /bsd.rollback${_RELINT} && rm /bsd.rollback${_RELINT}
+}
+
rollback_patch()
{
needs_root
@@ -238,6 +252,7 @@ _REL=${_KERNV[0]}
_RELINT=${_REL%\.*}${_REL#*\.}
_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
@@ -254,4 +269,5 @@ shift $(( OPTIND -1 ))
[[ ${OPTIND} != 1 ]] || apply_patches
+sp_cleanup
rm -rf ${_TMP}