d14a8a52b7ad1df9de7ce34c345717e879369646
[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 LIBCITADEL_SOURCE=libcitadel-easyinstall.tar.gz
107 CITADEL_SOURCE=citadel-easyinstall.tar.gz
108 WEBCIT_SOURCE=webcit-easyinstall.tar.gz
109 TEXTCLIENT_SOURCE=textclient-easyinstall.tar.gz
110 INCADD=
111 LDADD=
112
113 case `uname -s` in
114         *BSD)
115                 LDADD="-L/usr/local/lib"
116                 INCADD="-I/usr/local/include"
117         ;;
118 esac
119
120 ##### BEGIN Functions #####
121
122 GetVersionFromFile()
123 {
124         VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
125 }
126
127
128 die () {
129         echo
130         echo $SETUP is aborting.
131         echo
132         echo A log file has been written to $LOG
133         echo Reading this file may tell you what went wrong.  If you
134         echo need to ask for help on the support forum, please post the
135         echo last screenful of text from this log.
136         echo
137         echo Operating system: ${OSSTR}
138         echo Operating system: ${OSSTR} >>$LOG
139         cd $WORKDIR
140         rm -fr $BUILD
141         exit 1
142 }
143
144
145
146 test_build_dir() {
147         tempfilename=test$$.sh
148
149         echo '#!/bin/sh' >$tempfilename
150         echo '' >>$tempfilename
151         echo 'exit 0' >>$tempfilename
152         chmod 700 $tempfilename
153
154         [ -x $tempfilename ] || {
155                 echo Cannot write to `pwd`
156                 echo 'Are you not running this program as root?'
157                 die
158         }
159
160         ./$tempfilename || {
161                 echo Cannot execute a script.
162                 echo 'If /tmp is mounted noexec, please change this before continuing.'
163                 die
164         }
165
166 }
167
168
169
170 download_this () {
171         WGET=`which wget 2>/dev/null`
172         CURL=`which curl 2>/dev/null`
173         if [ -n "${WGET}" -a -x "${WGET}" ]; then
174                 $WGET $DOWNLOAD_SITE/$FILENAME >/dev/null 2>>$LOG || die
175         else
176                 if [ -n "${CURL}" -a -x "${CURL}" ]; then
177                         $CURL $DOWNLOAD_SITE/$FILENAME >$FILENAME 2>>$LOG || die
178                 else
179                         echo Unable to find a wget or curl command.
180                         echo $SETUP cannot continue.
181                         die;
182                 fi
183         fi
184 }
185
186
187
188 install_ical () {
189         cd $BUILD >>$LOG 2>&1 || die
190         FILENAME=libical-easyinstall.sum ; download_this
191         SUM=`cat libical-easyinstall.sum`
192         SUMFILE=$SUPPORT/etc/libical-easyinstall.sum
193         if [ -r $SUMFILE ] ; then
194                 OLDSUM=`cat $SUMFILE`
195                 if [ "$SUM" = "$OLDSUM" ] ; then
196                         echo "* libical does not need updating."
197                         return
198                 fi
199         fi
200         echo "* Downloading libical..."
201         FILENAME=$ICAL_SOURCE ; download_this
202         echo "* Installing libical..."
203         ( gzip -dc $ICAL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
204         cd $BUILD/libical >>$LOG 2>&1 || die
205         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
206         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
207         $MAKE install >>$LOG 2>&1 || die
208         echo "  Complete."
209         echo $SUM >$SUMFILE
210         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
211         rm -f $WEBCIT/webcit-easyinstall.sum 2>/dev/null
212 }
213
214 install_libsieve () {
215         cd $BUILD >>$LOG 2>&1 || die
216         FILENAME=libsieve-easyinstall.sum ; download_this
217         SUM=`cat libsieve-easyinstall.sum`
218         SUMFILE=$SUPPORT/etc/libsieve-easyinstall.sum
219         if [ -r $SUMFILE ] ; then
220                 OLDSUM=`cat $SUMFILE`
221                 if [ "$SUM" = "$OLDSUM" ] ; then
222                         echo "* libsieve does not need updating."
223                         return
224                 fi
225         fi
226         echo "* Downloading libsieve..."
227         FILENAME=$LIBSIEVE_SOURCE ; download_this
228         echo "* Installing libsieve..."
229         ( gzip -dc $LIBSIEVE_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
230         cd $BUILD/libsieve-2.2.7/src >>$LOG 2>&1 || die
231         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
232         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
233         $MAKE install >>$LOG 2>&1 || die
234         echo "  Complete."
235         echo $SUM >$SUMFILE
236         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
237 }
238
239 install_expat () {
240         cd $BUILD >>$LOG 2>&1 || die
241         FILENAME=expat-easyinstall.sum ; download_this
242         SUM=`cat expat-easyinstall.sum`
243         SUMFILE=$SUPPORT/etc/expat-easyinstall.sum
244         if [ -r $SUMFILE ] ; then
245                 OLDSUM=`cat $SUMFILE`
246                 if [ "$SUM" = "$OLDSUM" ] ; then
247                         echo "* expat does not need updating."
248                         return
249                 fi
250         fi
251         echo "* Downloading expat..."
252         FILENAME=$EXPAT_SOURCE ; download_this
253         echo "* Installing Expat..."
254         ( gzip -dc $EXPAT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
255         cd $BUILD/expat-2.0.1 >>$LOG 2>&1 || die
256         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
257         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
258         $MAKE install >>$LOG 2>&1 || die
259         echo "  Complete."
260         echo $SUM >$SUMFILE
261         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
262 }
263
264
265 install_libcurl () {
266         cd $BUILD >>$LOG 2>&1 || die
267         FILENAME=libcurl-easyinstall.sum ; download_this
268         SUM=`cat libcurl-easyinstall.sum`
269         SUMFILE=$SUPPORT/etc/libcurl-easyinstall.sum
270         if [ -r $SUMFILE ] ; then
271                 OLDSUM=`cat $SUMFILE`
272                 if [ "$SUM" = "$OLDSUM" ] ; then
273                         echo "* libcurl does not need updating."
274                         return
275                 fi
276         fi
277         echo "* Downloading libcurl..."
278         FILENAME=$LIBCURL_SOURCE ; download_this
279         echo "* Installing libcurl..."
280         ( gzip -dc $LIBCURL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
281         CFLAGS="${CFLAGS} -I${SUPPORT}/include ${INCADD} -g"
282         CPPFLAGS="${CFLAGS}"
283         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib ${LDADD}"
284         export CFLAGS CPPFLAGS LDFLAGS
285
286         cd $BUILD/curl-7.26.0 >>$LOG 2>&1 || die
287         ./configure --prefix=$SUPPORT --disable-file --disable-ldap --disable-ldaps \
288                 --disable-dict --disable-telnet --disable-tftp --disable-manual \
289                 --enable-thread --disable-sspi --disable-crypto-auth --disable-cookies \
290                 --without-libssh2 --without-ca-path --without-libidn \
291                 --enable-ares=$SUPPORT \
292                 >>$LOG 2>&1 || die
293         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
294         $MAKE install >>$LOG 2>&1 || die
295         echo "  Complete."
296         echo $SUM >$SUMFILE
297         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
298 }
299
300
301 install_libev () {
302         cd $BUILD >>$LOG 2>&1 || die
303         FILENAME=libev-easyinstall.sum ; download_this
304         SUM=`cat libev-easyinstall.sum`
305         SUMFILE=$SUPPORT/etc/libev-easyinstall.sum
306         if [ -r $SUMFILE ] ; then
307                 OLDSUM=`cat $SUMFILE`
308                 if [ "$SUM" = "$OLDSUM" ] ; then
309                         echo "* libev does not need updating."
310                         return
311                 fi
312         fi
313         echo "* Downloading libev..."
314         FILENAME=$LIBEV_SOURCE ; download_this
315         echo "* Installing libev..."
316         ( gzip -dc $LIBEV_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
317         cd $BUILD/libev-4.11 >>$LOG 2>&1 || die
318         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
319         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
320         $MAKE install >>$LOG 2>&1 || die
321         echo "  Complete."
322         echo $SUM >$SUMFILE
323         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
324 }
325
326
327 install_cares () {
328         cd $BUILD >>$LOG 2>&1 || die
329         FILENAME=c-ares-easyinstall.sum ; download_this
330         SUM=`cat c-ares-easyinstall.sum`
331         SUMFILE=$SUPPORT/etc/c-ares-easyinstall.sum
332         if [ -r $SUMFILE ] ; then
333                 OLDSUM=`cat $SUMFILE`
334                 if [ "$SUM" = "$OLDSUM" ] ; then
335                         echo "* c-ares does not need updating."
336                         return
337                 fi
338         fi
339         echo "* Downloading libev..."
340         FILENAME=$CARES_SOURCE ; download_this
341         echo "* Installing c-ares..."
342         ( gzip -dc $CARES_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
343         cd $BUILD/c-ares-1.7.5 >>$LOG 2>&1 || die
344         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
345         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
346         $MAKE install >>$LOG 2>&1 || die
347         echo "  Complete."
348         echo $SUM >$SUMFILE
349         rm -f $SUPPORT/etc/libcurl-easyinstall.sum 2>/dev/null
350         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
351 }
352
353
354 install_libcitadel () {
355         cd $BUILD >>$LOG 2>&1 || die
356         FILENAME=libcitadel-easyinstall.sum ; download_this
357         SUM=`cat libcitadel-easyinstall.sum`
358         SUMFILE=$SUPPORT/etc/libcitadel-easyinstall.sum
359         if [ -r $SUMFILE ] ; then
360                 OLDSUM=`cat $SUMFILE`
361                 if [ "$SUM" = "$OLDSUM" ] ; then
362                         echo "* libcitadel does not need updating."
363                         return
364                 fi
365         fi
366         echo "* Downloading libcitadel..."
367         FILENAME=$LIBCITADEL_SOURCE ; download_this
368         echo "* Installing libcitadel..."
369         ( gzip -dc $LIBCITADEL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
370         cd $BUILD/libcitadel >>$LOG 2>&1 || die
371         ./configure --prefix=$SUPPORT >>$LOG 2>&1 || die
372         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
373         $MAKE install >>$LOG 2>&1 || die
374         echo "  Complete."
375         echo $SUM >$SUMFILE
376         # Upgrading libcitadel forces the upgrade of programs which link to it
377         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
378         rm -f $CITADEL/webcit-easyinstall.sum 2>/dev/null
379         rm -f $CITADEL/textclient-easyinstall.sum 2>/dev/null
380 }
381
382 install_db () {
383         cd $BUILD >>$LOG 2>&1 || die
384         FILENAME=db-easyinstall.sum ; download_this
385         SUM=`cat db-easyinstall.sum`
386         SUMFILE=$SUPPORT/etc/db-easyinstall.sum
387         if [ -r $SUMFILE ] ; then
388                 OLDSUM=`cat $SUMFILE`
389                 if [ "$SUM" = "$OLDSUM" ] ; then
390                         echo "* Berkeley DB does not need updating."
391                         return
392                 fi
393         fi
394         echo "* Downloading Berkeley DB..."
395         FILENAME=$DB_SOURCE ; download_this
396         echo "* Installing Berkeley DB..."
397         ( gzip -dc $DB_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
398         cd $BUILD/db-5.1.29.NC/build_unix >>$LOG 2>&1 || die
399         ../dist/configure --prefix=$SUPPORT --disable-compat185 --disable-cxx --disable-debug --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm >>$LOG 2>&1 || die
400         $MAKE $MAKEOPTS >>$LOG 2>&1 || die
401         $MAKE install >>$LOG 2>&1 || die
402         echo "  Complete."
403         echo $SUM >$SUMFILE
404         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
405 }
406
407 install_prerequisites () {
408
409         # Create the support directories if they don't already exist
410
411         mkdir $SUPPORT          2>/dev/null
412         mkdir $SUPPORT/bin      2>/dev/null
413         mkdir $SUPPORT/sbin     2>/dev/null
414         mkdir $SUPPORT/lib      2>/dev/null
415         mkdir $SUPPORT/libexec  2>/dev/null
416         mkdir $SUPPORT/include  2>/dev/null
417         mkdir $SUPPORT/etc      2>/dev/null
418
419         # Now have phun!
420
421         if [ -z "$OK_ICAL" ]
422         then
423                 install_ical
424         fi
425         if [ -z "$OK_LIBSIEVE" ]
426         then
427                 install_libsieve
428         fi
429         if [ -z "$OK_DB" ]
430         then
431                 install_db
432         fi
433         if [ -z "$OK_EXPAT" ]
434         then
435                 install_expat
436         fi
437         if [ -z "$OK_LIBEV" ]
438         then
439                 install_libev
440         fi
441         if [ -z "$OK_CARES" ]
442         then
443                 install_cares
444         fi
445         if [ -z "$OK_LIBCURL" ]
446         then
447                 install_libcurl
448         fi
449 }
450
451 install_sources () {
452
453         install_libcitadel
454
455         cd $BUILD >>$LOG 2>&1 || die
456         if [ x$IS_UPGRADE = xyes ]
457         then
458                 echo "* Upgrading your existing Citadel installation."
459         fi
460
461         CFLAGS="${CFLAGS} -I${SUPPORT}/include ${INCADD} -g"
462         CPPFLAGS="${CFLAGS}"
463         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib ${LDADD}"
464         export CFLAGS CPPFLAGS LDFLAGS
465
466         DO_INSTALL_CITADEL=yes
467         FILENAME=citadel-easyinstall.sum ; download_this
468         SUM=`cat citadel-easyinstall.sum`
469         SUMFILE=$CITADEL/citadel-easyinstall.sum
470         if [ -r $SUMFILE ] ; then
471                 OLDSUM=`cat $SUMFILE`
472                 if [ "$SUM" = "$OLDSUM" ] ; then
473                         echo "* Citadel does not need updating."
474                         DO_INSTALL_CITADEL=no
475                 fi
476         fi
477
478         if [ $DO_INSTALL_CITADEL = yes ] ; then
479                 echo "* Downloading Citadel..."
480                 FILENAME=$CITADEL_SOURCE ; download_this
481                 echo "* Installing Citadel..."
482                 cd $BUILD >>$LOG 2>&1 || die
483                 ( gzip -dc $CITADEL_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
484                 cd $BUILD/citadel >>$LOG 2>&1 || die
485                 if [ -z "$OK_DB" ]
486                 then
487                         ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --with-libical --disable-threaded-client >>$LOG 2>&1 || die
488                 else
489                         ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --with-libical --disable-threaded-client >>$LOG 2>&1 || die
490                 fi
491                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
492                 if [ x$IS_UPGRADE = xyes ]
493                 then
494                         echo "* Performing Citadel upgrade..."
495                         $MAKE upgrade >>$LOG 2>&1 || die
496                 else
497                         echo "* Performing Citadel install..."
498                         $MAKE install >>$LOG 2>&1 || die
499                         useradd -c "Citadel service account" -d $CITADEL -s $CITADEL/citadel citadel >>$LOG 2>&1
500                 fi
501                 echo $SUM >$SUMFILE
502         fi
503
504         ## begin webcit install
505
506         cd $BUILD >>$LOG 2>&1 || die
507         DO_INSTALL_WEBCIT=yes
508         FILENAME=webcit-easyinstall.sum ; download_this
509         SUM=`cat webcit-easyinstall.sum`
510         SUMFILE=$WEBCIT/webcit-easyinstall.sum
511         if [ -r $SUMFILE ] ; then
512                 OLDSUM=`cat $SUMFILE`
513                 if [ "$SUM" = "$OLDSUM" ] ; then
514                         echo "* WebCit does not need updating."
515                         DO_INSTALL_WEBCIT=no
516                 fi
517         fi
518
519         if [ $DO_INSTALL_WEBCIT = yes ] ; then
520                 echo "* Downloading WebCit..."
521                 FILENAME=$WEBCIT_SOURCE ; download_this
522                 echo "* Installing WebCit..."
523                 cd $BUILD >>$LOG 2>&1 || die
524                 ( gzip -dc $WEBCIT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
525                 cd $BUILD/webcit >>$LOG 2>&1 || die
526                 ./configure --prefix=$WEBCIT --with-libical >>$LOG 2>&1 || die
527                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
528                 rm -fr $WEBCIT/static 2>&1
529                 $MAKE install >>$LOG 2>&1 || die
530                 echo "  Complete."
531                 echo $SUM >$SUMFILE
532         fi
533
534         ## begin text client install
535
536         cd $BUILD >>$LOG 2>&1 || die
537         DO_INSTALL_TEXTCLIENT=yes
538         FILENAME=textclient-easyinstall.sum ; download_this
539         SUM=`cat textclient-easyinstall.sum`
540         SUMFILE=$CITADEL/webcit-easyinstall.sum
541         if [ -r $SUMFILE ] ; then
542                 OLDSUM=`cat $SUMFILE`
543                 if [ "$SUM" = "$OLDSUM" ] ; then
544                         echo "* Citadel text mode client does not need updating."
545                         DO_INSTALL_TEXTCLIENT=no
546                 fi
547         fi
548
549         if [ $DO_INSTALL_TEXTCLIENT = yes ] ; then
550                 echo "* Downloading the Citadel text mode client..."
551                 FILENAME=$TEXTCLIENT_SOURCE ; download_this
552                 echo "* Installing the Citadel text mode client..."
553                 cd $BUILD >>$LOG 2>&1 || die
554                 ( gzip -dc $TEXTCLIENT_SOURCE | tar -xf - ) >>$LOG 2>&1 || die
555                 cd $BUILD/textclient >>$LOG 2>&1 || die
556                 ./configure --prefix=$CITADEL >>$LOG 2>&1 || die
557                 $MAKE $MAKEOPTS >>$LOG 2>&1 || die
558                 $MAKE install >>$LOG 2>&1 || die
559                 echo "  Complete."
560                 echo $SUM >$SUMFILE
561         fi
562 }
563
564
565 do_config () {
566         echo "* Configuring your system ..."
567
568         if [ x$IS_UPGRADE = xyes ]
569         then
570                 echo Upgrading your existing Citadel installation.
571         else
572                 echo This is a new Citadel installation.
573         fi
574
575         if [ -x /etc/init.d/citadel ] ; then
576                 echo Stopping any previously running Citadel server...
577                 /etc/init.d/citadel stop
578         fi
579
580         # If we are running a Linux operating system we try even harder to stop citserver
581         if uname -a | grep -i linux ; then
582                 if ps ax | grep citserver | grep -v grep ; then
583                         echo citserver still running ... trying again to terminate it
584                         killall citserver
585                         sleep 3
586                 fi
587         fi
588
589         # If we are running a Linux operating system we try even harder to stop citserver
590         if uname -a | grep -i linux ; then
591                 if ps ax | grep citserver | grep -v grep ; then
592                         echo citserver still running ... trying again to terminate it
593                         killall -9 citserver
594                         sleep 3
595                 fi
596         fi
597
598         FILENAME=citadel-init-scripts.tar ; download_this
599         cat citadel-init-scripts.tar | (cd / ; tar xvf - )
600         echo Starting Citadel server...
601         /etc/init.d/citadel start
602
603         $CITADEL/setup </dev/tty || die
604         $WEBCIT/setup </dev/tty || die
605 }
606
607
608
609 ##### END Functions #####
610
611 ##### BEGIN main #####
612
613
614 # 0. Test to make sure we're running as root
615
616 PERMSTESTDIR=/usr/local/ctdltest.$$
617 mkdir $PERMSTESTDIR || {
618         echo
619         echo 'Easy Install is unable to create subdirectories in /usr/local.'
620         echo 'Did you forget to run the install command as the root user?'
621         echo 'Please become root (with a command like "su" or "sudo su") and'
622         echo 'try again.'
623         echo
624         exit 1
625 }
626 rmdir $PERMSTESTDIR 2>/dev/null
627
628 # 1. Gather information about the target system
629
630 # Non-GNU make does not work.
631 # This probably ought to be fixed, but for now we will simply require GNU make.
632
633 MAKE=xx
634 if gmake -v 2>&1 | grep -i GNU ; then
635         MAKE=`which gmake`
636 else
637         if make -v 2>&1 | grep -i GNU ; then
638                 MAKE=`which make`
639         fi
640 fi
641
642 if [ $MAKE == xx ] ; then
643         echo
644         echo 'Easy Install requires GNU Make (gmake), which was not found.'
645         echo 'Please install gmake and try again.'
646         echo
647         exit 1
648 fi
649
650 export MAKE
651
652 clear
653
654 os=`uname`
655
656 echo MAKE is $MAKE
657 export MAKE
658 rm -f $LOG 2>/dev/null
659
660
661 # Determine which operating system we are running on
662
663 OS=`uname -s`
664 REV=`uname -r`
665 MACH=`uname -m`
666
667 if [ "${OS}" = "SunOS" ] ; then
668         OS=Solaris
669         ARCH=`uname -p` 
670         OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
671 elif [ "${OS}" = "AIX" ] ; then
672         OSSTR="${OS} `oslevel` (`oslevel -r`)"
673 elif [ "${OS}" = "Linux" ] ; then
674         KERNEL=`uname -r`
675         if [ -f /etc/redhat-release ] ; then
676                 DIST='RedHat'
677                 PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
678                 REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
679         elif [ -f /etc/SUSE-release ] ; then
680                 DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
681                 REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
682         elif [ -f /etc/mandrake-release ] ; then
683                 DIST='Mandrake'
684                 PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
685                 REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
686         elif [ -f /etc/debian_version ] ; then
687                 DIST="Debian `cat /etc/debian_version`"
688                 REV=""
689
690         fi
691         if [ -f /etc/UnitedLinux-release ] ; then
692                 DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
693         fi
694         
695         OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
696
697 fi
698
699
700 rm -rf $BUILD
701 mkdir -p $BUILD
702 cd $BUILD
703
704
705 # 2. Present the installation steps (from 1 above) to the user
706 clear
707 if whiptail --infobox "Welcome to Citadel Easy Install" 10 70 2>/dev/null
708 then
709         CTDL_DIALOG=`which whiptail`
710         export CTDL_DIALOG
711 fi
712 clear
713
714 test_build_dir
715
716 echo "Welcome to $SETUP"
717 echo Running on: ${OSSTR}
718 echo "We will perform the following actions:"
719 echo ""
720 echo "Installation:"
721 echo "* Download/install supporting libraries (if needed)"
722 echo "* Download/install Citadel (if needed)"
723 echo "* Download/install WebCit (if needed)"
724 echo ""
725 echo "Configuration:"
726 echo "* Configure Citadel"
727 echo "* Configure WebCit"
728 echo ""
729 echo -n "Perform the above installation steps now? "
730 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
731
732         yesno=yes
733 else
734         read yesno </dev/tty
735 fi
736
737 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
738         exit 2
739 fi
740
741
742 FILENAME=gpl.txt ; download_this
743 cat $FILENAME
744 echo ""
745 echo "Do you accept the terms of this license?"
746 echo "If you do not accept the General Public License, Easy Install will exit."
747 echo -n "Enter Y or Yes to accept: "
748 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
749         yesno=yes
750 else
751         read yesno </dev/tty
752 fi
753
754 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
755         exit 2
756 fi
757
758 echo
759 if [ -f $CITADEL/citadel.config ]
760 then
761         IS_UPGRADE=yes
762         echo "* Upgrading your existing Citadel installation."
763 else
764         IS_UPGRADE=no
765         echo "* This is a NEW Citadel installation."
766 fi
767
768 if [ x$IS_UPGRADE = xyes ]
769 then
770         echo
771         echo "This appears to be an upgrade of an existing Citadel installation."
772         echo -n "Have you performed a FULL BACKUP of your programs and data? "
773         if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
774                 yesno=yes
775         else
776                 read yesno </dev/tty
777         fi
778
779         if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
780                 echo
781                 echo "citadel.org does not provide emergency support for sites"
782                 echo "which broke irrecoverably during a failed upgrade."
783                 echo "Easy Install will now exit."
784                 exit 2
785         fi
786 fi
787
788 clear
789
790 echo ""
791 echo "Installation will now begin."
792 echo "Command output will not be sent to the terminal."
793 echo "To view progress, see the $LOG file."
794 echo ""
795
796 # 3. Do the installation
797
798 install_prerequisites
799 install_sources
800
801 # 4. Do post-installation setup
802
803 if [ x$UNATTENDED_BUILD = "xYOU_BETCHA" ] ; then
804         echo skipping config
805 else
806         do_config
807 fi
808 rm -fr $BUILD
809
810 ##### END main #####
811
812