]> 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
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 # SLAPD_BINARY          Location of the slapd binary
87 # DISTRO_MAJOR          Linux distribution name, if applicable
88 # DISTRO_MINOR          Linux distribution name, if applicable
89 # DISTRO_VERSION        Linux distribution version (major digit) if applicable
90 # CC                    C compiler being used
91 # MAKE                  Make program being used
92 # CFLAGS                C compiler flags
93 # LDFLAGS               Linker flags
94 # IS_UPGRADE            Set to "yes" if upgrading an existing Citadel
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.21.NC.tar.gz
105 # DB_PATCHES=db-x.x.x.patches
106 ICAL_SOURCE=libical-0.24.RC4.tar.gz
107 CITADEL_SOURCE=citadel-easyinstall.tar.gz
108 WEBCIT_SOURCE=webcit-easyinstall.tar.gz
109
110 SETUP="Citadel Easy Install"
111
112
113 ##### BEGIN Functions #####
114
115 die () {
116         echo Easy Install is aborting.
117         echo Please report this problem to the Citadel developers.
118         echo Log file: $LOG
119         rm -fr $BUILD
120         exit 1
121 }
122
123
124 determine_distribution () {
125         # First look for Red Hat in general
126         if [ -x /bin/rpm ]; then
127                 RELEASE_FILE=/dev/null
128                 if /bin/rpm -q redhat-release >/dev/null 2>&1; then
129                         DISTRO_MAJOR=RedHat
130                         RELEASE_FILE=/etc/redhat-release
131                 fi
132                 if /bin/rpm -q whitebox-release >/dev/null 2>&1; then
133                         DISTRO_MAJOR=WhiteBox
134                         RELEASE_FILE=/etc/whitebox-release
135                 fi
136                 if /bin/rpm -q fedora-release >/dev/null 2>&1; then
137                         DISTRO_MAJOR=RedHat
138                         DISTRO_MINOR=Fedora
139                         RELEASE_FILE=/etc/fedora-release
140                 fi
141                 # Then look for specific version
142                 ( cat $RELEASE_FILE | grep Enterprise ) >/dev/null 2>&1 && \
143                         DISTRO_MINOR=Enterprise
144                 DISTRO_VERSION=`tr -cd "[^0-9.]" < $RELEASE_FILE | cut -c 1`
145         fi
146
147         # Check for Gentoo
148         if [ -f /etc/gentoo-release ]; then
149                 DISTRO_MAJOR=Gentoo
150         fi
151
152         # Check for Debian
153         # TODO: check for Debian
154 }
155
156 install_ical () {
157         cd $BUILD 2>&1 >>$LOG || die
158         $WGET $DOWNLOAD_SITE/libical-easyinstall.sum
159         SUM=`cat libical-easyinstall.sum`
160         SUMFILE=$SUPPORT/etc/libical-easyinstall.sum
161         if [ -r $SUMFILE ] ; then
162                 OLDSUM=`cat $SUMFILE`
163                 if [ $SUM = $OLDSUM ] ; then
164                         echo "* libical does not need updating."
165                         return
166                 fi
167         fi
168         echo "* Downloading libical..."
169         $WGET $DOWNLOAD_SITE/$ICAL_SOURCE 2>&1 >>$LOG || die
170         echo "* Installing libical..."
171         ( gzip -dc $ICAL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
172         cd $BUILD/libical-0.24 2>&1 >>$LOG || die
173         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
174         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
175         $MAKE install 2>&1 >>$LOG || die
176         echo "  Complete."
177         echo $SUM >$SUMFILE
178         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
179         rm -f $WEBCIT/webcit-easyinstall.sum 2>/dev/null
180 }
181
182 install_db () {
183         cd $BUILD 2>&1 >>$LOG || die
184         $WGET $DOWNLOAD_SITE/db-easyinstall.sum
185         SUM=`cat db-easyinstall.sum`
186         SUMFILE=$SUPPORT/etc/db-easyinstall.sum
187         if [ -r $SUMFILE ] ; then
188                 OLDSUM=`cat $SUMFILE`
189                 if [ $SUM = $OLDSUM ] ; then
190                         echo "* Berkeley DB does not need updating."
191                         return
192                 fi
193         fi
194         echo "* Downloading Berkeley DB..."
195         $WGET $DOWNLOAD_SITE/$DB_SOURCE 2>&1 >>$LOG || die
196         echo "* Installing Berkeley DB..."
197         ( gzip -dc $DB_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
198         cd $BUILD/db-4.3.21.NC 2>&1 >>$LOG || die
199         #patch -p0 < ../$DB_PATCHES 2>&1 >>$LOG || die
200         cd $BUILD/db-4.3.21.NC/build_unix 2>&1 >>$LOG || die
201         ../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
202         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
203         $MAKE install 2>&1 >>$LOG || die
204         echo "  Complete."
205         echo $SUM >$SUMFILE
206         rm -f $CITADEL/citadel-easyinstall.sum 2>/dev/null
207 }
208
209 install_prerequisites () {
210
211         # Create the support directories if they don't already exist
212
213         mkdir $SUPPORT          2>/dev/null
214         mkdir $SUPPORT/bin      2>/dev/null
215         mkdir $SUPPORT/sbin     2>/dev/null
216         mkdir $SUPPORT/lib      2>/dev/null
217         mkdir $SUPPORT/libexec  2>/dev/null
218         mkdir $SUPPORT/include  2>/dev/null
219         mkdir $SUPPORT/etc      2>/dev/null
220
221         # Now have phun!
222
223         if [ -z "$OK_ICAL" ]
224         then
225                 install_ical
226         fi
227         if [ -z "$OK_DB" ]
228         then
229                 install_db
230         fi
231 }
232
233 install_sources () {
234         cd $BUILD 2>&1 >>$LOG || die
235         if [ -f $CITADEL/citadel.config ]
236         then
237                 IS_UPGRADE=yes
238                 echo "* Upgrading your existing Citadel installation."
239         else
240                 IS_UPGRADE=no
241         fi
242
243         CFLAGS="-I${SUPPORT}/include"
244         CPPFLAGS="${CFLAGS}"
245         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
246         export CFLAGS CPPFLAGS LDFLAGS
247
248         DO_INSTALL_CITADEL=yes
249         $WGET $DOWNLOAD_SITE/citadel-easyinstall.sum
250         SUM=`cat citadel-easyinstall.sum`
251         SUMFILE=$CITADEL/citadel-easyinstall.sum
252         if [ -r $SUMFILE ] ; then
253                 OLDSUM=`cat $SUMFILE`
254                 if [ $SUM = $OLDSUM ] ; then
255                         echo "* Citadel does not need updating."
256                         DO_INSTALL_CITADEL=no
257                 fi
258         fi
259
260         if [ $DO_INSTALL_CITADEL = yes ] ; then
261                 echo "* Downloading Citadel..."
262                 $WGET $DOWNLOAD_SITE/$CITADEL_SOURCE 2>&1 >>$LOG || die
263                 echo "* Installing Citadel..."
264                 cd $BUILD 2>&1 >>$LOG || die
265                 ( gzip -dc $CITADEL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
266                 cd $BUILD/citadel 2>&1 >>$LOG || die
267                 if [ -z "$OK_DB" ]
268                 then
269                         ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --enable-autologin --with-libical --disable-threaded-client 2>&1 >>$LOG || die
270                 else
271                         ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --enable-autologin --with-libical --disable-threaded-client 2>&1 >>$LOG || die
272                 fi
273                 $MAKE $MAKEOPTS 2>&1 >>$LOG || die
274                 if [ $IS_UPGRADE = yes ]
275                 then
276                         echo "* Performing Citadel upgrade..."
277                         $MAKE upgrade 2>&1 >>$LOG || die
278                 else
279                         echo "* Performing Citadel install..."
280                         $MAKE install 2>&1 >>$LOG || die
281                         useradd -c "Citadel service account" -d $CITADEL -s $CITADEL/citadel citadel 2>&1 >>$LOG
282                 fi
283                 echo $SUM >$SUMFILE
284         fi
285
286         cd $BUILD 2>&1 >>$LOG || die
287         DO_INSTALL_WEBCIT=yes
288         $WGET $DOWNLOAD_SITE/webcit-easyinstall.sum
289         SUM=`cat webcit-easyinstall.sum`
290         SUMFILE=$WEBCIT/webcit-easyinstall.sum
291         if [ -r $SUMFILE ] ; then
292                 OLDSUM=`cat $SUMFILE`
293                 if [ $SUM = $OLDSUM ] ; then
294                         echo "* WebCit does not need updating."
295                         DO_INSTALL_WEBCIT=no
296                 fi
297         fi
298
299         if [ $DO_INSTALL_WEBCIT = yes ] ; then
300                 echo "* Downloading WebCit..."
301                 $WGET $DOWNLOAD_SITE/$WEBCIT_SOURCE 2>&1 >>$LOG || die
302                 echo "* Installing WebCit..."
303                 cd $BUILD 2>&1 >>$LOG || die
304                 ( gzip -dc $WEBCIT_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
305                 cd $BUILD/webcit 2>&1 >>$LOG || die
306                 ./configure --prefix=$WEBCIT --with-libical 2>&1 >>$LOG || die
307                 $MAKE $MAKEOPTS 2>&1 >>$LOG || die
308                 $MAKE install 2>&1 >>$LOG || die
309                 echo "  Complete."
310                 echo $SUM >$SUMFILE
311         fi
312 }
313
314
315 do_config () {
316         echo "* Configuring your system ..."
317
318         if [ x$IS_UPGRADE == xyes ] ; then
319                 echo Upgrading your existing Citadel installation.
320                 #$CITADEL/setup -q || die
321                 $CITADEL/setup </dev/tty || die
322         else
323                 echo This is a new Citadel installation.
324                 $CITADEL/setup </dev/tty || die
325         fi
326
327         $WEBCIT/setup </dev/tty || die
328 }
329
330
331
332 ##### END Functions #####
333
334 ##### BEGIN main #####
335
336 # 1. Gather information about the target system
337
338 # FIXME: non-GNU make does not work
339
340 gmake -v || {
341         echo
342         echo 'Easy Install requires GNU Make (gmake), which was not found.'
343         echo 'Please install gmake and try again.'
344         echo
345         exit 1
346 }
347 MAKE=`which gmake`
348 export MAKE
349
350 clear
351
352 os=`uname`
353
354 #[ -n "$WGET" ] && [ -x `which wget` ] && WGET=`which wget`
355 #[ -z "$WGET" ] && [ -x `which curl` ] && WGET=`which curl`\ -O
356
357 [ -n "$WGET" ] && [ -x `which curl` ] && WGET=`which curl`\ -O
358 [ -z "$WGET" ] && [ -x `which wget` ] && WGET=`which wget`
359
360 echo MAKE is $MAKE
361 echo WGET is $WGET 
362 export MAKE WGET
363
364 # 1A. Do we use the native packaging system or build our own copy of Citadel?
365
366 if [ "$os" = "Linux" ]; then
367         determine_distribution
368 elif [ "$os" = "FreeBSD" ]; then
369         # TODO: We detect FreeBSD but the port is still out of date...
370         DISTRO_MAJOR=FreeBSD
371 elif [ "$os" = "Darwin" ]; then
372         # TODO: Deal with Apple weirdness
373         DISTRO_MAJOR=Darwin
374 fi
375
376
377 rm -rf $BUILD
378 mkdir -p $BUILD
379 cd $BUILD
380
381
382 # 2. Present the installation steps (from 1 above) to the user
383 clear
384 if dialog --clear </dev/tty ; then
385         CTDL_DIALOG=`which dialog`
386         export CTDL_DIALOG
387 fi
388 clear
389
390 echo "$SETUP will perform the following actions:"
391 echo ""
392 echo "Installation:"
393 echo "* Download/install supporting libraries (if needed)"
394 echo "* Download/install Citadel (if needed)"
395 echo "* Download/install WebCit (if needed)"
396 echo ""
397 echo "Configuration:"
398 echo "* Configure Citadel"
399 echo "* Configure WebCit"
400 echo ""
401 echo -n "Perform the above installation steps now? "
402 read yesno </dev/tty
403
404 if [ "`echo $yesno | cut -c 1 | tr N n`" = "n" ]; then
405         exit 2
406 fi
407
408 echo ""
409 echo "Command output will not be sent to the terminal."
410 echo "To view progress, see the $LOG file."
411 echo ""
412
413 # 3. Present any pre-install customizations to the user
414
415 # TODO: enter in the configuration dialogs
416
417 # Configure Citadel
418
419 # Configure WebCit
420
421 # 4. Do the installation
422
423 # 4A. Download any source code files or binary packages required
424
425 if [ "$prepackaged" ]; then
426         download_packages
427
428 # 4B. For native packaging, call the native packaging system to install
429
430         install_packages
431 else
432
433 # 4C. If we build our own, compile and install prerequisites then Citadel
434
435         install_prerequisites
436         install_sources
437 fi
438
439 # 5. Do post-installation setup
440         rm -fr $BUILD
441         do_config
442 ##### END main #####