]> code.citadel.org Git - citadel.git/blob - citadel/newinstall.sh
* newinstall.sh: various tweaks to make it more reliable
[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 # 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 BUILD=/tmp/citadel-build.$$
73 export SUPPORT CITADEL WEBCIT
74
75 # Change the number of jobs to one plus the number of CPUs for best
76 # performance when compiling software.
77 MAKEOPTS="-j2"
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 # SUPPORT               Directory where support programs are installed
85 # LDAP_CONFIG           Location of the slapd.conf file
86 # DISTRO_MAJOR          Linux distribution name, if applicable
87 # DISTRO_MINOR          Linux distribution name, if applicable
88 # DISTRO_VERSION        Linux distribution version (major digit) if applicable
89 # CC                    C compiler being used
90 # MAKE                  Make program being used
91 # CFLAGS                C compiler flags
92 # LDFLAGS               Linker flags
93
94 # Let Citadel setup recognize the Citadel installer
95 CITADEL_INSTALLER=web
96 export CITADEL_INSTALLER
97
98 DOWNLOAD_SITE=http://my.citadel.org/download
99
100 # Original source code packages.
101 DB_SOURCE=db-4.1.25.tar.gz
102 DB_PATCHES=db-4.1.25.patches
103 ICAL_SOURCE=libical-0.24.RC4.tar.gz
104 LDAP_SOURCE=openldap-stable-20040329.tgz
105 CITADEL_SOURCE=citadel-6.24.tar.gz
106 WEBCIT_SOURCE=webcit-5.22.tar.gz
107
108 SETUP="Citadel Easy Install"
109
110 LOG=$BUILD/log.txt
111
112 ##### BEGIN Functions #####
113
114 die () {
115         echo Easy Install is aborting.
116         echo Please report this problem to the Citadel developers.
117         rm -fr $BUILD
118         exit 1
119 }
120
121
122 determine_distribution () {
123         # First look for Red Hat in general
124         if [ -x /bin/rpm ]; then
125                 RELEASE_FILE=/dev/null
126                 if /bin/rpm -q redhat-release >/dev/null 2>&1; then
127                         DISTRO_MAJOR=RedHat
128                         RELEASE_FILE=/etc/redhat-release
129                 fi
130                 if /bin/rpm -q whitebox-release >/dev/null 2>&1; then
131                         DISTRO_MAJOR=WhiteBox
132                         RELEASE_FILE=/etc/whitebox-release
133                 fi
134                 if /bin/rpm -q fedora-release >/dev/null 2>&1; then
135                         DISTRO_MAJOR=RedHat
136                         DISTRO_MINOR=Fedora
137                         RELEASE_FILE=/etc/fedora-release
138                 fi
139                 # Then look for specific version
140                 ( cat $RELEASE_FILE | grep Enterprise ) >/dev/null 2>&1 && \
141                         DISTRO_MINOR=Enterprise
142                 DISTRO_VERSION=`tr -cd "[^0-9.]" < $RELEASE_FILE | cut -c 1`
143         fi
144
145         # Check for Gentoo
146         if [ -f /etc/gentoo-release ]; then
147                 DISTRO_MAJOR=Gentoo
148         fi
149
150         # Check for Debian
151         # TODO: check for Debian
152 }
153
154 download_sources () {
155         echo "* Downloading Berkeley DB..."
156         wget -c $DOWNLOAD_SITE/$DB_SOURCE 2>&1 >>$LOG || die
157         echo "* Downloading libical..."
158         wget -c $DOWNLOAD_SITE/$ICAL_SOURCE 2>&1 >>$LOG || die
159         echo "* Downloading OpenLDAP..."
160         wget -c $DOWNLOAD_SITE/$LDAP_SOURCE 2>&1 >>$LOG || die
161         echo "* Downloading Citadel..."
162         wget -c $DOWNLOAD_SITE/$CITADEL_SOURCE 2>&1 >>$LOG || die
163         echo "* Downloading WebCit..."
164         wget -c $DOWNLOAD_SITE/$WEBCIT_SOURCE 2>&1 >>$LOG || die
165 }
166
167 install_ical () {
168         echo "* Installing libical..."
169         cd $BUILD 2>&1 >>$LOG || die
170         ( gzip -dc $ICAL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
171         cd $BUILD/libical-0.24 2>&1 >>$LOG || die
172         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
173         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
174         $MAKE install 2>&1 >>$LOG || die
175         echo "  Complete."
176 }
177
178 install_db () {
179         echo "* Installing Berkeley DB..."
180         cd $BUILD 2>&1 >>$LOG || die
181         ( gzip -dc $DB_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
182         cd $BUILD/db-4.1.25 2>&1 >>$LOG || die
183         #patch -p0 < ../$DB_PATCHES 2>&1 >>$LOG || die
184         cd $BUILD/db-4.1.25/build_unix 2>&1 >>$LOG || die
185         ../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
186         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
187         $MAKE install 2>&1 >>$LOG || die
188         echo "  Complete."
189 }
190
191 install_ldap () {
192         echo "* Installing OpenLDAP..."
193         CFLAGS="${CFLAGS} -I${SUPPORT}/include"
194         CPPFLAGS="${CFLAGS}"
195         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
196         export CFLAGS CPPFLAGS LDFLAGS
197         cd $BUILD 2>&1 >>$LOG || die
198         ( gzip -dc $LDAP_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
199         cd $BUILD/openldap-2.1.29 2>&1 >>$LOG || die
200         ./configure --prefix=$SUPPORT --enable-bdb 2>&1 >>$LOG || die
201         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
202         LDAP_CONFIG=$SUPPORT/etc/openldap/slapd.conf
203         export LDAP_CONFIG
204         $MAKE install 2>&1 >>$LOG || die
205         echo "  Complete."
206 }
207
208 install_prerequisites () {
209
210         # Create the support directories if they don't already exist
211
212         mkdir $SUPPORT          2>/dev/null
213         mkdir $SUPPORT/bin      2>/dev/null
214         mkdir $SUPPORT/sbin     2>/dev/null
215         mkdir $SUPPORT/lib      2>/dev/null
216         mkdir $SUPPORT/libexec  2>/dev/null
217         mkdir $SUPPORT/include  2>/dev/null
218         mkdir $SUPPORT/etc      2>/dev/null
219
220         # Now have phun!
221
222         if [ -z "$OK_ICAL" ]
223         then
224                 install_ical
225         fi
226         if [ -z "$OK_DB" ]
227         then
228                 install_db
229         fi
230         if [ -z "$OK_LDAP" ]
231         then
232                 install_ldap
233         fi
234 }
235
236 install_sources () {
237         echo "* Installing Citadel..."
238
239         CFLAGS="${CFLAGS} -I${SUPPORT}/include"
240         CPPFLAGS="${CFLAGS}"
241         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
242         export CFLAGS CPPFLAGS LDFLAGS
243
244         cd $BUILD 2>&1 >>$LOG || die
245         ( gzip -dc $CITADEL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
246         cd $BUILD/citadel 2>&1 >>$LOG || die
247         if [ -z "$OK_DB" ]
248         then
249                 ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
250         else
251                 ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
252         fi
253         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
254         if [ -f $CITADEL/citadel.config ]
255         then
256                 $MAKE upgrade 2>&1 >>$LOG || die
257                 $CITADEL/setup -q
258         else
259                 $MAKE install 2>&1 >>$LOG || die
260                 useradd -c Citadel -s /bin/false -r -d $CITADEL citadel 2>&1 >>$LOG || die
261                 $CITADEL/setup
262         fi
263
264         echo "* Installing WebCit..."
265         cd $BUILD 2>&1 >>$LOG || die
266         ( gzip -dc $WEBCIT_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
267         cd $BUILD/webcit 2>&1 >>$LOG || die
268         ./configure --prefix=$WEBCIT --with-libical 2>&1 >>$LOG || die
269         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
270         $MAKE install 2>&1 >>$LOG || die
271         echo "  Complete."
272 }
273
274 ##### END Functions #####
275
276 ##### BEGIN main #####
277
278 # 1. Gather information about the target system
279
280 [ x$MAKE == x ] && MAKE=`which gmake`
281 [ x$MAKE == x ] && MAKE=`which make`
282 clear
283
284 os=`uname`
285
286 # 1A. Do we use the native packaging system or build our own copy of Citadel?
287
288 if [ "$os" = "Linux" ]; then
289         determine_distribution
290 elif [ "$os" = "FreeBSD" ]; then
291         # TODO: We detect FreeBSD but the port is still out of date...
292         DISTRO_MAJOR=FreeBSD
293 fi
294
295 # 2. Present the installation steps (from 1 above) to the user
296
297 echo "$SETUP will perform the following actions:"
298 echo ""
299 echo "Configuration:"
300 echo "* Configure Citadel"
301 echo "* Configure WebCit"
302 echo ""
303 echo "Installation:"
304
305 if [ "$prepackaged" ]; then
306         show_packages_to_install
307 else
308         echo "* Install supporting libraries"
309         echo "* Install Citadel"
310         echo "* Install WebCit"
311 fi
312
313 echo ""
314 echo -n "Perform the above installation steps now? (yes) "
315
316 read junk
317 if [ "`echo $junk | cut -c 1 | tr N n`" = "n" ]; then
318         exit 2
319 fi
320
321 rm -rf $BUILD
322 mkdir -p $BUILD
323 cd $BUILD
324
325 echo ""
326 echo "Command output will not be sent to the terminal."
327 echo "To view progress, see the $LOG file."
328 echo ""
329
330 # 3. Present any pre-install customizations to the user
331
332 # TODO: enter in the configuration dialogs
333
334 # Configure Citadel
335
336 # Configure WebCit
337
338 # 4. Do the installation
339
340 # 4A. Download any source code files or binary packages required
341
342 if [ "$prepackaged" ]; then
343         download_packages
344
345 # 4B. For native packaging, call the native packaging system to install
346
347         install_packages
348 else
349
350 # 4C. If we build our own, compile and install prerequisites then Citadel
351
352         download_sources
353         install_prerequisites
354         install_sources
355 fi
356
357 # 5. Do post-installation setup
358         cd $CITADEL
359         ./setup || die
360
361         cd $WEBCIT
362         ./setup || die
363
364         rm -fr $BUILD
365 ##### END main #####