virecover revision 230099
1135669Scognet#!/bin/sh 2135669Scognet# 3135669Scognet# $FreeBSD: head/etc/rc.d/virecover 230099 2012-01-14 02:18:41Z dougb $ 4239362Sandrew# 5135669Scognet 6# PROVIDE: virecover 7# REQUIRE: mountcritremote ldconfig 8# BEFORE: DAEMON 9# 10# XXX: should require `mail'! 11 12. /etc/rc.subr 13 14name="virecover" 15rcvar="virecover_enable" 16stop_cmd=":" 17start_cmd="virecover_start" 18 19virecover_start() 20{ 21 [ -d /var/tmp/vi.recover ] || return 22 find /var/tmp/vi.recover ! -type f -a ! -type d -delete 23 vibackup=`echo /var/tmp/vi.recover/vi.*` 24 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 25 echo -n 'Recovering vi editor sessions:' 26 for i in /var/tmp/vi.recover/vi.*; do 27 # Only test files that are readable. 28 if [ ! -r "${i}" ]; then 29 continue 30 fi 31 32 # Unmodified nvi editor backup files either have the 33 # execute bit set or are zero length. Delete them. 34 if [ -x "${i}" -o ! -s "${i}" ]; then 35 rm -f "${i}" 36 fi 37 done 38 39 # It is possible to get incomplete recovery files, if the editor 40 # crashes at the right time. 41 virecovery=`echo /var/tmp/vi.recover/recover.*` 42 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 43 for i in /var/tmp/vi.recover/recover.*; do 44 # Only test files that are readable. 45 if [ ! -r "${i}" ]; then 46 continue 47 fi 48 49 # Delete any recovery files that are zero length, 50 # corrupted, or that have no corresponding backup file. 51 # Else send mail to the user. 52 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 53 if [ -n "${recfile}" -a -s "${recfile}" ]; then 54 sendmail -t < "${i}" 55 else 56 rm -f "${i}" 57 fi 58 done 59 fi 60 echo '.' 61 fi 62} 63 64load_rc_config $name 65run_rc_command "$1" 66