3 # Configures and builds nmh.
4 # * This script must be invoked from an nmh source directory.
5 # * This script retrieves configuration from the first existing nmh
6 # installation on your $PATH, if any, as well as any $EDITOR/$VISUAL
7 # and $PAGER environment variable settings.
8 # * Unless the -y option is provided, this script then interactively
9 # walks you through confirmation of common configuration settings.
12 # The first time you invoke this script, use the -i option to install
13 # nmh in the specified location. The script will walk you through the
14 # common nmh configuration settings. The -v option will cause display
15 # of brief progress indicators. Be sure to add the bin directory of
16 # the install location to your $PATH, if not already there.
17 # Subsequently, invoke this script with the -y option, to use the
18 # relevant configuration settings from the installed nmh without
24 # -v to display progress
25 # Subsequent uses, assuming installed nmh bin directory is on $PATH:
26 # -y to accept all configuration options without confirmation
28 # -l <logfile name>, default 'build_nmh.log'
29 # Advanced/developer use:
30 # -c to run 'make distcheck' instead of 'make check'
31 # -d to build nmh with debug enabled
32 # -s to use 'make superclean': requires recent autoconf and automake,
33 # see docs/README.developers
36 # On Fedora, at least these rpms must be installed:
39 # cyrus-sasl-devel, if using sasl
40 # openssl-devel, if using TLS
41 # autoconf and automake, with -s (see docs/README.developers for versions)
46 #### OS-specific setup.
52 os=${OSTYPE:-`uname -s`}
53 #### It'd be nice to have configure decide what locking style to use.
54 #### In the meantime, select it manually. To determine what style
55 #### locking your system uses by default, try something like this,
56 #### assuming that strace is installed:
57 #### $ echo test | strace -o /tmp/mail.strace mail -s test $LOGNAME
58 #### Then look in /tmp/mail.strace for fcntl, flock, and lockf system
59 #### calls and opens of dot files in the mail spool.
60 #### These might help but are old:
61 #### https://bugzilla.mozilla.org/show_bug.cgi?id=239013#c9
62 #### http://www.jwz.org/doc/movemail.html
65 freebsd*) locking=flock ;;
66 linux* ) locking=fcntl ;;
71 #### Interpret command arguments.
82 [-c to run 'make distcheck' instead of 'make check']
83 [-d to build nmh with debug enabled]
85 [-l <logfile name>, default '$logfile']
87 [-s to use 'make superclean': requires recent autoconf and automake]
88 [-v to display progress]
89 [-y to accept all configuration options without confirmation]"
91 while getopts 'cdil:rsvy?' arg; do
93 c ) check=distcheck ;;
96 l ) logfile=$OPTARG ;;
101 '?') echo "$usage"; exit 0 ;;
104 shift `expr $OPTIND - 1`
106 #### No command line arguments are supported.
107 if [ $# -gt 0 ]; then
112 #### Check to see that we're in a nmh source directory.
113 if ! grep 'the authors of nmh' COPYRIGHT >/dev/null; then
114 echo "$0: not in nmh source directory"
119 #### Set up configure options. Handle options that can have embedded
120 #### spaces (currently just smtpservers) specially.
123 #### dotlocking, the usual default, requires chgrp and chmod of inc.
125 if [ $install -ge 1 -a `id -u` -ne 0 ]; then
126 if [ "x$locking" = x -o "$locking" = dot ]; then
127 echo "$0: "'install requires chgrp and chmod 2755'
128 echo 'so will sudo to install. Terminate with Ctrl-C if unacceptable.'
134 #### Here are the config options that we will try to detect, then
135 #### confirm, and finally set.
136 config_prefix=/usr/local/nmh
137 config_locking="$locking"
139 config_smtpservers=localhost
146 if mhparam >/dev/null 2>&1; then
147 # Determine config options from installed nmh.
148 mhparam=`which mhparam`
149 mhbin=`dirname "$mhparam"`
151 config_prefix=`cd $mhbin/.. && pwd`
153 mtsconf=`dirname "$mhbin"`/etc/mts.conf
154 if [ -f "$mtsconf" ]; then
155 mts_entry=`grep '^mts:' $mtsconf`
156 if [ "mts_entry" ]; then
157 mts=`echo $mts_entry | sed -e 's/^mts: *//'`
158 if [ "$mts" -a "$mts" != smtp ]; then
163 mtsconfservers=`grep '^servers:' $mtsconf`
164 if [ "$mtsconfservers" ]; then
165 servers=`echo $mtsconfservers | sed -e 's/^servers: *//' -e 's/ /\\\ /g'`
166 [ "$servers" ] && config_smtpservers="$servers"
170 if $ldd $mhbin/inc | grep sasl >/dev/null; then
174 if $ldd $mhbin/inc | grep ssl >/dev/null; then
179 if [ "$EDITOR" ]; then
180 config_editor="$EDITOR"
181 elif [ "$VISUAL" ]; then
182 config_editor="$VISUAL"
185 [ "$PAGER" ] && config_pager="$PAGER"
187 [ $debug -ge 1 ] && config_debug=y
189 if [ $yes -eq 0 ]; then
190 #### Confirm each config setting with user.
191 printf 'Install prefix [%s]: ' $config_prefix
193 [ "$prefix" ] && config_prefix="$prefix"
195 printf 'Locking type (dot|fcntl|flock|lockf) [%s]: ' $config_locking
197 [ "$locking" ] && config_locking="$locking"
199 printf 'MTS (smtp|sendmail) [%s]: ' $config_mts
201 [ "$mts" ] && config_mts="$mts"
203 if [ ! "$mts" -o "$mts" = smtp ]; then
204 printf 'SMTP server(s), space separated [%s]: ' $config_smtpservers
206 servers=`echo $response | sed -e 's/ /\\\ /g'`
207 [ "$servers" ] && config_smtpservers="$servers"
210 printf 'Cyrus SASL support [%s]: ' $config_sasl
212 if [ "$response" = y -o "$response" = Y ]; then
214 elif [ "$response" = n -o "$response" = N ]; then
218 printf 'TLS support [%s]: ' $config_tls
220 if [ "$response" = y -o "$response" = Y ]; then
222 elif [ "$response" = n -o "$response" = N ]; then
226 printf 'Default editor [%s]: ' $config_editor
228 [ "$editor" ] && config_editor=$editor
230 printf 'Pager [%s]: ' $config_pager
232 [ "$pager" ] && config_pager=$pager
234 #### Don't confirm debug here: obey the -d option to this script.
238 config_opts="--prefix=$config_prefix"
240 [ "$config_locking" ] && \
241 config_opts="$config_opts --with-locking=$config_locking"
242 [ "$config_mts" -a "$config_mts" != smtp ] && \
243 config_opts="$config_opts --with-mts=$config_mts"
244 [ "$config_smtpservers" -a "$config_smtpservers" != localhost ] && \
245 smtpservers="--with-smtpservers=$config_smtpservers"
246 [ "$config_sasl" = y ] && \
247 config_opts="$config_opts --with-cyrus-sasl"
248 [ "$config_tls" = y ] && \
249 config_opts="$config_opts --with-tls"
250 [ "$config_editor" ] && \
251 config_opts="$config_opts --with-editor=$config_editor"
252 [ "$config_pager" ] && \
253 config_opts="$config_opts --with-pager=$config_pager"
254 [ $config_debug = y ] && \
255 config_opts="$config_opts --enable-debug"
259 #### Clean up, and set up with autoconfig if necessary.
261 if [ -f Makefile ]; then
262 [ $verbose -ge 1 ] && echo cleaning . . .
263 if [ $superclean -ge 1 ]; then
264 make superclean >/dev/null
266 make distclean >/dev/null
271 if [ -f configure -a -f Makefile.in ]; then
274 [ $verbose -ge 1 ] && echo autoconfiguring . . .
275 ./autogen.sh >>$logfile 2>&1
282 [ $verbose -ge 1 ] && echo configuring . . .
283 echo ./configure $config_opts ${smtpservers:+"$smtpservers"} >>$logfile 2>&1
284 ./configure $config_opts ${smtpservers:+"$smtpservers"} >>$logfile 2>&1
287 if [ $status -eq 0 ]; then
288 [ $verbose -ge 1 ] && echo building . . .
292 if [ $status -eq 0 ]; then
293 [ $verbose -ge 1 ] && echo testing . . .
294 checkoutput=`make $check SETGID_MAIL= 2>>$logfile`
297 tests_summary=`echo "$checkoutput" | grep tests`
298 if [ "$tests_summary" ]; then
299 echo '===================' >>$logfile
300 echo $tests_summary >>$logfile
301 echo '===================' >>$logfile
302 [ "$check" = distcheck ] && \
303 echo "$checkoutput" | tail -n 4 >>$logfile
306 if [ $status -eq 0 ]; then
307 if [ $install -ge 1 ]; then
308 [ $verbose -ge 1 ] && echo installing . . .
309 ($installpriv make install) >/dev/null 2>>$logfile
313 if [ $status -eq 0 -a $build_rpm -ge 1 ]; then
314 [ $verbose -ge 1 ] && echo building rpm . . .
315 make rpm >/dev/null 2>>$logfile
322 grep -E 'Error|warn' $logfile
323 [ $status -ne 0 ] && echo build failed!
324 [ $status -eq 0 -a $verbose -ge 1 ] && echo build completed successfully