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