izmijenjen newalises-gecos
[postfix-cn.git] / make-aliases-gecos.sh
1 #!/bin/sh
2
3 set -e
4
5 # ovo se moze otkomentirati, ako se ne zele poruke o duplim GECOS aliasima
6 #PA_OPTIONS="-r"
7
8 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
9
10 [ -x /usr/sbin/postalias ] || exit 0
11 [ -f /etc/postfix/main.cf ] || exit 0
12 gecos="/var/lib/postfix-cn/aliases_gecos"
13 grep -q "hash:$gecos" /etc/postfix/main.cf || exit 0
14
15 [ -d /var/lib/postfix-cn/ ] || exit 0
16
17 # Load CARNet Tools
18 . /usr/share/carnet-tools/functions.sh
19
20 getent passwd | awk -F: '
21         $3 >= 100 && $1 != "nobody" && $5 \
22         {
23                 split($5, g, ",");
24                 if (g[1]=="") {next};
25                 gsub(/ /, ".", g[1]);
26                 print tolower(g[1]) ": " $1;
27         }' > $gecos.dpkg-tmp.$$
28
29
30 if ! cmp -s $gecos.dpkg-tmp.$$ $gecos > /dev/null; then
31   cp_mv $gecos.dpkg-tmp.$$ $gecos
32   postalias $PA_OPTIONS hash:$gecos
33 else
34   rm -f $gecos.dpkg-tmp.$$
35 fi