]> code.citadel.org Git - citadel.git/blob - citadel/newinstall.sh
* Generalize some of the inittab-tweaking stuff so that we can use it
[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 I 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.24                    Latest
40 # WebCit       5.22                    Latest
41 # libical      0.24.RC4                Latest
42 # Berkeley DB  4.1.25 + 2 patches      Stable
43 # OpenLDAP     2.1.30 stable-20040329  Stable
44
45
46 ###############################################################################
47 #
48 # This is the general stuff we're going to do, in order:
49 #
50 # 1. Gather information about the target system
51 # 2. Present the installation steps (from 1 above) to the user
52 # 3. Present any pre-install customizations to the user
53 # 4. Do the installation
54 #    A. Download any source code files or binary packages required
55 #    B. For native packaging, call the native packaging system to install
56 #    C. If we build our own, compile and install prerequisites then Citadel
57 # 5. Do post-installation setup
58 #
59 # Then call it a day.
60 #
61 ###############################################################################
62
63
64 # Begin user customization area
65 #
66 # These two directories specify where Citadel and its private support
67 # libraries will be installed.  This keeps them safely tucked away from
68 # the rest of your system.  The defaults should be fine for most people.
69 # NB: When binary packages are installed, these settings are ignored!
70 SUPPORT=/usr/local/ctdlsupport
71 CITADEL=/usr/local/citadel
72 WEBCIT=/usr/local/webcit
73 BUILD=/tmp/citadel-build.$$
74 export SUPPORT CITADEL WEBCIT
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 # WEBCIT                Directory where WebCit is installed
86 # SUPPORT               Directory where support programs are installed
87 # LDAP_CONFIG           Location of the slapd.conf file
88 # SLAPD_BINARY          Location of the slapd binary
89 # DISTRO_MAJOR          Linux distribution name, if applicable
90 # DISTRO_MINOR          Linux distribution name, if applicable
91 # DISTRO_VERSION        Linux distribution version (major digit) if applicable
92 # CC                    C compiler being used
93 # MAKE                  Make program being used
94 # CFLAGS                C compiler flags
95 # LDFLAGS               Linker flags
96 # IS_UPGRADE            Set to "yes" if upgrading an existing Citadel
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.1.25.tar.gz
106 DB_PATCHES=db-4.1.25.patches
107 ICAL_SOURCE=libical-0.24.RC4.tar.gz
108 LDAP_SOURCE=openldap-stable-20040329.tgz
109 CITADEL_SOURCE=citadel-easyinstall.tar.gz
110 WEBCIT_SOURCE=webcit-5.22.tar.gz
111
112 SETUP="Citadel Easy Install"
113
114 LOG=$BUILD/log.txt
115
116 ##### BEGIN Functions #####
117
118 die () {
119         echo Easy Install is aborting.
120         echo Please report this problem to the Citadel developers.
121         rm -fr $BUILD
122         exit 1
123 }
124
125
126 determine_distribution () {
127         # First look for Red Hat in general
128         if [ -x /bin/rpm ]; then
129                 RELEASE_FILE=/dev/null
130                 if /bin/rpm -q redhat-release >/dev/null 2>&1; then
131                         DISTRO_MAJOR=RedHat
132                         RELEASE_FILE=/etc/redhat-release
133                 fi
134                 if /bin/rpm -q whitebox-release >/dev/null 2>&1; then
135                         DISTRO_MAJOR=WhiteBox
136                         RELEASE_FILE=/etc/whitebox-release
137                 fi
138                 if /bin/rpm -q fedora-release >/dev/null 2>&1; then
139                         DISTRO_MAJOR=RedHat
140                         DISTRO_MINOR=Fedora
141                         RELEASE_FILE=/etc/fedora-release
142                 fi
143                 # Then look for specific version
144                 ( cat $RELEASE_FILE | grep Enterprise ) >/dev/null 2>&1 && \
145                         DISTRO_MINOR=Enterprise
146                 DISTRO_VERSION=`tr -cd "[^0-9.]" < $RELEASE_FILE | cut -c 1`
147         fi
148
149         # Check for Gentoo
150         if [ -f /etc/gentoo-release ]; then
151                 DISTRO_MAJOR=Gentoo
152         fi
153
154         # Check for Debian
155         # TODO: check for Debian
156 }
157
158 download_sources () {
159         echo "* Downloading Berkeley DB..."
160         wget -c $DOWNLOAD_SITE/$DB_SOURCE 2>&1 >>$LOG || die
161         echo "* Downloading libical..."
162         wget -c $DOWNLOAD_SITE/$ICAL_SOURCE 2>&1 >>$LOG || die
163         echo "* Downloading OpenLDAP..."
164         wget -c $DOWNLOAD_SITE/$LDAP_SOURCE 2>&1 >>$LOG || die
165         echo "* Downloading Citadel..."
166         wget -c $DOWNLOAD_SITE/$CITADEL_SOURCE 2>&1 >>$LOG || die
167         echo "* Downloading WebCit..."
168         wget -c $DOWNLOAD_SITE/$WEBCIT_SOURCE 2>&1 >>$LOG || die
169 }
170
171 install_ical () {
172         echo "* Installing libical..."
173         cd $BUILD 2>&1 >>$LOG || die
174         ( gzip -dc $ICAL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
175         cd $BUILD/libical-0.24 2>&1 >>$LOG || die
176         ./configure --prefix=$SUPPORT 2>&1 >>$LOG || die
177         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
178         $MAKE install 2>&1 >>$LOG || die
179         echo "  Complete."
180 }
181
182 install_db () {
183         echo "* Installing Berkeley DB..."
184         cd $BUILD 2>&1 >>$LOG || die
185         ( gzip -dc $DB_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
186         cd $BUILD/db-4.1.25 2>&1 >>$LOG || die
187         #patch -p0 < ../$DB_PATCHES 2>&1 >>$LOG || die
188         cd $BUILD/db-4.1.25/build_unix 2>&1 >>$LOG || die
189         ../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
190         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
191         $MAKE install 2>&1 >>$LOG || die
192         echo "  Complete."
193 }
194
195 install_ldap () {
196         echo "* Installing OpenLDAP..."
197         CFLAGS="${CFLAGS} -I${SUPPORT}/include"
198         CPPFLAGS="${CFLAGS}"
199         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
200         export CFLAGS CPPFLAGS LDFLAGS
201         cd $BUILD 2>&1 >>$LOG || die
202         ( gzip -dc $LDAP_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
203         cd $BUILD/openldap-2.1.29 2>&1 >>$LOG || die
204         ./configure --prefix=$SUPPORT --enable-bdb 2>&1 >>$LOG || die
205         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
206         LDAP_CONFIG=$SUPPORT/etc/openldap/slapd.conf
207         export LDAP_CONFIG
208         SLAPD_BINARY=$SUPPORT/libexec/slapd
209         export SLAPD_BINARY
210         $MAKE install 2>&1 >>$LOG || die
211         echo "  Complete."
212 }
213
214 install_prerequisites () {
215
216         # Create the support directories if they don't already exist
217
218         mkdir $SUPPORT          2>/dev/null
219         mkdir $SUPPORT/bin      2>/dev/null
220         mkdir $SUPPORT/sbin     2>/dev/null
221         mkdir $SUPPORT/lib      2>/dev/null
222         mkdir $SUPPORT/libexec  2>/dev/null
223         mkdir $SUPPORT/include  2>/dev/null
224         mkdir $SUPPORT/etc      2>/dev/null
225
226         # Now have phun!
227
228         if [ -z "$OK_ICAL" ]
229         then
230                 install_ical
231         fi
232         if [ -z "$OK_DB" ]
233         then
234                 install_db
235         fi
236         if [ -z "$OK_LDAP" ]
237         then
238                 install_ldap
239         fi
240 }
241
242 install_sources () {
243         echo "* Installing Citadel..."
244
245         CFLAGS="${CFLAGS} -I${SUPPORT}/include"
246         CPPFLAGS="${CFLAGS}"
247         LDFLAGS="-L${SUPPORT}/lib -Wl,--rpath -Wl,${SUPPORT}/lib"
248         export CFLAGS CPPFLAGS LDFLAGS
249
250         cd $BUILD 2>&1 >>$LOG || die
251         ( gzip -dc $CITADEL_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
252         cd $BUILD/citadel 2>&1 >>$LOG || die
253         if [ -z "$OK_DB" ]
254         then
255                 ./configure --prefix=$CITADEL --with-db=$SUPPORT --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
256         else
257                 ./configure --prefix=$CITADEL --with-db=$OK_DB --with-pam --enable-autologin --with-ldap --with-libical --disable-threaded-client 2>&1 >>$LOG || die
258         fi
259         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
260         if [ -f $CITADEL/citadel.config ]
261         then
262                 $MAKE upgrade 2>&1 >>$LOG || die
263                 IS_UPGRADE=yes
264         else
265                 $MAKE install 2>&1 >>$LOG || die
266                 useradd -c "Citadel service account" -b $CITADEL -s /bin/false -r -d $CITADEL citadel 2>&1 >>$LOG
267         fi
268
269         echo "* Installing WebCit..."
270         cd $BUILD 2>&1 >>$LOG || die
271         ( gzip -dc $WEBCIT_SOURCE | tar -xvf - ) 2>&1 >>$LOG || die
272         cd $BUILD/webcit 2>&1 >>$LOG || die
273         ./configure --prefix=$WEBCIT --with-libical 2>&1 >>$LOG || die
274         $MAKE $MAKEOPTS 2>&1 >>$LOG || die
275         $MAKE install 2>&1 >>$LOG || die
276         echo "  Complete."
277 }
278
279
280 do_config () {
281         echo "* Configuring your system ..."
282
283         if [ x$IS_UPGRADE == xyes ] ; then
284                 echo Upgrading your existing Citadel installation.
285                 #$CITADEL/setup -q || die
286                 $CITADEL/setup || die
287         else
288                 echo This is a new Citadel installation.
289                 $CITADEL/setup || die
290         fi
291
292         $WEBCIT/setup || die
293 }
294
295
296
297 ##### END Functions #####
298
299 ##### BEGIN main #####
300
301 # 1. Gather information about the target system
302
303 [ x$MAKE == x ] && MAKE=`which gmake`
304 [ x$MAKE == x ] && MAKE=`which make`
305 clear
306
307 os=`uname`
308
309 # 1A. Do we use the native packaging system or build our own copy of Citadel?
310
311 if [ "$os" = "Linux" ]; then
312         determine_distribution
313 elif [ "$os" = "FreeBSD" ]; then
314         # TODO: We detect FreeBSD but the port is still out of date...
315         DISTRO_MAJOR=FreeBSD
316 fi
317
318 # 2. Present the installation steps (from 1 above) to the user
319
320 echo "$SETUP will perform the following actions:"
321 echo ""
322 echo "Configuration:"
323 echo "* Configure Citadel"
324 echo "* Configure WebCit"
325 echo ""
326 echo "Installation:"
327
328 if [ "$prepackaged" ]; then
329         show_packages_to_install
330 else
331         echo "* Install supporting libraries"
332         echo "* Install Citadel"
333         echo "* Install WebCit"
334 fi
335
336 echo ""
337 echo -n "Perform the above installation steps now? (yes) "
338
339 read junk </dev/tty
340 if [ "`echo $junk | cut -c 1 | tr N n`" = "n" ]; then
341         exit 2
342 fi
343
344 rm -rf $BUILD
345 mkdir -p $BUILD
346 cd $BUILD
347
348 echo ""
349 echo "Command output will not be sent to the terminal."
350 echo "To view progress, see the $LOG file."
351 echo ""
352
353 # 3. Present any pre-install customizations to the user
354
355 # TODO: enter in the configuration dialogs
356
357 # Configure Citadel
358
359 # Configure WebCit
360
361 # 4. Do the installation
362
363 # 4A. Download any source code files or binary packages required
364
365 if [ "$prepackaged" ]; then
366         download_packages
367
368 # 4B. For native packaging, call the native packaging system to install
369
370         install_packages
371 else
372
373 # 4C. If we build our own, compile and install prerequisites then Citadel
374
375         download_sources
376         install_prerequisites
377         install_sources
378 fi
379
380 # 5. Do post-installation setup
381         rm -fr $BUILD
382         do_config
383 ##### END main #####