]> git.evergreen-ils.org Git - Evergreen.git/blob - install.sh
broke build into three parts - config, build, and install
[Evergreen.git] / install.sh
1 #!/bin/bash
2 # --------------------------------------------------------------------
3 # Copyright (C) 2005  Georgia Public Library Service 
4 # Bill Erickson <highfalutin@gmail.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # --------------------------------------------------------------------
16
17
18 # --------------------------------------------------------------------
19 # ILS install script
20 # --------------------------------------------------------------------
21 CONFIG_FILE="install.conf";
22 DEFAULT_CONFIG_FILE="install.conf.default";
23
24
25 # --------------------------------------------------------------------
26 # Loads all of the path information from the user setting 
27 # install variables as it goes
28 # --------------------------------------------------------------------
29
30 function fail {
31         MSG="$1";
32         echo "A build error occured: $MSG";
33         exit 99;
34 }
35
36
37 function verifyInstallPaths {
38
39         cat <<-WORDS
40
41         -----------------------------------------------------------------------
42         Verify the following install directories are sane.
43         Note: * indicates that you must have write privelages for the location
44         -----------------------------------------------------------------------
45
46         -----------------------------------------------------------------------
47         Install prefix            [$PREFIX]*
48         Temporary files directory [$TMP]*
49         Apache2 apxs binary       [$APXS2]
50         Apache2 header directory  [$APACHE2_HEADERS]
51         Libxml2 header directory  [$LIBXML2_HEADERS]
52         Building targets          [${TARGETS[@]:0}];
53         -----------------------------------------------------------------------
54
55         If these are not OK, use control-c to break out and fix the variables 
56         in install.config.  Otherwise, type enter.
57
58         To disable this message, run "./install.sh force".
59
60         WORDS
61         read OK;
62 }
63
64 #function postMessage {
65
66 #cat <<-WORDS
67 #       --------------------------------------------------------------------
68
69
70 #}
71
72 # --------------------------------------------------------------------
73 # Makes sure the install directories exist and are writable
74 # --------------------------------------------------------------------
75 function mkInstallDirs {
76
77         if installing; then
78
79                 mkdir -p "$PREFIX";
80                 if [ "$?" != "0" ]; then
81                         fail "Error creating $PREFIX";
82                 fi
83
84                 if [ ! -w "$PREFIX" ]; then
85                         fail "We don't have write access to $PREFIX";
86                 fi
87
88         fi
89
90         if building; then
91
92                 mkdir -p "$TMP";
93                 if [ "$?" != "0" ]; then
94                         fail "Error creating $TMP";
95                 fi
96
97                 if [ ! -w "$TMP" ]; then
98                         fail "We don't have write access to $TMP";
99                 fi
100         fi
101
102         
103
104 }
105
106 function installing {
107         if [ -z "$INSTALLING" ]; then return 1; fi;
108         return 0;
109 }
110
111 function building {
112         if [ -z "$BUILDING" ]; then return 1; fi;
113         return 0;
114 }
115
116
117
118 # --------------------------------------------------------------------
119 # Loads the config file.  If it can't fine CONFIG_FILE, it attempts to
120 # use DEFAULT_CONFIG_FILE.  If it can't find that, it fails.
121 # --------------------------------------------------------------------
122 function loadConfig {
123         if [ ! -f "$CONFIG_FILE" ]; then
124                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
125                         echo "+ + + Copying $DEFAULT_CONFIG_FILE to $CONFIG_FILE and using its settings...";
126                         cp "$DEFAULT_CONFIG_FILE" "$CONFIG_FILE";
127                 else
128                         fail "config file \"$CONFIG_FILE\" cannot be found";
129                 fi
130         fi
131         source "$CONFIG_FILE";
132 }
133
134
135 function runInstall {
136
137
138         loadConfig;
139         #[ -z "$FORCE" ] && verifyInstallPaths;
140         mkInstallDirs;
141
142         # pass the collected variables to make
143         for target in ${TARGETS[@]:0}; do
144
145                 cat <<-MSG
146
147                 --------------------------------------------------------------------
148                 Building $target
149                 --------------------------------------------------------------------
150
151                 MSG
152
153                 MAKE="make APXS2=$APXS2 PREFIX=$PREFIX TMP=$TMP APACHE2_HEADERS=$APACHE2_HEADERS LIBXML2_HEADERS=$LIBXML2_HEADERS"; 
154
155                 echo "Passing to sub-makes: $VARS"
156                         
157                 case "$target" in
158                         
159                         "jserver" | "router" | "gateway" | "srfsh" ) 
160                                 if building; then $MAKE -C "$OPENSRF_DIR" "$target"; fi;
161                                 if installing; then $MAKE -C "$OPENSRF_DIR" "$target-install"; fi;
162                                 ;;
163
164                         *) fail "Unknown target: $target";;
165
166                 esac
167
168         done
169 }
170
171
172 # --------------------------------------------------------------------
173 # Checks command line parameters for special behavior
174 # Supported params are:
175 # clean - cleans all build files
176 # force - forces build without the initial message
177 # --------------------------------------------------------------------
178 function checkParams {
179
180         if [ -z "$1" ]; then return; fi;
181
182         for arg in "$@"; do
183
184                 lastArg="$arg";
185
186                 case "$arg" in
187
188                         "clean") 
189                                 cleanMe;;
190
191                         "force")
192                                 FORCE="1";;
193
194                         "build")
195                                 BUILDING="1";;
196
197                         "install")
198                                 INSTALLING="1";;
199
200                         *) fail "Unknown command line argument: $arg";;
201                 esac
202         done
203
204         if [ "$lastArg" = "clean" ]; then exit 0; fi;
205 }
206
207
208 function cleanMe {
209         loadConfig;
210         make -C "$OPENSRF_DIR" clean;
211         make -C "$OPENILS_DIR"  clean;
212         make -C "$EVERGREEN_DIR" clean;
213 }
214
215 checkParams "$@";
216
217 if installing; then echo "Installing..."; fi;
218
219 # Kick it off...
220 runInstall;
221
222
223