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