1 #!/bin/sh
2 #
3 # mlmmj-make-ml.sh - henne@hennevogel.de
4 #
5 # modified for Debian GNU/Linux by boll@debian.org
7 VERSION="0.1-debian (Modified for Debian GNU/Linux)"
8 DEFAULTDIR="/var/spool/mlmmj"
9 ETCDEFAULTDIR="/etc/mlmmj/lists"
10 TEXTPATH="/usr/share/mlmmj/text.skel"
11 SENDMAILPKG=`grep-dctrl -FProvides mail-transport-agent -a -FStatus installed -sPackage -n /var/lib/dpkg/status`
12 NEWALIASES=`which newaliases`
14 USAGE="
15 mlmmj-make-ml $VERSION
16 $0 [OPTIONS]
17 -h display this help text
18 -L the name of the mailinglist
19 -s your spool directory if not $DEFAULTDIR
20 -z nuffn for now
21 "
23 echo
24 echo "+------------------------------------------------------------+"
25 echo "| Information: |"
26 echo "| Please report bugs against mlmmj-make-ml to the Debian BTS |"
27 echo "| at http://bugs.debian.org/ |"
28 echo "+------------------------------------------------------------+"
29 echo
32 while getopts ":hL:s:az:" Option
33 do
34 case "$Option" in
35 h )
36 echo "$USAGE"
37 exit 0
38 ;;
39 z )
40 echo -n "nothing"
41 exit 0
42 ;;
43 L )
44 LISTNAME="$OPTARG"
45 ;;
46 s )
47 SPOOLDIR="$OPTARG"
48 ;;
49 * )
50 printf "$0: invalid option\nTry $0 -h for more information.\n"
51 exit 1
52 ;;
53 esac
54 done
55 SHIFTVAL=$(( $OPTIND - 1 ))
56 shift $SHIFTVAL
58 if [ -z "$SPOOLDIR" ]; then
59 SPOOLDIR="$DEFAULTDIR"
60 fi
62 echo "Creating Directorys below $SPOOLDIR. Use '-s spooldir' to change"
64 if [ -z "$LISTNAME" ]; then
65 echo -n "What should the name of the Mailinglist be? [mlmmj-test] : "
66 read LISTNAME
67 if [ -z "$LISTNAME" ]; then
68 LISTNAME="mlmmj-test"
69 fi
70 fi
72 LISTDIR="$SPOOLDIR/$LISTNAME"
73 ETCLISTDIR="$ETCDEFAULTDIR/$LISTNAME"
75 mkdir -p $LISTDIR
76 mkdir -p $ETCLISTDIR
78 for DIR in incoming queue queue/discarded archive subconf unsubconf \
79 bounce moderation subscribers.d digesters.d requeue \
80 nomailsubs.d
81 do
82 mkdir "$LISTDIR"/"$DIR"
83 done
85 for DIR in text control
86 do
87 mkdir "$ETCLISTDIR"/"$DIR"
88 ln -s "$ETCLISTDIR"/"$DIR" "$LISTDIR"/"$DIR"
89 done
91 test -f "$LISTDIR"/index || touch "$LISTDIR"/index
93 echo -n "The Domain for the List? [] : "
94 read FQDN
95 if [ -z "$FQDN" ]; then
96 FQDN="localhost.localdomain"
97 fi
99 echo -n "The emailaddress of the list owner? [postmaster] : "
100 read OWNER
101 if [ -z "$OWNER" ]; then
102 OWNER="postmaster"
103 fi
104 echo "$OWNER" > "$ETCLISTDIR"/"control/owner"
106 if [ -z "$TEXTPATH" -o ! -d "$TEXTPATH" ]; then
107 echo "**NOTE** Could not copy the texts for the list"
108 echo "Please manually copy the files from $TEXTPATH"
109 else
110 cp "$TEXTPATH"/* "$ETCLISTDIR"/"text"
111 fi
113 LISTADDRESS="$LISTNAME@$FQDN"
114 echo "$LISTADDRESS" > "$ETCLISTDIR"/control/"listaddress"
116 MLMMJRECIEVE=`which mlmmj-recieve 2>/dev/null`
117 if [ -z "$MLMMJRECIEVE" ]; then
118 MLMMJRECIEVE="/usr/bin/mlmmj-recieve"
119 fi
121 MLMMJMAINTD=`which mlmmj-maintd 2>/dev/null`
122 if [ -z "$MLMMJMAINTD" ]; then
123 MLMMJMAINTD="/usr/bin/mlmmj-maintd"
124 fi
126 ALIAS="$LISTNAME: \"|$MLMMJRECIEVE -L $SPOOLDIR/$LISTNAME/\""
128 echo "I am adding the following to your /etc/aliases file:"
129 echo "$ALIAS"
130 echo -n "is this ok (if not, you need to do so yourself)? [y/N] : "
131 read OKIDOKI
132 case $OKIDOKI in
133 y|Y)
134 echo "$ALIAS" >> /etc/aliases
135 ;;
136 n|N)
137 exit 0
138 ;;
139 *)
140 echo "Options were: y, Y, n or N"
141 esac
143 echo "Detecting the installed MTA and changing ownership as needed..."
145 if [ "$SENDMAILPKG" = "postfix" ]; then
146 USER="nobody"
147 GROUP="nogroup"
148 echo "Postfix appears to be handling your mail, using ownership $USER:$GROUP..."
149 elif [ "$SENDMAILPKG" = "exim4-daemon-light" ]; then
150 USER="Debian-exim"
151 GROUP="Debian-exim"
152 echo "Exim appears to be handling your mail, using ownership $USER:$GROUP..."
153 else
154 USER="nobody"
155 GROUP="nogroup"
156 echo "Unable to detect MTA, using default ownership: $USER:$GROUP..."
157 fi
159 chown -R $USER:$GROUP $LISTDIR $LISTDIR/*
160 chmod -R 755 $LISTDIR
161 chmod -R 755 $ETCLISTDIR
163 # Check if all lists are owned by the right user, if not, ask if we should fix
164 # it.
166 ANOMALIES=0
168 for ENTRY in `ls $SPOOLDIR`
169 do
170 SOWNER=`stat -c %U $SPOOLDIR/$ENTRY`
171 SGROUP=`stat -c %G $SPOOLDIR/$ENTRY`
173 if [ $SOWNER != $USER -o $SGROUP != $GROUP ]
174 then
175 ANOMALIES=1
176 fi
177 done
179 if [ $ANOMALIES -eq 1 ]
180 then
181 echo -n "It appears that not all lists have proper ownership, do you want me to fix this? [y/N] : "
182 read FIXOWNERSHIP
183 case $FIXOWNERSHIP in
184 y|Y)
185 chown -R $USER:$GROUP $SPOOLDIR/*
187 ;;
188 n|N)
189 echo "Not fixing ownership"
190 ;;
191 *)
192 echo "Options were: y, Y, n or N"
193 esac
196 fi
198 echo "Running $NEWALIASES"
199 $NEWALIASES
201 echo "Done."