Added a comma after each msgnum exported. The parser was globbing them all together...
[citadel.git] / contrib / easyinstall.sh
1 #!/bin/sh
2 #
3 # Automatic script to install Citadel on a target system.
4 # Copyright (C) 2004 Michael Hampton <error@citadel.org>
5 # Copyright (C) 2004-2015 Art Cancro <ajc@citadel.org>
6 #
7 # This program is open source software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License version 3.
9 #
10 # Our favorite operating system is called Linux.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # Reading this script?  Here's some helpful hints:
18 #
19 # If you're seeing this in your browser, it's probably not what you want.
20 # You can either save it to disk and run it, or do it the easy way:
21 #
22 # curl http://easyinstall.citadel.org/install | sh
23 #
24 # Note that this script installs software on your system and so it requires
25 # root privileges.  Feel free to inspect the script to make sure we didn't
26 # do anything stupid...
27 #
28 # We have provided you the source code according to the terms of the respective
29 # software licenses included in the source code packages, even if you choose
30 # not to keep the source code around.  You can always download it again later.
31 #
32 # We install the "latest" or "stable" versions of these packages:
33 #
34 # Citadel server, WebCit, libcitadel, libical, Berkeley DB, libSieve, Expat
35 #
36 # Do *not* attempt to do anything with the UNATTENDED_BUILD mode.  This is
37 # for our use only and is not only unsupported, but we will deliberately break
38 # it from time to time in order to prevent you from trying to use it.
39
40 ###############################################################################
41 #
42 # This is the general stuff we're going to do, in order:
43 #
44 # 1. Gather information about the target system
45 # 2. Present the installation steps (from 1 above) to the user
46 # 3. Present any pre-install customizations to the user
47 # 4. Do the installation
48 #    A. Download any source code files packages required
49 #    B. If we build our own, compile and install prerequisites then Citadel
50 # 5. Do post-installation setup
51 #
52 # Then call it a day.
53 #
54 ###############################################################################
55
56
57 # Begin user customization area
58 #
59 # These two directories specify where Citadel and its private support
60 # libraries will be installed.  This keeps them safely tucked away from
61 # the rest of your system.  The defaults should be fine for most people.
62
63 SUPPORT=/usr/local/ctdlsupport
64 CITADEL=/usr/local/citadel
65 WEBCIT=/usr/local/webcit
66 WORKDIR=/tmp
67 BUILD=$WORKDIR/citadel-build.$$
68 LOG=$WORKDIR/citadel-install-log.txt
69 export SUPPORT CITADEL WEBCIT
70 unset LANG
71
72 MAKEOPTS=""
73
74 # End user customization area
75
76 # We're now exporting a bunch of environment variables, and here's a list:
77 # CITADEL_INSTALLER     Set to "web" to indicate this script
78 # CITADEL               Directory where Citadel is installed
79 # WEBCIT                Directory where WebCit is installed
80 # SUPPORT               Directory where support programs are installed
81 # DISTRO_MAJOR          Linux distribution name, if applicable
82 # DISTRO_MINOR          Linux distribution name, if applicable
83 # DISTRO_VERSION        Linux distribution version (major digit) if applicable
84 # CC                    C compiler being used
85 # MAKE                  Make program being used
86 # CFLAGS                C compiler flags
87 # LDFLAGS               Linker flags
88 # IS_UPGRADE            Set to "yes" if upgrading an existing Citadel
89 # CTDL_DIALOG           Where (if at all) the "whiptail" or "dialog" program may be found
90
91 # Let Citadel setup recognize the Citadel installer
92 CITADEL_INSTALLER=web
93 export CITADEL_INSTALLER
94
95 SETUP="Citadel Easy Install"
96 DOWNLOAD_SITE=http://easyinstall.citadel.org
97
98 # Original source code packages.
99 DB_SOURCE=db-5.1.29.NC.tar.gz
100 ICAL_SOURCE=libical-easyinstall.tar.gz
101 LIBSIEVE_SOURCE=libsieve-2.2.7-ctdl2.tar.gz
102 EXPAT_SOURCE=expat-2.0.1.tar.gz
103 LIBCURL_SOURCE=curl-7.26.0.tar.gz
104 LIBEV_SOURCE=libev-4.11.tar.gz
105 CARES_SOURCE=c-ares-1.7.5.tar.gz
106 LIBDISCOUNT_SOURCE=discount-2.1.8.tar.gz
107 LIBCITADEL_SOURCE=libcitadel-easyinstall.tar.gz
108 CITADEL_SOURCE=citadel-easyinstall.tar.gz
109 WEBCIT_SOURCE=webcit-easyinstall.tar.gz
110 TEXTCLIENT_SOURCE=textclient-easyinstall.tar.gz
111 INCADD=
112 LDADD=
113
114 case `uname -s` in
115         *BSD)
116                 LDADD="-L/usr/local/lib"
117                 INCADD="-I/usr/local/include"
118         ;;
119 esac
120
121 ##### BEGIN Functions #####
122
123 GetVersionFromFile()
124 {
125         VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
126 }
127
128
129 die () {
130         echo
131         echo $SETUP is aborting.
132         echo
133         echo A log file has been written to $LOG
134         echo Reading this file may tell you what went wrong.  If you
135         echo need to ask for help on the support forum, please post the
136         echo last screenful of text from this log.
137         echo
138         echo Operating system: ${OSSTR}
139         echo Operating system: ${OSSTR} >>$LOG
140         cd $WORKDIR
141         rm -fr $BUILD
142         exit 1
143 }
144
145
146
147 test_build_dir() {
148         tempfilename=test$$.sh
149
150         echo '#!/bin/sh' >$tempfilename
151         echo '' >>$tempfilename
152         echo 'exit 0' >>$tempfilename
153         chmod 700 $tempfilename
154
155         [ -x $tempfilename ] || {
156                 echo Cannot write to `pwd`
157                 echo 'Are you not running this program as root?'
158                 die
159         }
160
161         ./$tempfilename || {
162                 echo Cannot execute a script.
163                 echo 'If /tmp is mounted noexec, please change this before continuing.'
164                 die
165         }
166
167 }
168
169
170
171 download_this () {
172         WGET=`which wget 2>/dev/null`
173         CURL=`which curl 2>/dev/null`
174         if [ -n "${WGET}" -a -x "${WGET}" ]; then
175                 $WGET $DOWNLOAD_SITE/$FILENAME >/dev/null 2>>$LOG || die
176         else
177                 if [ -n "${CURL}" -a -x "${CURL}" ]; then
178                         $CURL $DOWNLOAD_SITE/$FILENAME >$FILENAME 2>>$LOG || die
179                 else
180                         echo Unable to find a wget or curl command.
181                         echo $SETUP cannot continue.
182                         die;
183                 fi
184         fi
185 }
186
187
188
189 install_ical () {
190         cd $BUILD >>$LOG 2>&1 || die
191         FILENAME=libical-easyinstall.sum ; download_this
192         SUM=`cat libical-easyinstall.sum`
193         SUMFILE=$SUPPORT/etc/libical-easyinstall.sum
194         if [ -r $SUMFILE ] ; then
195                 OLDSUM=`cat $SUMFILE`
196                 if [ "$SUM" = "$OLDSUM" ] ; then
197                         echo "* libical does not need updating."
198                         return
199                 fi
200         fi
201         echo "* Downloading libical..."
202         FILENAME=$ICAL_SOURCE ; download_this
203         echo "* Installing libical..."
204         ( gzip -dc $ICAL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
205         cd $BUILD/libical >>$LOG 2>&1 || die
206         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
207         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
208         $MAKE install >>$LOG 2>&1 || die
209         echo "  Complete."
210         echo $SUM >$SUMFILE
211         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
212         rm -f $WEBCIT/webcit-easyinstall.sum 2>/dev/null
213 }
214
215 install_libsieve () {
216         cd $BUILD >>$LOG 2>&1 || die
217         FILENAME=libsieve-easyinstall.sum ; download_this
218         SUM=`cat libsieve-easyinstall.sum`
219         SUMFILE=$SUPPORT/etc/libsieve-easyinstall.sum
220         if [ -r $SUMFILE ] ; then
221                 OLDSUM=`cat $SUMFILE`
222                 if [ "$SUM" = "$OLDSUM" ] ; then
223                         echo "* libsieve does not need updating."
224                         return
225                 fi
226         fi
227         echo "* Downloading libsieve..."
228         FILENAME=$LIBSIEVE_SOURCE ; download_this
229         echo "* Installing libsieve..."
230         ( gzip -dc $LIBSIEVE_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
231         cd $BUILD/libsieve-2.2.7/src >>$LOG 2>&1 || die
232         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
233         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
234         $MAKE install >>$LOG 2>&1 || die
235         echo "  Complete."
236         echo $SUM >$SUMFILE
237         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
238 }
239
240 install_expat () {
241         cd $BUILD >>$LOG 2>&1 || die
242         FILENAME=expat-easyinstall.sum ; download_this
243         SUM=`cat expat-easyinstall.sum`
244         SUMFILE=$SUPPORT/etc/expat-easyinstall.sum
245         if [ -r $SUMFILE ] ; then
246                 OLDSUM=`cat $SUMFILE`
247                 if [ "$SUM" = "$OLDSUM" ] ; then
248                         echo "* expat does not need updating."
249                         return
250                 fi
251         fi
252         echo "* Downloading expat..."
253         FILENAME=$EXPAT_SOURCE ; download_this
254         echo "* Installing Expat..."
255         ( gzip -dc $EXPAT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
256         cd $BUILD/expat-2.0.1 >>$LOG 2>&1 || die
257         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
258         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
259         $MAKE install >>$LOG 2>&1 || die
260         echo "  Complete."
261         echo $SUM >$SUMFILE
262         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
263 }
264
265
266 install_libcurl () {
267         cd $BUILD >>$LOG 2>&1 || die
268         FILENAME=libcurl-easyinstall.sum ; download_this
269         SUM=`cat libcurl-easyinstall.sum`
270         SUMFILE=$SUPPORT/etc/libcurl-easyinstall.sum
271         if [ -r $SUMFILE ] ; then
272                 OLDSUM=`cat $SUMFILE`
273                 if [ "$SUM" = "$OLDSUM" ] ; then
274                         echo "* libcurl does not need updating."
275                         return
276                 fi
277         fi
278         echo "* Downloading libcurl..."
279         FILENAME=$LIBCURL_SOURCE ; download_this
280         echo "* Installing libcurl..."
281         ( gzip -dc $LIBCURL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
282         CFLAGS="${CFLAGS} -I${SUPPORT}/include ${INCADD} -g"
283         CPPFLAGS="${CFLAGS}"
284         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib ${LDADD}"
285         export CFLAGS CPPFLAGS LDFLAGS
286
287         cd $BUILD/curl-7.26.0 >>$LOG 2>&1 || die
288         ./configure --prefix=$SUPPORT --disable-file --disable-ldap --disable-ldaps \
289                 --disable-dict --disable-telnet --disable-tftp --disable-manual \
290                 --enable-thread --disable-sspi --disable-crypto-auth --disable-cookies \
291                 --without-libssh2 --without-ca-path --without-libidn \
292                 --enable-ares=$SUPPORT \
293                 >>$LOG 2>&1 || die
294         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
295         $MAKE install >>$LOG 2>&1 || die
296         echo "  Complete."
297         echo $SUM >$SUMFILE
298         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
299 }
300
301
302 install_libev () {
303         cd $BUILD >>$LOG 2>&1 || die
304         FILENAME=libev-easyinstall.sum ; download_this
305         SUM=`cat libev-easyinstall.sum`
306         SUMFILE=$SUPPORT/etc/libev-easyinstall.sum
307         if [ -r $SUMFILE ] ; then
308                 OLDSUM=`cat $SUMFILE`
309                 if [ "$SUM" = "$OLDSUM" ] ; then
310                         echo "* libev does not need updating."
311                         return
312                 fi
313         fi
314         echo "* Downloading libev..."
315         FILENAME=$LIBEV_SOURCE ; download_this
316         echo "* Installing libev..."
317         ( gzip -dc $LIBEV_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
318         cd $BUILD/libev-4.11 >>$LOG 2>&1 || die
319         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
320         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
321         $MAKE install >>$LOG 2>&1 || die
322         echo "  Complete."
323         echo $SUM >$SUMFILE
324         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
325 }
326
327
328 install_cares () {
329         cd $BUILD >>$LOG 2>&1 || die
330         FILENAME=c-ares-easyinstall.sum ; download_this
331         SUM=`cat c-ares-easyinstall.sum`
332         SUMFILE=$SUPPORT/etc/c-ares-easyinstall.sum
333         if [ -r $SUMFILE ] ; then
334                 OLDSUM=`cat $SUMFILE`
335                 if [ "$SUM" = "$OLDSUM" ] ; then
336                         echo "* c-ares does not need updating."
337                         return
338                 fi
339         fi
340         echo "* Downloading c-ares..."
341         FILENAME=$CARES_SOURCE ; download_this
342         echo "* Installing c-ares..."
343         ( gzip -dc $CARES_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
344         cd $BUILD/c-ares-1.7.5 >>$LOG 2>&1 || die
345         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
346         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
347         $MAKE install >>$LOG 2>&1 || die
348         echo "  Complete."
349         echo $SUM >$SUMFILE
350         rm -f $SUPPORT/etc/libcurl-easyinstall.sum 2>/dev/null
351         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
352 }
353
354 install_discount () {
355         cd $BUILD >>$LOG 2>&1 || die
356         cp /home/willi/Downloads/discount*z .
357         FILENAME=discount-easyinstall.sum ; download_this
358         SUM=`cat discount-easyinstall.sum`
359         SUMFILE=$SUPPORT/etc/discount-easyinstall.sum
360         if [ -r $SUMFILE ] ; then
361                 OLDSUM=`cat $SUMFILE`
362                 if [ "$SUM" = "$OLDSUM" ] ; then
363                         echo "* discount does not need updating."
364                         return
365                 fi
366         fi
367         echo "* Downloading discount..."
368         FILENAME=$LIBDISCOUNT_SOURCE ; download_this
369         echo "* Installing discount..."
370         ( gzip -dc $LIBDISCOUNT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
371         cd $BUILD/discount-2.1.8 >>$LOG 2>&1 || die
372         ./configure.sh --shared    \
373             --prefix=$SUPPORT      \
374             --with-id-anchor       \
375             --with-github-tags     \
376             --with-fenced-code     \
377             --with-dl=both         \
378             ||die
379
380         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
381         $MAKE install >>$LOG 2>&1 || die
382         echo "  Complete."
383         echo $SUM >$SUMFILE
384         rm -f $SUPPORT/etc/discount-easyinstall.sum 2>/dev/null
385         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
386 }
387
388 install_libcitadel () {
389         cd $BUILD >>$LOG 2>&1 || die
390         FILENAME=libcitadel-easyinstall.sum ; download_this
391         SUM=`cat libcitadel-easyinstall.sum`
392         SUMFILE=$SUPPORT/etc/libcitadel-easyinstall.sum
393         if [ -r $SUMFILE ] ; then
394                 OLDSUM=`cat $SUMFILE`
395                 if [ "$SUM" = "$OLDSUM" ] ; then
396                         echo "* libcitadel does not need updating."
397                         return
398                 fi
399         fi
400         echo "* Downloading libcitadel..."
401         FILENAME=$LIBCITADEL_SOURCE ; download_this
402         echo "* Installing libcitadel..."
403         ( gzip -dc $LIBCITADEL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
404         cd $BUILD/libcitadel >>$LOG 2>&1 || die
405         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
406         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
407         $MAKE install >>$LOG 2>&1 || die
408         echo "  Complete."
409         echo $SUM >$SUMFILE
410         # Upgrading libcitadel forces the upgrade of programs which link to it
411         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
412         rm -f $CITADEL/webcit-easyinstall.sum 2>/dev/null
413         rm -f $CITADEL/textclient-easyinstall.sum 2>/dev/null
414 }
415
416 install_db () {
417         cd $BUILD >>$LOG 2>&1 || die
418         FILENAME=db-easyinstall.sum ; download_this
419         SUM=`cat db-easyinstall.sum`
420         SUMFILE=$SUPPORT/etc/db-easyinstall.sum
421         if [ -r $SUMFILE ] ; then
422                 OLDSUM=`cat $SUMFILE`
423                 if [ "$SUM" = "$OLDSUM" ] ; then
424                         echo "* Berkeley DB does not need updating."
425                         return
426                 fi
427         fi
428         echo "* Downloading Berkeley DB..."
429         FILENAME=$DB_SOURCE ; download_this
430         echo "* Installing Berkeley DB..."
431         ( gzip -dc $DB_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
432         cd $BUILD/db-5.1.29.NC/build_unix >>$LOG 2>&1 || die
433         ../dist/configure --prefix=$SUPPORT --disable-compat185 --disable-cxx --disable-debug --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm >>$LOG 2>&1 || die
434         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
435         $MAKE install >>$LOG 2>&1 || die
436         echo "  Complete."
437         echo $SUM >$SUMFILE
438         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
439 }
440
441 install_prerequisites () {
442
443         # Create the support directories if they don't already exist
444
445         mkdir $SUPPORT          2>/dev/null
446         mkdir $SUPPORT/bin      2>/dev/null
447         mkdir $SUPPORT/sbin     2>/dev/null
448         mkdir $SUPPORT/lib      2>/dev/null
449         mkdir $SUPPORT/libexec  2>/dev/null
450         mkdir $SUPPORT/include  2>/dev/null
451         mkdir $SUPPORT/etc      2>/dev/null
452
453         # Now have phun!
454
455         if [ -z "$OK_ICAL" ]
456         then
457                 install_ical
458         fi
459         if [ -z "$OK_LIBSIEVE" ]
460         then
461                 install_libsieve
462         fi
463         if [ -z "$OK_DB" ]
464         then
465                 install_db
466         fi
467         if [ -z "$OK_EXPAT" ]
468         then
469                 install_expat
470         fi
471         if [ -z "$OK_LIBEV" ]
472         then
473                 install_libev
474         fi
475         if [ -z "$OK_CARES" ]
476         then
477                 install_cares
478         fi
479         if [ -z "$OK_DISCOUNT" ]
480         then
481                 install_discount
482         fi
483         if [ -z "$OK_LIBCURL" ]
484         then
485                 install_libcurl
486         fi
487 }
488
489 install_sources () {
490
491         install_libcitadel
492
493         cd $BUILD >>$LOG 2>&1 || die
494         if [ x$IS_UPGRADE = xyes ]
495         then
496                 echo "* Upgrading your existing Citadel installation."
497         fi
498
499         CFLAGS="${CFLAGS} -I${SUPPORT}/include ${INCADD} -g"
500         CPPFLAGS="${CFLAGS}"
501         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib ${LDADD}"
502         export CFLAGS CPPFLAGS LDFLAGS
503
504         DO_INSTALL_CITADEL=yes
505         FILENAME=citadel-easyinstall.sum ; download_this
506         SUM=`cat citadel-easyinstall.sum`
507         SUMFILE=$CITADEL/citadel-easyinstall.sum
508         if [ -r $SUMFILE ] ; then
509                 OLDSUM=`cat $SUMFILE`
510                 if [ "$SUM" = "$OLDSUM" ] ; then
511                         echo "* Citadel does not need updating."
512                         DO_INSTALL_CITADEL=no
513                 fi
514         fi
515
516         if [ $DO_INSTALL_CITADEL = yes ] ; then
517                 echo "* Downloading Citadel..."
518                 FILENAME=$CITADEL_SOURCE ; download_this
519                 echo "* Installing Citadel..."
520                 cd $BUILD >>$LOG 2>&1 || die
521                 ( gzip -dc $CITADEL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
522                 cd $BUILD/citadel >>$LOG 2>&1 || die
523                 if [ -z "$OK_DB" ]
524                 then
525                         ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --with-libical --disable-threaded-client >>$LOG 2>&1 || die
526                 else
527                         ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --with-libical --disable-threaded-client >>$LOG 2>&1 || die
528                 fi
529                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
530                 if [ x$IS_UPGRADE = xyes ]
531                 then
532                         echo "* Performing Citadel upgrade..."
533                         $MAKE upgrade >>$LOG 2>&1 || die
534                 else
535                         echo "* Performing Citadel install..."
536                         $MAKE install >>$LOG 2>&1 || die
537                         useradd -c "Citadel service account" -d $CITADEL -s $CITADEL/citadel citadel >>$LOG 2>&1
538                 fi
539                 echo $SUM >$SUMFILE
540         fi
541
542         ## begin webcit install
543
544         cd $BUILD >>$LOG 2>&1 || die
545         DO_INSTALL_WEBCIT=yes
546         FILENAME=webcit-easyinstall.sum ; download_this
547         SUM=`cat webcit-easyinstall.sum`
548         SUMFILE=$WEBCIT/webcit-easyinstall.sum
549         if [ -r $SUMFILE ] ; then
550                 OLDSUM=`cat $SUMFILE`
551                 if [ "$SUM" = "$OLDSUM" ] ; then
552                         echo "* WebCit does not need updating."
553                         DO_INSTALL_WEBCIT=no
554                 fi
555         fi
556
557         if [ $DO_INSTALL_WEBCIT = yes ] ; then
558                 echo "* Downloading WebCit..."
559                 FILENAME=$WEBCIT_SOURCE ; download_this
560                 echo "* Installing WebCit..."
561                 cd $BUILD >>$LOG 2>&1 || die
562                 ( gzip -dc $WEBCIT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
563                 cd $BUILD/webcit >>$LOG 2>&1 || die
564                 ./configure --prefix=$WEBCIT --with-libical >>$LOG 2>&1 || die
565                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
566                 rm -fr $WEBCIT/static 2>&1
567                 $MAKE install >>$LOG 2>&1 || die
568                 echo "  Complete."
569                 echo $SUM >$SUMFILE
570         fi
571
572         ## begin text client install
573
574         cd $BUILD >>$LOG 2>&1 || die
575         DO_INSTALL_TEXTCLIENT=yes
576         FILENAME=textclient-easyinstall.sum ; download_this
577         SUM=`cat textclient-easyinstall.sum`
578         SUMFILE=$CITADEL/webcit-easyinstall.sum
579         if [ -r $SUMFILE ] ; then
580                 OLDSUM=`cat $SUMFILE`
581                 if [ "$SUM" = "$OLDSUM" ] ; then
582                         echo "* Citadel text mode client does not need updating."
583                         DO_INSTALL_TEXTCLIENT=no
584                 fi
585         fi
586
587         if [ $DO_INSTALL_TEXTCLIENT = yes ] ; then
588                 echo "* Downloading the Citadel text mode client..."
589                 FILENAME=$TEXTCLIENT_SOURCE ; download_this
590                 echo "* Installing the Citadel text mode client..."
591                 cd $BUILD >>$LOG 2>&1 || die
592                 ( gzip -dc $TEXTCLIENT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
593                 cd $BUILD/textclient >>$LOG 2>&1 || die
594                 ./configure --prefix=$CITADEL >>$LOG 2>&1 || die
595                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
596                 $MAKE install >>$LOG 2>&1 || die
597                 echo "  Complete."
598                 echo $SUM >$SUMFILE
599         fi
600 }
601
602
603 do_config () {
604         echo "* Configuring your system ..."
605
606         if [ x$IS_UPGRADE = xyes ]
607         then
608                 echo Upgrading your existing Citadel installation.
609         else
610                 echo This is a new Citadel installation.
611         fi
612
613         if [ -x /etc/init.d/citadel ] ; then
614                 echo Stopping any previously running Citadel server...
615                 /etc/init.d/citadel stop
616         fi
617
618         # If we are running a Linux operating system we try even harder to stop citserver
619         if uname -a | grep -i linux ; then
620                 if ps ax | grep citserver | grep -v grep ; then
621                         echo citserver still running ... trying again to terminate it
622                         killall citserver
623                         sleep 3
624                 fi
625         fi
626
627         # If we are running a Linux operating system we try even harder to stop citserver
628         if uname -a | grep -i linux ; then
629                 if ps ax | grep citserver | grep -v grep ; then
630                         echo citserver still running ... trying again to terminate it
631                         killall -9 citserver
632                         sleep 3
633                 fi
634         fi
635
636         FILENAME=citadel-init-scripts.tar ; download_this
637         cat citadel-init-scripts.tar | (cd / ; tar xvf - )
638         echo Starting Citadel server...
639         /etc/init.d/citadel start
640
641         $CITADEL/setup </dev/tty || die
642         $WEBCIT/setup </dev/tty || die
643 }
644
645
646
647 ##### END Functions #####
648
649 ##### BEGIN main #####
650
651
652 # 0. Test to make sure we're running as root
653
654 PERMSTESTDIR=/usr/local/ctdltest.$$
655 mkdir $PERMSTESTDIR || {
656         echo
657         echo 'Easy Install is unable to create subdirectories in /usr/local.'
658         echo 'Did you forget to run the install command as the root user?'
659         echo 'Please become root (with a command like "su" or "sudo su") and'
660         echo 'try again.'
661         echo
662         exit 1
663 }
664 rmdir $PERMSTESTDIR 2>/dev/null
665
666 # 1. Gather information about the target system
667
668 # Non-GNU make does not work.
669 # This probably ought to be fixed, but for now we will simply require GNU make.
670
671 MAKE=xx
672 if gmake -v 2>&1 | grep -i GNU ; then
673         MAKE=`which gmake`
674 else
675         if make -v 2>&1 | grep -i GNU ; then
676                 MAKE=`which make`
677         fi
678 fi
679
680 if [ $MAKE == xx ] ; then
681         echo
682         echo 'Easy Install requires GNU Make (gmake), which was not found.'
683         echo 'Please install gmake and try again.'
684         echo
685         exit 1
686 fi
687
688 export MAKE
689
690 clear
691
692 os=`uname`
693
694 echo MAKE is $MAKE
695 export MAKE
696 rm -f $LOG 2>/dev/null
697
698
699 # Determine which operating system we are running on
700
701 OS=`uname -s`
702 REV=`uname -r`
703 MACH=`uname -m`
704
705 if [ "${OS}" = "SunOS" ] ; then
706         OS=Solaris
707         ARCH=`uname -p` 
708         OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
709 elif [ "${OS}" = "AIX" ] ; then
710         OSSTR="${OS} `oslevel` (`oslevel -r`)"
711 elif [ "${OS}" = "Linux" ] ; then
712         KERNEL=`uname -r`
713         if [ -f /etc/redhat-release ] ; then
714                 DIST='RedHat'
715                 PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
716                 REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
717         elif [ -f /etc/SUSE-release ] ; then
718                 DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
719                 REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
720         elif [ -f /etc/mandrake-release ] ; then
721                 DIST='Mandrake'
722                 PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
723                 REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
724         elif [ -f /etc/debian_version ] ; then
725                 DIST="Debian `cat /etc/debian_version`"
726                 REV=""
727
728         fi
729         if [ -f /etc/UnitedLinux-release ] ; then
730                 DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
731         fi
732         
733         OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
734
735 fi
736
737
738 rm -rf $BUILD
739 mkdir -p $BUILD
740 cd $BUILD
741
742
743 # 2. Present the installation steps (from 1 above) to the user
744 clear
745 if whiptail --infobox "Welcome to Citadel Easy Install" 10 70 2>/dev/null
746 then
747         CTDL_DIALOG=`which whiptail`
748         export CTDL_DIALOG
749 fi
750 clear
751
752 test_build_dir
753
754 echo "Welcome to $SETUP"
755 echo Running on: ${OSSTR}
756 echo "We will perform the following actions:"
757 echo ""
758 echo "Installation:"
759 echo "* Download/install supporting libraries (if needed)"
760 echo "* Download/install Citadel (if needed)"
761 echo "* Download/install WebCit (if needed)"
762 echo ""
763 echo "Configuration:"
764 echo "* Configure Citadel"
765 echo "* Configure WebCit"
766 echo ""
767 echo -n "Perform the above installation steps now? "
768 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
769
770         yesno=yes
771 else
772         read yesno </dev/tty
773 fi
774
775 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
776         exit 2
777 fi
778
779
780 FILENAME=gpl.txt ; download_this
781 cat $FILENAME
782 echo ""
783 echo "Do you accept the terms of this license?"
784 echo "If you do not accept the General Public License, Easy Install will exit."
785 echo -n "Enter Y or Yes to accept: "
786 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
787         yesno=yes
788 else
789         read yesno </dev/tty
790 fi
791
792 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
793         exit 2
794 fi
795
796 echo
797 if [ -f $CITADEL/citadel.config ]
798 then
799         IS_UPGRADE=yes
800         echo "* Upgrading your existing Citadel installation."
801 else
802         IS_UPGRADE=no
803         echo "* This is a NEW Citadel installation."
804 fi
805
806 if [ x$IS_UPGRADE = xyes ]
807 then
808         echo
809         echo "This appears to be an upgrade of an existing Citadel installation."
810         echo -n "Have you performed a FULL BACKUP of your programs and data? "
811         if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
812                 yesno=yes
813         else
814                 read yesno </dev/tty
815         fi
816
817         if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
818                 echo
819                 echo "citadel.org does not provide emergency support for sites"
820                 echo "which broke irrecoverably during a failed upgrade."
821                 echo "Easy Install will now exit."
822                 exit 2
823         fi
824 fi
825
826 clear
827
828 echo ""
829 echo "Installation will now begin."
830 echo "Command output will not be sent to the terminal."
831 echo "To view progress, see the $LOG file."
832 echo ""
833
834 # 3. Do the installation
835
836 install_prerequisites
837 install_sources
838
839 # 4. Do post-installation setup
840
841 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
842         echo skipping config
843 else
844         do_config
845 fi
846 rm -fr $BUILD
847
848 ##### END main #####
849
850