1#!/bin/sh - 2# 3# $NetBSD: virecover,v 1.4 2017/11/09 15:03:01 christos Exp $ 4# 5# @(#)recover.in 8.8 (Berkeley) 10/10/96 6# 7# Script to recover nvi edit sessions. 8 9RECDIR="/var/tmp/vi.recover" 10SENDMAIL="/usr/sbin/sendmail" 11 12# Check editor backup files. 13for i in $RECDIR/vi.*; do 14 15 case "$i" in 16 $RECDIR/vi.\*) continue;; 17 esac 18 19 # Only test files that are readable. 20 if [ ! -f "$i" ] || [ ! -r "$i" ]; then 21 continue 22 fi 23 24 # Unmodified nvi editor backup files either have the 25 # execute bit set or are zero length. Delete them. 26 if [ -x "$i" ] || [ ! -s "$i" ]; then 27 rm -f "$i" 28 fi 29done 30 31# It is possible to get incomplete recovery files, if the editor crashes 32# at the right time. 33for i in $RECDIR/recover.*; do 34 35 case "$i" in 36 $RECDIR/recover.\*) continue;; 37 esac 38 39 # Only test plain files that are readable. 40 if [ ! -f "$i" ] || [ ! -r "$i" ]; then 41 continue 42 fi 43 44 # Delete any recovery files that are zero length, corrupted, 45 # or that have no corresponding backup file. Else send mail 46 # to the user. 47 recfile=$(awk '/^X-vi-recover-path:/{print $2}' < "$i") 48 if [ -n "$recfile" ] && [ -s "$recfile" ]; then 49 $SENDMAIL -t < "$i" 50 else 51 rm -f "$i" 52 fi 53done 54