diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-11-14 15:45:41 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-11-14 15:45:41 +0000 |
commit | 0ceac96529672710f0af0c1ece3d856a5bf162a2 (patch) | |
tree | 59e205327d5c9d9414e37800bd5ac10d7ad98da2 /usr.sbin/syspatch/syspatch.sh | |
parent | 7695099918677672444dead41d65a7e3a6843b29 (diff) |
Check for available space before installing a patch.
Diffstat (limited to 'usr.sbin/syspatch/syspatch.sh')
-rw-r--r-- | usr.sbin/syspatch/syspatch.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/usr.sbin/syspatch/syspatch.sh b/usr.sbin/syspatch/syspatch.sh index 2451b56b953..e18b87c922b 100644 --- a/usr.sbin/syspatch/syspatch.sh +++ b/usr.sbin/syspatch/syspatch.sh @@ -1,6 +1,6 @@ #!/bin/ksh # -# $OpenBSD: syspatch.sh,v 1.48 2016/11/14 09:09:20 ajacoutot Exp $ +# $OpenBSD: syspatch.sh,v 1.49 2016/11/14 15:45:40 ajacoutot Exp $ # # Copyright (c) 2016 Antoine Jacoutot <ajacoutot@openbsd.org> # @@ -78,13 +78,22 @@ apply_patches() checkfs() { - # XXX check for available space - local _d _files="${@}" + local _d _df _dev _files="${@}" _sz [[ -n ${_files} ]] - for _d in $(stat -qf "%Sd" ${_files} | sort -u); do + eval $(cd / && + stat -qf "_dev=\"\${_dev} %Sd\" %Sd=\"\${%Sd:+\${%Sd}\+}%Uz\"" \ + ${_files}) + + for _d in $(printf '%s\n' ${_dev} | sort -u); do + # make sure the fs is local and RW mount | grep -v read-only | grep -q "^/dev/${_d} " || - sp_err "Remote or read-only filesystem, aborting" + sp_err "Remote or read-only filesystem, aborting" + # make sure we have enough space + _df=$(df -Pk | grep "^/dev/${_d} " | tr -s ' ' | cut -d ' ' -f4) + _sz=$(($((${_d}))/1024)) + [[ ${_df} -gt ${_sz} ]] || + sp_err "No space left on device ${_d}, aborting" done } |