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