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