2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: virecover
|
2003-05-05 09:53:32 +00:00
|
|
|
# REQUIRE: mountcritremote ldconfig
|
2002-06-13 22:14:37 +00:00
|
|
|
# BEFORE: DAEMON
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
# XXX: should require `mail'!
|
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="virecover"
|
2004-03-03 15:21:01 +00:00
|
|
|
rcvar="`set_rcvar`"
|
2001-06-16 07:16:14 +00:00
|
|
|
stop_cmd=":"
|
2004-01-17 10:59:43 +00:00
|
|
|
start_cmd="virecover_start"
|
2002-06-13 22:14:37 +00:00
|
|
|
|
2001-06-16 07:16:14 +00:00
|
|
|
virecover_start()
|
|
|
|
{
|
2003-02-21 09:37:20 +00:00
|
|
|
[ -d /var/tmp/vi.recover ] || return
|
2002-06-13 22:14:37 +00:00
|
|
|
find /var/tmp/vi.recover ! -type f -a ! -type d -delete
|
|
|
|
vibackup=`echo /var/tmp/vi.recover/vi.*`
|
|
|
|
if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
|
|
|
|
echo -n 'Recovering vi editor sessions:'
|
|
|
|
for i in /var/tmp/vi.recover/vi.*; do
|
|
|
|
# Only test files that are readable.
|
|
|
|
if [ ! -r "${i}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Unmodified nvi editor backup files either have the
|
|
|
|
# execute bit set or are zero length. Delete them.
|
|
|
|
if [ -x "${i}" -o ! -s "${i}" ]; then
|
|
|
|
rm -f "${i}"
|
|
|
|
fi
|
2001-06-16 07:16:14 +00:00
|
|
|
done
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
# It is possible to get incomplete recovery files, if the editor
|
|
|
|
# crashes at the right time.
|
|
|
|
virecovery=`echo /var/tmp/vi.recover/recover.*`
|
|
|
|
if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
|
|
|
|
for i in /var/tmp/vi.recover/recover.*; do
|
|
|
|
# Only test files that are readable.
|
|
|
|
if [ ! -r "${i}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete any recovery files that are zero length,
|
|
|
|
# corrupted, or that have no corresponding backup file.
|
|
|
|
# Else send mail to the user.
|
|
|
|
recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
|
|
|
|
if [ -n "${recfile}" -a -s "${recfile}" ]; then
|
|
|
|
sendmail -t < "${i}"
|
|
|
|
else
|
|
|
|
rm -f "${i}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
echo '.'
|
2001-06-16 07:16:14 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|