]> 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 #
7 #   This program is free software; you can redistribute it and/or modify
8 #   it under the terms of the GNU General Public License as published by
9 #   the Free Software Foundation; either version 2 of the License, or
10 #   (at your option) any later version.
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 # wget -q -O - http://my.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 I 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      Version                 Status
38 # Citadel      6.24                    Latest
39 # WebCit       5.22                    Latest
40 # libical      0.24.RC4                Latest
41 # Berkeley DB  4.1.25 + 2 patches      Stable
42 # OpenLDAP     2.1.30 stable-20040329  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 #    A. Do we use the native packaging system or build our own copy of Citadel?
51 #    B. If we build our own, are its prerequisites present and usable?
52 # 2. Present the installation steps (from 1 above) to the user
53 # 3. Present any pre-install customizations to the user
54 # 4. Do the installation
55 #    A. Download any source code files or binary packages required
56 #    B. For native packaging, call the native packaging system to install
57 #    C. If we build our own, compile and install prerequisites then Citadel
58 # 5. Do post-installation setup
59 #
60 # Then call it a day.
61 #
62 ###############################################################################
63
64
65 # Begin user customization area
66 #
67 # These two directories specify where Citadel and its private support
68 # libraries will be installed.  This keeps them safely tucked away from
69 # the rest of your system.  The defaults should be fine for most people.
70 # NB: When binary packages are installed, these settings are ignored!
71 SUPPORT=/usr/local/ctdlsupport
72 CITADEL=/usr/local/citadel
73 BUILD=/tmp/citadel-build.$$
74 export SUPPORT CITADEL
75
76 # Change the number of jobs to one plus the number of CPUs for best
77 # performance when compiling software.
78 MAKEOPTS="-j2"
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 # SUPPORT               Directory where support programs are installed
86 # LDAP_CONFIG           Location of the slapd.conf file
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
95 # Let Citadel setup recognize the Citadel installer
96 CITADEL_INSTALLER=web
97 export CITADEL_INSTALLER
98
99 DOWNLOAD_SITE=http://my.citadel.org/download
100
101 # Original source code packages.
102 CITADEL_SOURCE=citadel-6.24.tar.gz
103 WEBCIT_SOURCE=webcit-5.22.tar.gz
104 DB_SOURCE=db-4.1.25.tar.gz
105 DB_PATCHES=db-4.1.25.patches
106 ICAL_SOURCE=libical-0.24.RC4.tar.gz
107 LDAP_SOURCE=openldap-stable-20040329.tgz
108
109 # Binary RPM package names.
110 # DB and LDAP are assumed to come with the distro
111 CITADEL_RPM=citadel-client-6.23-1.i386.rpm
112 CITDATA_RPM=citadel-data-6.23-1.i386.rpm
113 CITSERVER_RPM=citadel-server-6.23-1.i386.rpm
114 WEBCIT_RPM=webcit-5.22-1.i386.rpm
115 ICAL_RPM=libical-0.24.RC4-1.i386.rpm
116
117 # Source RPMs used for this build.
118 # These are for your reference only; the script doesn't use them.
119 CITADEL_SRC_RPM=$DOWNLOAD_SITE/SRPMS/citadel-6.23-1.src.rpm
120 WEBCIT_SRC_RPM=$DOWNLOAD_SITE/SRPMS/webcit-5.22-1.src.rpm
121 ICAL_SRC_RPM=$DOWNLOAD_SITE/SRPMS/libical-0.24.RC4-1.src.rpm
122
123 SETUP="Citadel Easy Install"
124
125 LOG=$BUILD/log.txt
126 CFLAGS="${CFLAGS} -I${SUPPORT}/include"
127 CPPFLAGS="${CFLAGS}"
128 LDFLAGS="-l${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
129 export CFLAGS CPPFLAGS LDFLAGS
130
131 ##### BEGIN Functions #####
132
133 die () {
134         echo Easy Install is aborting.
135         echo Please report this problem to the Citadel developers.
136         rm -fr $BUILD
137         exit 1
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 find_libical () {
174         for path in $SUPPORT /usr/local/ctdlsupport /usr/local /usr
175         do
176                 if [ -x $path/lib/libical.so.0.0.0 -a -f $path/include/ical.h ]
177                 then
178                         # Verify correct version
179                         if grep "define ICAL_VERSION" $path/include/ical.h | grep "0.24" >/dev/null
180                         then
181                                 OK_ICAL=$path
182                                 return
183                         else
184                                 echo "Warning: Wrong libical version found"
185                         fi
186                 fi
187         done
188 }
189
190 find_openldap () {
191         for path in $SUPPORT /usr/local/ctdlsupport /usr/local /usr
192         do
193                 if [ -x $path/libexec/slapd -o -x $path/lib/openldap/slapd -o -x $path/sbin/slapd ]
194                 then
195                         if [ -f $path/lib/libldap.so.2 -a -f $path/include/ldap.h ]
196                         then
197                                 OK_LDAP=$path
198                                 return
199                         fi
200                 fi
201         done
202 }
203
204 find_berkeley_db () {
205         for path in $SUPPORT /usr/local/ctdlsupport /usr/local/BerkeleyDB.4.1.25 /usr
206         do
207                 if [ -x $path/lib/libdb-4.1.so -a -f $path/include/db.h ]
208                 then
209                         OK_DB=$path
210                         return
211                 fi
212         done
213 }
214
215 show_prerequisites_to_install () {
216         if [ -z "$OK_ICAL" ]
217         then
218                 echo "* libical"
219         fi
220         if [ -z "$OK_DB" ]
221         then
222                 echo "* Berkeley DB"
223         fi
224         if [ -z "$OK_LDAP" ]
225         then
226                 echo "* OpenLDAP"
227         fi
228 }
229
230 download_prerequisite_sources () {
231         if [ -z "$OK_ICAL" ]
232         then
233                 echo "* Downloading libical..."
234                 wget -c $DOWNLOAD_SITE/$ICAL_SOURCE 2>&1 >>$LOG || die
235         fi
236         if [ -z "$OK_DB" ]
237         then
238                 echo "* Downloading Berkeley DB..."
239                 wget -c $DOWNLOAD_SITE/$DB_SOURCE 2>&1 >>$LOG || die
240                 #wget -c $DOWNLOAD_SITE/$DB_PATCHES 2>&1 >>$LOG || die
241         fi
242         if [ -z "$OK_LDAP" ]
243         then
244                 echo "* Downloading OpenLDAP..."
245                 wget -c $DOWNLOAD_SITE/$LDAP_SOURCE 2>&1 >>$LOG || die
246         fi
247 }
248
249 download_sources () {
250         echo "* Downloading Citadel..."
251         wget -c $DOWNLOAD_SITE/$CITADEL_SOURCE 2>&1 >>$LOG || die
252         echo "* Downloading WebCit..."
253         wget -c $DOWNLOAD_SITE/$WEBCIT_SOURCE 2>&1 >>$LOG || die
254 }
255
256 install_ical () {
257         echo "* Installing libical..."
258         cd $BUILD 2>&1 >>$LOG || die
259         ( gzip -dc $ICAL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
260         cd $BUILD/libical-0.24 2>&1 >>$LOG || die
261         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
262         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
263         $MAKE install 2>&1 >>$LOG || die
264         echo "  Complete."
265 }
266
267 install_db () {
268         echo "* Installing Berkeley DB..."
269         cd $BUILD 2>&1 >>$LOG || die
270         ( gzip -dc $DB_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
271         cd $BUILD/db-4.1.25 2>&1 >>$LOG || die
272         #patch -p0 < ../$DB_PATCHES 2>&1 >>$LOG || die
273         cd $BUILD/db-4.1.25/build_unix 2>&1 >>$LOG || die
274         ../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
275         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
276         $MAKE install 2>&1 >>$LOG || die
277         echo "  Complete."
278 }
279
280 install_ldap () {
281         echo "* Installing OpenLDAP..."
282         cd $BUILD 2>&1 >>$LOG || die
283         ( gzip -dc $LDAP_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
284         cd $BUILD/openldap-2.1.29 2>&1 >>$LOG || die
285         ./configure --prefix=$SUPPORT --enable-crypt --enable-lmpasswd 2>&1 >>$LOG || die
286         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
287         LDAP_CONFIG=$SUPPORT/etc/openldap/slapd.conf
288         export LDAP_CONFIG
289         $MAKE install 2>&1 >>$LOG || die
290         echo "  Complete."
291 }
292
293 install_prerequisites () {
294         if [ -z "$OK_ICAL" ]
295         then
296                 install_ical
297         fi
298         if [ -z "$OK_DB" ]
299         then
300                 install_db
301         fi
302         if [ -z "$OK_LDAP" ]
303         then
304                 install_ldap
305         fi
306 }
307
308 install_sources () {
309         echo "* Installing Citadel..."
310         cd $BUILD 2>&1 >>$LOG || die
311         ( gzip -dc $CITADEL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
312         cd $BUILD/citadel 2>&1 >>$LOG || die
313         if [ -z "$OK_DB" ]
314         then
315                 ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
316         else
317                 ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
318         fi
319         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
320         if [ -f $CITADEL/citadel.config ]
321         then
322                 $MAKE upgrade 2>&1 >>$LOG || die
323                 $CITADEL/setup -q
324         else
325                 $MAKE install 2>&1 >>$LOG || die
326                 useradd -c Citadel -s /bin/false -r -d $CITADEL citadel 2>&1 >>$LOG || die
327                 $CITADEL/setup
328         fi
329
330         echo "* Installing WebCit..."
331         cd $BUILD 2>&1 >>$LOG || die
332         ( gzip -dc $WEBCIT_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
333         cd $BUILD/webcit 2>&1 >>$LOG || die
334         ./configure --prefix=$CITADEL --with-libical 2>&1 >>$LOG || die
335         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
336         $MAKE install 2>&1 >>$LOG || die
337         echo "  Complete."
338 }
339
340 ##### END Functions #####
341
342 ##### BEGIN main #####
343
344 # 1. Gather information about the target system
345
346 os=`uname`
347
348 # 1A. Do we use the native packaging system or build our own copy of Citadel?
349
350 if [ "$os" = "Linux" ]; then
351         determine_distribution
352 elif [ "$os" = "FreeBSD" ]; then
353         # TODO: We detect FreeBSD but the port is still out of date...
354         DISTRO_MAJOR=FreeBSD
355 fi
356
357 # 1B. If we build our own, are its prerequisites present and usable?
358
359 if [ -z "$prepackaged" ]; then
360         find_libical
361         find_openldap
362         find_berkeley_db
363 fi
364
365 # 2. Present the installation steps (from 1 above) to the user
366
367 echo "$SETUP will perform the following actions:"
368 echo ""
369 echo "Configuration:"
370 echo "* Configure Citadel"
371 echo "* Configure WebCit"
372 echo ""
373 echo "Installation:"
374
375 if [ "$prepackaged" ]; then
376         show_packages_to_install
377 else
378         show_prerequisites_to_install
379         echo "* Install Citadel"
380         echo "* Install WebCit"
381 fi
382
383 echo ""
384 echo -n "Perform the above installation steps now? (yes) "
385
386 read junk
387 if [ "`echo $junk | cut -c 1 | tr N n`" = "n" ]; then
388         exit 2
389 fi
390
391 rm -rf $BUILD
392 mkdir -p $BUILD
393 cd $BUILD
394
395 echo ""
396 echo "Command output will not be sent to the terminal."
397 echo "To view progress, see the $LOG file."
398 echo ""
399
400 # 3. Present any pre-install customizations to the user
401
402 # TODO: enter in the configuration dialogs
403
404 # Configure Citadel
405
406 # Configure WebCit
407
408 # 4. Do the installation
409
410 # 4A. Download any source code files or binary packages required
411
412 if [ "$prepackaged" ]; then
413         download_packages
414
415 # 4B. For native packaging, call the native packaging system to install
416
417         install_packages
418 else
419
420 # 4C. If we build our own, compile and install prerequisites then Citadel
421
422         download_prerequisite_sources
423         download_sources
424         
425         install_prerequisites
426         install_sources
427 fi
428
429 # 5. Do post-installation setup
430
431 ##### END main #####