virecover revision 267654
126213Swpaul#!/bin/sh 226213Swpaul# 326213Swpaul# $FreeBSD: releng/9.3/etc/rc.d/virecover 231653 2012-02-14 10:16:56Z dougb $ 426213Swpaul# 526213Swpaul 626213Swpaul# PROVIDE: virecover 726213Swpaul# REQUIRE: mountcritremote ldconfig 826213Swpaul# BEFORE: DAEMON 926213Swpaul# 1026213Swpaul# XXX: should require `mail'! 1126213Swpaul 1226213Swpaul. /etc/rc.subr 1326213Swpaul 1426213Swpaulname="virecover" 1526213Swpaulrcvar="virecover_enable" 1626213Swpaulstop_cmd=":" 1726213Swpaulstart_cmd="virecover_start" 1826213Swpaul 1926213Swpaulvirecover_start() 2026213Swpaul{ 2126213Swpaul [ -d /var/tmp/vi.recover ] || return 2226213Swpaul find /var/tmp/vi.recover ! -type f -a ! -type d -delete 2326213Swpaul vibackup=`echo /var/tmp/vi.recover/vi.*` 2426213Swpaul if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 2526213Swpaul echo -n 'Recovering vi editor sessions:' 2626213Swpaul for i in /var/tmp/vi.recover/vi.*; do 2726213Swpaul # Only test files that are readable. 2826213Swpaul if [ ! -r "${i}" ]; then 2926213Swpaul continue 3026213Swpaul fi 3126213Swpaul 3226213Swpaul # Unmodified nvi editor backup files either have the 3326213Swpaul # execute bit set or are zero length. Delete them. 3426213Swpaul if [ -x "${i}" -o ! -s "${i}" ]; then 3584220Sdillon rm -f "${i}" 3684220Sdillon fi 3784220Sdillon done 3826213Swpaul 3926213Swpaul # It is possible to get incomplete recovery files, if the editor 4026213Swpaul # crashes at the right time. 4126213Swpaul virecovery=`echo /var/tmp/vi.recover/recover.*` 4226213Swpaul if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 43146841Sstefanf for i in /var/tmp/vi.recover/recover.*; do 44146841Sstefanf # Only test files that are readable. 45146841Sstefanf if [ ! -r "${i}" ]; then 46146841Sstefanf continue 47146841Sstefanf fi 4892917Sobrien 4992917Sobrien # Delete any recovery files that are zero length, 5092917Sobrien # corrupted, or that have no corresponding backup file. 5192917Sobrien # Else send mail to the user. 5226213Swpaul recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 5326213Swpaul if [ -n "${recfile}" -a -s "${recfile}" ]; then 5426213Swpaul sendmail -t < "${i}" 5526213Swpaul else 5626213Swpaul rm -f "${i}" 5726213Swpaul fi 5826213Swpaul done 59189087Sed fi 6026213Swpaul echo '.' 6126213Swpaul fi 6226213Swpaul} 6326213Swpaul 6426213Swpaulload_rc_config $name 6526213Swpaulrun_rc_command "$1" 6626213Swpaul