virecover revision 111210
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 111210 2003-02-21 09:37:20Z dougb $ 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 19103019Sgordoncase ${OSTYPE} in 2098184SgordonFreeBSD) 2198184Sgordon start_cmd="virecover_start" 2298184Sgordon ;; 2398184SgordonNetBSD) 2498184Sgordon command="/usr/libexec/${name}" 2598184Sgordon ;; 2698184Sgordonesac 2798184Sgordon 2878344Sobrienvirecover_start() 2978344Sobrien{ 30111210Sdougb [ -d /var/tmp/vi.recover ] || return 3198184Sgordon find /var/tmp/vi.recover ! -type f -a ! -type d -delete 3298184Sgordon vibackup=`echo /var/tmp/vi.recover/vi.*` 3398184Sgordon if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 3498184Sgordon echo -n 'Recovering vi editor sessions:' 3598184Sgordon for i in /var/tmp/vi.recover/vi.*; do 3698184Sgordon # Only test files that are readable. 3798184Sgordon if [ ! -r "${i}" ]; then 3898184Sgordon continue 3998184Sgordon fi 4098184Sgordon 4198184Sgordon # Unmodified nvi editor backup files either have the 4298184Sgordon # execute bit set or are zero length. Delete them. 4398184Sgordon if [ -x "${i}" -o ! -s "${i}" ]; then 4498184Sgordon rm -f "${i}" 4598184Sgordon fi 4678344Sobrien done 4798184Sgordon 4898184Sgordon # It is possible to get incomplete recovery files, if the editor 4998184Sgordon # crashes at the right time. 5098184Sgordon virecovery=`echo /var/tmp/vi.recover/recover.*` 5198184Sgordon if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 5298184Sgordon for i in /var/tmp/vi.recover/recover.*; do 5398184Sgordon # Only test files that are readable. 5498184Sgordon if [ ! -r "${i}" ]; then 5598184Sgordon continue 5698184Sgordon fi 5798184Sgordon 5898184Sgordon # Delete any recovery files that are zero length, 5998184Sgordon # corrupted, or that have no corresponding backup file. 6098184Sgordon # Else send mail to the user. 6198184Sgordon recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 6298184Sgordon if [ -n "${recfile}" -a -s "${recfile}" ]; then 6398184Sgordon sendmail -t < "${i}" 6498184Sgordon else 6598184Sgordon rm -f "${i}" 6698184Sgordon fi 6798184Sgordon done 6898184Sgordon fi 6998184Sgordon echo '.' 7078344Sobrien fi 7178344Sobrien} 7278344Sobrien 7378344Sobrienload_rc_config $name 7478344Sobrienrun_rc_command "$1" 75