virecover revision 98184
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 98184 2002-06-13 22:14:37Z gordon $ 578344Sobrien# 678344Sobrien 778344Sobrien# PROVIDE: virecover 878344Sobrien# REQUIRE: mountcritremote 998184Sgordon# BEFORE: DAEMON 1098184Sgordon# KEYWORD: FreeBSD NetBSD 1178344Sobrien# 1278344Sobrien# XXX: should require `mail'! 1378344Sobrien 1478344Sobrien. /etc/rc.subr 1578344Sobrien 1678344Sobrienname="virecover" 1778344Sobrienstop_cmd=":" 1878344Sobrien 1998184Sgordoncase `${CMD_OSTYPE}` in 2098184SgordonFreeBSD) 2198184Sgordon start_cmd="virecover_start" 2298184Sgordon ;; 2398184SgordonNetBSD) 2498184Sgordon command="/usr/libexec/${name}" 2598184Sgordon ;; 2698184Sgordonesac 2798184Sgordon 2878344Sobrienvirecover_start() 2978344Sobrien{ 3098184Sgordon find /var/tmp/vi.recover ! -type f -a ! -type d -delete 3198184Sgordon vibackup=`echo /var/tmp/vi.recover/vi.*` 3298184Sgordon if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 3398184Sgordon echo -n 'Recovering vi editor sessions:' 3498184Sgordon for i in /var/tmp/vi.recover/vi.*; do 3598184Sgordon # Only test files that are readable. 3698184Sgordon if [ ! -r "${i}" ]; then 3798184Sgordon continue 3898184Sgordon fi 3998184Sgordon 4098184Sgordon # Unmodified nvi editor backup files either have the 4198184Sgordon # execute bit set or are zero length. Delete them. 4298184Sgordon if [ -x "${i}" -o ! -s "${i}" ]; then 4398184Sgordon rm -f "${i}" 4498184Sgordon fi 4578344Sobrien done 4698184Sgordon 4798184Sgordon # It is possible to get incomplete recovery files, if the editor 4898184Sgordon # crashes at the right time. 4998184Sgordon virecovery=`echo /var/tmp/vi.recover/recover.*` 5098184Sgordon if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 5198184Sgordon for i in /var/tmp/vi.recover/recover.*; do 5298184Sgordon # Only test files that are readable. 5398184Sgordon if [ ! -r "${i}" ]; then 5498184Sgordon continue 5598184Sgordon fi 5698184Sgordon 5798184Sgordon # Delete any recovery files that are zero length, 5898184Sgordon # corrupted, or that have no corresponding backup file. 5998184Sgordon # Else send mail to the user. 6098184Sgordon recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 6198184Sgordon if [ -n "${recfile}" -a -s "${recfile}" ]; then 6298184Sgordon sendmail -t < "${i}" 6398184Sgordon else 6498184Sgordon rm -f "${i}" 6598184Sgordon fi 6698184Sgordon done 6798184Sgordon fi 6898184Sgordon echo '.' 6978344Sobrien fi 7078344Sobrien} 7178344Sobrien 7278344Sobrienload_rc_config $name 7378344Sobrienrun_rc_command "$1" 74