virecover revision 124622
178344Sobrien#!/bin/sh 278344Sobrien# 398184Sgordon# $NetBSD: virecover,v 1.6 2002/03/22 04:34:00 thorpej Exp $ 498184Sgordon# $FreeBSD: head/etc/rc.d/virecover 124622 2004-01-17 10:59:43Z mtm $ 578344Sobrien# 678344Sobrien 778344Sobrien# PROVIDE: virecover 8114726Smtm# REQUIRE: mountcritremote ldconfig 998184Sgordon# BEFORE: DAEMON 10124616Smtm# KEYWORD: FreeBSD 1178344Sobrien# 1278344Sobrien# XXX: should require `mail'! 1378344Sobrien 1478344Sobrien. /etc/rc.subr 1578344Sobrien 1678344Sobrienname="virecover" 1778344Sobrienstop_cmd=":" 18124622Smtmstart_cmd="virecover_start" 1978344Sobrien 2078344Sobrienvirecover_start() 2178344Sobrien{ 22111210Sdougb [ -d /var/tmp/vi.recover ] || return 2398184Sgordon find /var/tmp/vi.recover ! -type f -a ! -type d -delete 2498184Sgordon vibackup=`echo /var/tmp/vi.recover/vi.*` 2598184Sgordon if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 2698184Sgordon echo -n 'Recovering vi editor sessions:' 2798184Sgordon for i in /var/tmp/vi.recover/vi.*; do 2898184Sgordon # Only test files that are readable. 2998184Sgordon if [ ! -r "${i}" ]; then 3098184Sgordon continue 3198184Sgordon fi 3298184Sgordon 3398184Sgordon # Unmodified nvi editor backup files either have the 3498184Sgordon # execute bit set or are zero length. Delete them. 3598184Sgordon if [ -x "${i}" -o ! -s "${i}" ]; then 3698184Sgordon rm -f "${i}" 3798184Sgordon fi 3878344Sobrien done 3998184Sgordon 4098184Sgordon # It is possible to get incomplete recovery files, if the editor 4198184Sgordon # crashes at the right time. 4298184Sgordon virecovery=`echo /var/tmp/vi.recover/recover.*` 4398184Sgordon if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 4498184Sgordon for i in /var/tmp/vi.recover/recover.*; do 4598184Sgordon # Only test files that are readable. 4698184Sgordon if [ ! -r "${i}" ]; then 4798184Sgordon continue 4898184Sgordon fi 4998184Sgordon 5098184Sgordon # Delete any recovery files that are zero length, 5198184Sgordon # corrupted, or that have no corresponding backup file. 5298184Sgordon # Else send mail to the user. 5398184Sgordon recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 5498184Sgordon if [ -n "${recfile}" -a -s "${recfile}" ]; then 5598184Sgordon sendmail -t < "${i}" 5698184Sgordon else 5798184Sgordon rm -f "${i}" 5898184Sgordon fi 5998184Sgordon done 6098184Sgordon fi 6198184Sgordon echo '.' 6278344Sobrien fi 6378344Sobrien} 6478344Sobrien 6578344Sobrienload_rc_config $name 6678344Sobrienrun_rc_command "$1" 67