]> Pileus Git - ~andy/fetchmail/blob - contrib/fetchmaildistrib
Credit John Beck's fixes.
[~andy/fetchmail] / contrib / fetchmaildistrib
1 #/bin/bash
2 #
3 # fetchmaildistrib --- Distribute central fetchmail knowledge.
4 #
5 # The central fetchmail database, /etc/fetchmail, contains all accounts that
6 # are to be fetched by the root's daemon. Often, a user desires quicker
7 # access (e.g., when testing some email path). In such cases, the destination
8 # user (marked as is USER here in the poll lines) should set up a ~/.fetchmailrc
9 # for himself. This scripts generates such lines from the central file.
10 #
11 # By Rick van Rein.
12
13 # From stdin, select poll lines for user $1
14 function selectuser () {
15         grep ^poll | grep "is $1 here"
16 }
17
18
19 for i in `cut -d: -f1 </etc/passwd`
20 do      homedir=`grep ^$i: /etc/passwd | cut -d: -f6`
21         fetchfile=`selectuser $i </etc/fetchmailrc`
22         if [ -z "$fetchfile" ]
23         then    rm -f $homedir/.fetchmailrc
24         else    cp /dev/null $homedir/.fetchmailrc
25                 chmod go-rwx $homedir/.fetchmailrc
26                 grep ^defaults /etc/fetchmailrc >>$homedir/.fetchmailrc
27                 selectuser $i </etc/fetchmailrc >>$homedir/.fetchmailrc
28         fi
29 done