d69e2c25f7a4bdc2de46aa7eadc1a8bb91fec453
[citadel.git] / citadel / newinstall.sh
1 #!/bin/sh
2 # $Id$
3 #
4 #   Automatic script to install Citadel on a target system.
5 #   Copyright (C) 2004 Michael Hampton <error@citadel.org>
6 #   Copyright (C) 2004 Art Cancro <ajc@uncensored.citadel.org>
7 #
8 #   This program is free software; you can redistribute it and/or modify
9 #   it under the terms of the GNU General Public License as published by
10 #   the Free Software Foundation, version 2.
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 #   You should have received a copy of the GNU General Public License
18 #   along with this program; if not, write to the Free Software
19 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21 # Reading this script?  Here's some helpful hints:
22 #
23 # If you're seeing this in your browser, it's probably not what you want.
24 # You can either save it to disk and run it, or do it the easy way:
25 #
26 # curl http://easyinstall.citadel.org/install | sh
27 #
28 # Note that this script installs software on your system and so it requires
29 # root privileges.  Feel free to inspect the script to make sure we didn't
30 # do anything stupid...
31 #
32 # We have provided you the source code according to the terms of the respective
33 # software licenses included in the source code packages, even if you choose
34 # not to keep the source code around.  You can always download it again later.
35 #
36 # We install the following versions in this release:
37 # Package                    Status
38 # Citadel                    Latest
39 # WebCit                     Latest
40 # libical                    Latest
41 # Berkeley DB                Stable
42 # libSieve                   Stable
43
44
45 ###############################################################################
46 #
47 # This is the general stuff we're going to do, in order:
48 #
49 # 1. Gather information about the target system
50 # 2. Present the installation steps (from 1 above) to the user
51 # 3. Present any pre-install customizations to the user
52 # 4. Do the installation
53 #    A. Download any source code files or binary packages required
54 #    B. For native packaging, call the native packaging system to install
55 #    C. If we build our own, compile and install prerequisites then Citadel
56 # 5. Do post-installation setup
57 #
58 # Then call it a day.
59 #
60 ###############################################################################
61
62
63 # Begin user customization area
64 #
65 # These two directories specify where Citadel and its private support
66 # libraries will be installed.  This keeps them safely tucked away from
67 # the rest of your system.  The defaults should be fine for most people.
68 # NB: When binary packages are installed, these settings are ignored!
69 SUPPORT=/usr/local/ctdlsupport
70 CITADEL=/usr/local/citadel
71 WEBCIT=/usr/local/webcit
72 WORKDIR=/tmp
73 BUILD=$WORKDIR/citadel-build.$$
74 LOG=$WORKDIR/citadel-install-log.txt
75 export SUPPORT CITADEL WEBCIT
76
77 MAKEOPTS=""
78
79 # End user customization area
80
81 # We're now exporting a bunch of environment variables, and here's a list:
82 # CITADEL_INSTALLER     Set to "web" to indicate this script
83 # CITADEL               Directory where Citadel is installed
84 # WEBCIT                Directory where WebCit is installed
85 # SUPPORT               Directory where support programs are installed
86 # DISTRO_MAJOR          Linux distribution name, if applicable
87 # DISTRO_MINOR          Linux distribution name, if applicable
88 # DISTRO_VERSION        Linux distribution version (major digit) if applicable
89 # CC                    C compiler being used
90 # MAKE                  Make program being used
91 # CFLAGS                C compiler flags
92 # LDFLAGS               Linker flags
93 # IS_UPGRADE            Set to "yes" if upgrading an existing Citadel
94 # IS_AUTOLOGIN          Set to "yes" to force enabling autologin
95 # CTDL_DIALOG           Where (if at all) the "dialog" program may be found
96
97 # Let Citadel setup recognize the Citadel installer
98 CITADEL_INSTALLER=web
99 export CITADEL_INSTALLER
100
101 DOWNLOAD_SITE=http://easyinstall.citadel.org
102
103 # Original source code packages.
104 DB_SOURCE=db-4.3.29.NC.tar.gz
105 # DB_PATCHES=db-x.x.x.patches
106 ICAL_SOURCE=libical-0.26-6.aurore.tar.gz
107 LIBSIEVE_SOURCE=libsieve-2.2.3.tar.gz
108 CITADEL_SOURCE=citadel-easyinstall.tar.gz
109 WEBCIT_SOURCE=webcit-easyinstall.tar.gz
110
111 SETUP="Citadel Easy Install"
112
113
114 ##### BEGIN Functions #####
115
116 die () {
117         echo Easy Install is aborting.
118         echo Please report this problem to the Citadel developers.
119         echo Log file: $LOG
120         rm -fr $BUILD
121         exit 1
122 }
123
124
125 download_this () {
126         WGET=`which wget 2>/dev/null`
127         CURL=`which curl 2>/dev/null`
128         if [ -n "${WGET}" -a -x "${WGET}" ]; then
129                 $WGET $DOWNLOAD_SITE/$FILENAME >/dev/null 2>>$LOG || die
130         else
131                 if [ -n "${CURL}" -a -x "${CURL}" ]; then
132                         $CURL $DOWNLOAD_SITE/$FILENAME >$FILENAME 2>>$LOG || die
133                 else
134                         echo Unable to find a wget or curl command.
135                         echo Easy Install cannot continue.
136                         die;
137                 fi
138         fi
139 }
140
141
142
143 determine_distribution () {
144         # First look for Red Hat in general
145         if [ -x /bin/rpm ]; then
146                 RELEASE_FILE=/dev/null
147                 if /bin/rpm -q redhat-release >/dev/null 2>&1; then
148                         DISTRO_MAJOR=RedHat
149                         RELEASE_FILE=/etc/redhat-release
150                 fi
151                 if /bin/rpm -q whitebox-release >/dev/null 2>&1; then
152                         DISTRO_MAJOR=WhiteBox
153                         RELEASE_FILE=/etc/whitebox-release
154                 fi
155                 if /bin/rpm -q fedora-release >/dev/null 2>&1; then
156                         DISTRO_MAJOR=RedHat
157                         DISTRO_MINOR=Fedora
158                         RELEASE_FILE=/etc/fedora-release
159                 fi
160                 # Then look for specific version
161                 ( cat $RELEASE_FILE | grep Enterprise ) >/dev/null 2>&1 && \
162                         DISTRO_MINOR=Enterprise
163                 DISTRO_VERSION=`tr -cd "[^0-9.]" < $RELEASE_FILE | cut -c 1`
164         fi
165
166         # Check for Gentoo
167         if [ -f /etc/gentoo-release ]; then
168                 DISTRO_MAJOR=Gentoo
169         fi
170
171         # Check for Debian
172         # TODO: check for Debian
173 }
174
175 install_ical () {
176         cd $BUILD 2>&1 >>$LOG || die
177         FILENAME=libical-easyinstall.sum ; download_this
178         SUM=`cat libical-easyinstall.sum`
179         SUMFILE=$SUPPORT/etc/libical-easyinstall.sum
180         if [ -r $SUMFILE ] ; then
181                 OLDSUM=`cat $SUMFILE`
182                 if [ $SUM = $OLDSUM ] ; then
183                         echo "* libical does not need updating."
184                         return
185                 fi
186         fi
187         echo "* Downloading libical..."
188         FILENAME=$ICAL_SOURCE ; download_this
189         echo "* Installing libical..."
190         ( gzip -dc $ICAL_SOURCE | tar -xf - ) 2>&1 >>$LOG || die
191         cd $BUILD/libical-0.26 2>&1 >>$LOG || die
192         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
193         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
194         $MAKE install 2>&1 >>$LOG || die
195         echo "  Complete."
196         echo $SUM >$SUMFILE
197         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
198         rm -f $WEBCIT/webcit-easyinstall.sum 2>/dev/null
199 }
200
201 install_libsieve () {
202         cd $BUILD 2>&1 >>$LOG || die
203         FILENAME=libsieve-easyinstall.sum ; download_this
204         SUM=`cat libsieve-easyinstall.sum`
205         SUMFILE=$SUPPORT/etc/libsieve-easyinstall.sum
206         if [ -r $SUMFILE ] ; then
207                 OLDSUM=`cat $SUMFILE`
208                 if [ $SUM = $OLDSUM ] ; then
209                         echo "* libsieve does not need updating."
210                         return
211                 fi
212         fi
213         echo "* Downloading libsieve..."
214         FILENAME=$LIBSIEVE_SOURCE ; download_this
215         echo "* Installing libsieve..."
216         ( gzip -dc $LIBSIEVE_SOURCE | tar -xf - ) 2>&1 >>$LOG || die
217         cd $BUILD/libsieve-2.2.3/src 2>&1 >>$LOG || die
218         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
219         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
220         $MAKE install 2>&1 >>$LOG || die
221         echo "  Complete."
222         echo $SUM >$SUMFILE
223         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
224 }
225
226 install_db () {
227         cd $BUILD 2>&1 >>$LOG || die
228         FILENAME=db-easyinstall.sum ; download_this
229         SUM=`cat db-easyinstall.sum`
230         SUMFILE=$SUPPORT/etc/db-easyinstall.sum
231         if [ -r $SUMFILE ] ; then
232                 OLDSUM=`cat $SUMFILE`
233                 if [ $SUM = $OLDSUM ] ; then
234                         echo "* Berkeley DB does not need updating."
235                         return
236                 fi
237         fi
238         echo "* Downloading Berkeley DB..."
239         FILENAME=$DB_SOURCE ; download_this
240         echo "* Installing Berkeley DB..."
241         ( gzip -dc $DB_SOURCE | tar -xf - ) 2>&1 >>$LOG || die
242         cd $BUILD/db-4.3.29.NC 2>&1 >>$LOG || die
243         #patch -p0 < ../$DB_PATCHES 2>&1 >>$LOG || die
244         cd $BUILD/db-4.3.29.NC/build_unix 2>&1 >>$LOG || die
245         ../dist/configure --prefix=$SUPPORT --disable-compat185 --disable-cxx --disable-debug --disable-dump185 --disable-java --disable-rpc --disable-tcl --disable-test --without-rpm 2>&1 >>$LOG || die
246         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
247         $MAKE install 2>&1 >>$LOG || die
248         echo "  Complete."
249         echo $SUM >$SUMFILE
250         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
251 }
252
253 install_prerequisites () {
254
255         # Create the support directories if they don't already exist
256
257         mkdir $SUPPORT          2>/dev/null
258         mkdir $SUPPORT/bin      2>/dev/null
259         mkdir $SUPPORT/sbin     2>/dev/null
260         mkdir $SUPPORT/lib      2>/dev/null
261         mkdir $SUPPORT/libexec  2>/dev/null
262         mkdir $SUPPORT/include  2>/dev/null
263         mkdir $SUPPORT/etc      2>/dev/null
264
265         # Now have phun!
266
267         if [ -z "$OK_ICAL" ]
268         then
269                 install_ical
270         fi
271         if [ -z "$OK_LIBSIEVE" ]
272         then
273                 install_libsieve
274         fi
275         if [ -z "$OK_DB" ]
276         then
277                 install_db
278         fi
279 }
280
281 install_sources () {
282         cd $BUILD 2>&1 >>$LOG || die
283         if [ -f $CITADEL/citadel.config ]
284         then
285                 IS_UPGRADE=yes
286                 echo "* Upgrading your existing Citadel installation."
287         else
288                 IS_UPGRADE=no
289         fi
290
291         CFLAGS="-I${SUPPORT}/include"
292         CPPFLAGS="${CFLAGS}"
293         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
294         export CFLAGS CPPFLAGS LDFLAGS
295
296         DO_INSTALL_CITADEL=yes
297         FILENAME=citadel-easyinstall.sum ; download_this
298         SUM=`cat citadel-easyinstall.sum`
299         SUMFILE=$CITADEL/citadel-easyinstall.sum
300         if [ -r $SUMFILE ] ; then
301                 OLDSUM=`cat $SUMFILE`
302                 if [ $SUM = $OLDSUM ] ; then
303                         echo "* Citadel does not need updating."
304                         DO_INSTALL_CITADEL=no
305                 fi
306         fi
307
308         if [ $DO_INSTALL_CITADEL = yes ] ; then
309                 echo "* Downloading Citadel..."
310                 FILENAME=$CITADEL_SOURCE ; download_this
311                 echo "* Installing Citadel..."
312                 cd $BUILD 2>&1 >>$LOG || die
313                 ( gzip -dc $CITADEL_SOURCE | tar -xf - ) 2>&1 >>$LOG || die
314                 cd $BUILD/citadel 2>&1 >>$LOG || die
315                 if [ x$IS_AUTOLOGIN = xyes ] ; then
316                         AL="--enable-autologin"
317                 else
318                         AL=""
319                 fi
320                 if [ -z "$OK_DB" ]
321                 then
322                         ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam $AL --with-libical --disable-threaded-client 2>&1 >>$LOG || die
323                 else
324                         ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam $AL --with-libical --disable-threaded-client 2>&1 >>$LOG || die
325                 fi
326                 $MAKE $MAKEOPTS 2>&1 >>$LOG || die
327                 if [ $IS_UPGRADE = yes ]
328                 then
329                         echo "* Performing Citadel upgrade..."
330                         $MAKE upgrade 2>&1 >>$LOG || die
331                 else
332                         echo "* Performing Citadel install..."
333                         $MAKE install 2>&1 >>$LOG || die
334                         useradd -c "Citadel service account" -d $CITADEL -s $CITADEL/citadel citadel 2>&1 >>$LOG
335                 fi
336                 echo $SUM >$SUMFILE
337         fi
338
339         cd $BUILD 2>&1 >>$LOG || die
340         DO_INSTALL_WEBCIT=yes
341         FILENAME=webcit-easyinstall.sum ; download_this
342         SUM=`cat webcit-easyinstall.sum`
343         SUMFILE=$WEBCIT/webcit-easyinstall.sum
344         if [ -r $SUMFILE ] ; then
345                 OLDSUM=`cat $SUMFILE`
346                 if [ $SUM = $OLDSUM ] ; then
347                         echo "* WebCit does not need updating."
348                         DO_INSTALL_WEBCIT=no
349                 fi
350         fi
351
352         if [ $DO_INSTALL_WEBCIT = yes ] ; then
353                 echo "* Downloading WebCit..."
354                 FILENAME=$WEBCIT_SOURCE ; download_this
355                 echo "* Installing WebCit..."
356                 cd $BUILD 2>&1 >>$LOG || die
357                 ( gzip -dc $WEBCIT_SOURCE | tar -xf - ) 2>&1 >>$LOG || die
358                 cd $BUILD/webcit 2>&1 >>$LOG || die
359                 ./configure --prefix=$WEBCIT --with-libical 2>&1 >>$LOG || die
360                 $MAKE $MAKEOPTS 2>&1 >>$LOG || die
361                 $MAKE install 2>&1 >>$LOG || die
362                 echo "  Complete."
363                 echo $SUM >$SUMFILE
364         fi
365 }
366
367
368 do_config () {
369         echo "* Configuring your system ..."
370
371         if [ x$IS_UPGRADE == xyes ] ; then
372                 echo Upgrading your existing Citadel installation.
373                 $CITADEL/setup </dev/tty || die
374         else
375                 echo This is a new Citadel installation.
376                 $CITADEL/setup </dev/tty || die
377         fi
378
379         $WEBCIT/setup </dev/tty || die
380 }
381
382
383
384 ##### END Functions #####
385
386 ##### BEGIN main #####
387
388 # 1. Gather information about the target system
389
390 # Non-GNU make does not work.
391 # This probably ought to be fixed, but for now we will simply require GNU make.
392
393 MAKE=xx
394 if gmake -v 2>&1 | grep -i GNU ; then
395         MAKE=`which gmake`
396 else
397         if make -v 2>&1 | grep -i GNU ; then
398                 MAKE=`which make`
399         fi
400 fi
401
402 if [ $MAKE == xx ] ; then
403         echo
404         echo 'Easy Install requires GNU Make (gmake), which was not found.'
405         echo 'Please install gmake and try again.'
406         echo
407         exit 1
408 fi
409
410 export MAKE
411
412 clear
413
414 os=`uname`
415
416
417 echo MAKE is $MAKE
418 export MAKE
419
420 # 1A. Do we use the native packaging system or build our own copy of Citadel?
421
422 if [ "$os" = "Linux" ]; then
423         determine_distribution
424 elif [ "$os" = "FreeBSD" ]; then
425         # TODO: We detect FreeBSD but the port is still out of date...
426         DISTRO_MAJOR=FreeBSD
427 elif [ "$os" = "Darwin" ]; then
428         # TODO: Deal with Apple weirdness
429         DISTRO_MAJOR=Darwin
430 fi
431
432
433 rm -rf $BUILD
434 mkdir -p $BUILD
435 cd $BUILD
436
437
438
439 # 2. Present the installation steps (from 1 above) to the user
440 clear
441 if dialog 2>&1 </dev/tty | grep gauge >/dev/null 2>&1 ; then
442         CTDL_DIALOG=`which dialog`
443         export CTDL_DIALOG
444 elif cdialog 2>&1 </dev/tty | grep gauge >/dev/null 2>&1 ; then
445         CTDL_DIALOG=`which cdialog`
446         export CTDL_DIALOG
447 fi
448 clear
449
450 echo "$SETUP will perform the following actions:"
451 echo ""
452 echo "Installation:"
453 echo "* Download/install supporting libraries (if needed)"
454 echo "* Download/install Citadel (if needed)"
455 echo "* Download/install WebCit (if needed)"
456 echo ""
457 echo "Configuration:"
458 echo "* Configure Citadel"
459 echo "* Configure WebCit"
460 if [ x$IS_AUTOLOGIN = xyes ] ; then
461         echo 'NOTE: this is an autologin installation.'
462         echo '      Authentication against user accounts on the host system is enabled.'
463 fi
464 echo ""
465 echo -n "Perform the above installation steps now? "
466 read yesno </dev/tty
467
468 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
469         exit 2
470 fi
471
472 echo ""
473 echo "Command output will not be sent to the terminal."
474 echo "To view progress, see the $LOG file."
475 echo ""
476
477 # 3. Present any pre-install customizations to the user
478
479 # TODO: enter in the configuration dialogs
480
481 # Configure Citadel
482
483 # Configure WebCit
484
485 # 4. Do the installation
486
487 # 4A. Download any source code files or binary packages required
488
489 if [ "$prepackaged" ]; then
490         download_packages
491
492 # 4B. For native packaging, call the native packaging system to install
493
494         install_packages
495 else
496
497 # 4C. If we build our own, compile and install prerequisites then Citadel
498
499         install_prerequisites
500         install_sources
501 fi
502
503 # 5. Do post-installation setup
504         rm -fr $BUILD
505         do_config
506 ##### END main #####