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