Merge from vendor branch OPENSSH:
[dragonfly.git] / contrib / nvi / build / recover.in
1 #!/bin/sh -
2 #
3 #       @(#)recover.in  8.8 (Berkeley) 10/10/96
4 #
5 # Script to recover nvi edit sessions.
6
7 RECDIR="@vi_cv_path_preserve@"
8 SENDMAIL="@vi_cv_path_sendmail@"
9
10 echo 'Recovering nvi editor sessions.'
11
12 # Check editor backup files.
13 vibackup=`echo $RECDIR/vi.*`
14 if [ "$vibackup" != "$RECDIR/vi.*" ]; then
15         for i in $vibackup; do
16                 # Only test files that are readable.
17                 if test ! -r $i; then
18                         continue
19                 fi
20
21                 # Unmodified nvi editor backup files either have the
22                 # execute bit set or are zero length.  Delete them.
23                 if test -x $i -o ! -s $i; then
24                         rm $i
25                 fi
26         done
27 fi
28
29 # It is possible to get incomplete recovery files, if the editor crashes
30 # at the right time.
31 virecovery=`echo $RECDIR/recover.*`
32 if [ "$virecovery" != "$RECDIR/recover.*" ]; then
33         for i in $virecovery; do
34                 # Only test files that are readable.
35                 if test ! -r $i; then
36                         continue
37                 fi
38
39                 # Delete any recovery files that are zero length, corrupted,
40                 # or that have no corresponding backup file.  Else send mail
41                 # to the user.
42                 recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
43                 if test -n "$recfile" -a -s "$recfile"; then
44                         $SENDMAIL -t < $i
45                 else
46                         rm $i
47                 fi
48         done
49 fi