virecover revision 114726
1226031Sstas#!/bin/sh 2# 3# $NetBSD: virecover,v 1.6 2002/03/22 04:34:00 thorpej Exp $ 4# $FreeBSD: head/etc/rc.d/virecover 114726 2003-05-05 09:53:32Z mtm $ 5# 6 7# PROVIDE: virecover 8# REQUIRE: mountcritremote ldconfig 9# BEFORE: DAEMON 10# KEYWORD: FreeBSD NetBSD 11# 12# XXX: should require `mail'! 13 14. /etc/rc.subr 15 16name="virecover" 17stop_cmd=":" 18 19case ${OSTYPE} in 20FreeBSD) 21 start_cmd="virecover_start" 22 ;; 23NetBSD) 24 command="/usr/libexec/${name}" 25 ;; 26esac 27 28virecover_start() 29{ 30 [ -d /var/tmp/vi.recover ] || return 31 find /var/tmp/vi.recover ! -type f -a ! -type d -delete 32 vibackup=`echo /var/tmp/vi.recover/vi.*` 33 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 34 echo -n 'Recovering vi editor sessions:' 35 for i in /var/tmp/vi.recover/vi.*; do 36 # Only test files that are readable. 37 if [ ! -r "${i}" ]; then 38 continue 39 fi 40 41 # Unmodified nvi editor backup files either have the 42 # execute bit set or are zero length. Delete them. 43 if [ -x "${i}" -o ! -s "${i}" ]; then 44 rm -f "${i}" 45 fi 46 done 47 48 # It is possible to get incomplete recovery files, if the editor 49 # crashes at the right time. 50 virecovery=`echo /var/tmp/vi.recover/recover.*` 51 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 52 for i in /var/tmp/vi.recover/recover.*; do 53 # Only test files that are readable. 54 if [ ! -r "${i}" ]; then 55 continue 56 fi 57 58 # Delete any recovery files that are zero length, 59 # corrupted, or that have no corresponding backup file. 60 # Else send mail to the user. 61 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 62 if [ -n "${recfile}" -a -s "${recfile}" ]; then 63 sendmail -t < "${i}" 64 else 65 rm -f "${i}" 66 fi 67 done 68 fi 69 echo '.' 70 fi 71} 72 73load_rc_config $name 74run_rc_command "$1" 75