xref: /freebsd/usr.sbin/periodic/etc/daily/210.backup-aliases (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# If there is a global system configuration file, suck it in.
7#
8if [ -r /etc/defaults/periodic.conf ]
9then
10    . /etc/defaults/periodic.conf
11    source_periodic_confs
12fi
13
14case "$daily_backup_aliases_enable" in
15    [Yy][Ee][Ss])
16	if [ ! -f /etc/mail/aliases ]
17	then
18	    echo '$daily_backup_aliases_enable is enabled but' \
19		"/etc/mail/aliases doesn't exist"
20	    rc=2
21	else
22	    bak=/var/backups
23	    rc=0
24
25	    echo ""
26	    echo "Backing up mail aliases:"
27
28	    if [ ! -f $bak/aliases.bak ]
29	    then
30		echo "no $bak/aliases.bak"
31		cp -p /etc/mail/aliases $bak/aliases.bak || rc=3
32	    fi
33
34	    if ! cmp -s $bak/aliases.bak /etc/mail/aliases
35	    then
36		[ $rc -lt 1 ] && rc=1
37		echo "$host aliases diffs:"
38		diff -u $bak/aliases.bak /etc/mail/aliases
39		mv $bak/aliases.bak $bak/aliases.bak2
40		cp -p /etc/mail/aliases $bak/aliases.bak || rc=3
41	    fi
42	fi;;
43
44    *)  rc=0;;
45esac
46
47exit $rc
48