forward-porting default_config build option
[Evergreen.git] / config.sh
1 #!/bin/bash
2 # --------------------------------------------------------------------
3 # Copyright (C) 2005  Georgia Public Library Service 
4 # Bill Erickson <highfalutin@gmail.com>
5 # Mike Rylander <mrylander@gmail.com>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (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
18
19 # --------------------------------------------------------------------
20 # Prompts the user for config settings and writes a custom config
21 # file based on these settings
22 # --------------------------------------------------------------------
23
24
25 CONFIG_FILE="install.conf";
26 DEFAULT_CONFIG_FILE="install.conf.default";
27 USE_DEFAULT="$1";
28
29 function buildConfig {
30
31         if [ -f "$CONFIG_FILE" ]; then
32                 source "$CONFIG_FILE";
33         else
34                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
35                         source "$DEFAULT_CONFIG_FILE";
36                 fi;
37         fi;
38
39     if [ -n "$USE_DEFAULT" ]; then
40         prompt "Default config requested, not prompting for values...\n";
41         writeConfig;
42         return 0;
43     fi;
44
45
46         echo "";
47         echo "-----------------------------------------------------------------------";
48         echo "Type Enter to select the default"
49         echo "-----------------------------------------------------------------------";
50
51         prompt "Install prefix [$PREFIX] ";
52         read X; if [ ! -z "$X" ]; then PREFIX="$X"; fi
53
54         BINDIR="$PREFIX/bin/";
55         LIBDIR="$PREFIX/lib/";
56         PERLDIR="$LIBDIR/perl5/";
57         INCLUDEDIR="$PREFIX/include/";
58         ETCDIR="$PREFIX/conf";
59         WEBDIR="$PREFIX/var/web";
60         DATADIR="$PREFIX/var/data";
61         CGIDIR="$PREFIX/var/cgi-bin";
62         TEMPLATEDIR="$PREFIX/var/templates";
63         CIRCRULESDIR="$PREFIX/var/circ";
64         CATALOGSCRIPTDIR="$PREFIX/var/catalog";
65         PENALTYRULESDIR="$PREFIX/var/penalty";
66         XSLDIR="$PREFIX/var/xsl";
67         REPORTERDIR="$PREFIX/var/reporter";
68         TMP="$(pwd)/.tmp";
69         ADMINDIR="$PREFIX/var/admin";
70
71         prompt "Web domain for OPAC in Staff Client [$NEW_OPAC_URL] "
72         read X; if [ ! -z "$X" ]; then NEW_OPAC_URL="$X"; fi;
73
74         prompt "Package Name for Staff Client [$NEW_XUL_PACKAGE_NAME] "
75         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_NAME="$X"; fi;
76
77         prompt "Package Label for Staff Client [$NEW_XUL_PACKAGE_LABEL] "
78         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_LABEL="$X"; fi;
79
80         prompt "Apache2 apxs binary [$APXS2] "
81         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
82
83         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
84         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
85
86         prompt "Apache2 APR headers directory [$APR_HEADERS] "
87         read X; if [ ! -z "$X" ]; then APR_HEADERS="$X"; fi;
88
89         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
90         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
91
92         prompt "Build targets [${TARGETS[@]:0}] "
93         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
94
95         prompt "Bootstrapping Database Driver [$DBDRVR] "
96         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
97
98         prompt "Bootstrapping Database Host [$DBHOST] "
99         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
100
101         prompt "Bootstrapping Database Port [$DBPORT] "
102         read X; if [ ! -z "$X" ]; then DBPORT="$X"; fi;
103
104         prompt "Bootstrapping Database Name [$DBNAME] "
105         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
106
107         prompt "Bootstrapping Database User [$DBUSER] "
108         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
109
110         prompt "Bootstrapping Database Password [$DBPW] "
111         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
112
113         prompt "Reporter Template Directory [$REPORTERDIR] "
114         read X; if [ ! -z "$X" ]; then REPORTERDIR="$X"; fi;
115
116         writeConfig;
117 }
118
119 function prompt { echo ""; echo -en "$*"; }
120
121 function writeConfig {
122
123         rm -f "$CONFIG_FILE";
124         echo "Writing installation config to $CONFIG_FILE...";
125
126         _write "PREFIX=\"$PREFIX\"";
127         _write "BINDIR=\"$BINDIR\"";
128         _write "LIBDIR=\"$LIBDIR\"";
129         _write "PERLDIR=\"$PERLDIR\"";
130         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
131         _write "SOCK=\"$PREFIX/var/sock\"";
132         _write "PID=\"$PREFIX/var/pid\"";
133         _write "LOG=\"$PREFIX/var/log\"";
134         _write "DATADIR=\"$DATADIR\"";
135
136         _write "TMP=\"$TMP\"";
137         _write "APXS2=\"$APXS2\"";
138         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
139         _write "APR_HEADERS=\"$APR_HEADERS\"";
140         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
141
142         _write "WEBDIR=\"$WEBDIR\"";
143         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
144         _write "ETCDIR=\"$ETCDIR\"";
145         _write "CIRCRULESDIR=\"$CIRCRULESDIR\"";
146         _write "CATALOGSCRIPTDIR=\"$CATALOGSCRIPTDIR\"";
147         _write "PENALTYRULESDIR=\"$PENALTYRULESDIR\"";
148         _write "XSLDIR=\"$XSLDIR\"";
149
150         _write "NEW_OPAC_URL=\"$NEW_OPAC_URL\"";
151         _write "NEW_XUL_PACKAGE_NAME=\"$NEW_XUL_PACKAGE_NAME\"";
152         _write "NEW_XUL_PACKAGE_LABEL=\"$NEW_XUL_PACKAGE_LABEL\"";
153
154         # print out the targets
155         STR="TARGETS=(";
156         for target in ${TARGETS[@]:0}; do
157                 STR="$STR \"$target\"";
158         done;
159         STR="$STR)";
160         _write "$STR";
161
162         _write "OPENSRFDIR=\"OpenSRF/src/\"";
163         _write "OPENILSDIR=\"Open-ILS/src/\"";
164         _write "EVERGREENDIR=\"Evergreen/\"";
165
166
167         _write "CGIDIR=\"$CGIDIR\"";
168
169         # db vars
170         _write "DBDRVR=\"$DBDRVR\"";
171         _write "DBHOST=\"$DBHOST\"";
172         _write "DBPORT=\"$DBPORT\"";
173         _write "DBNAME=\"$DBNAME\"";
174         _write "DBUSER=\"$DBUSER\"";
175         _write "DBPW=\"$DBPW\"";
176         _write "REPORTERDIR=\"$REPORTERDIR\"";
177         _write "ADMINDIR=\"$ADMINDIR\"";
178
179
180         # Now we'll write out the DB bootstrapping config
181         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
182         rm -f "$CONFIG_FILE";
183         echo "Writing bootstrapping config to $CONFIG_FILE...";
184
185         STR='$main::config{dsn} =';
186                 STR="$STR 'dbi:${DBDRVR}:host=";
187                 STR="${STR}${DBHOST};dbname=";
188                 STR="${STR}${DBNAME};port=";
189                 STR="${STR}${DBPORT}';";
190         _write "$STR"
191
192         STR='$main::config{usr} =';
193                 STR="$STR '$DBUSER';";
194         _write "$STR"
195         
196         STR='$main::config{pw} =';
197                 STR="$STR '$DBPW';";
198         _write "$STR"
199         
200         _write '$main::config{index} = "config.cgi";';
201
202
203         prompt "";
204         prompt "";
205         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
206         prompt "!! If installing openils_all / openils_db !!";
207         prompt "!! Before running 'make install' you MUST !!";
208         prompt "!! create a database for Open-ILS.  Use   !!";
209         prompt "!! the settings that you listed above and !!";
210         prompt "!! the install scripts will create the    !!";
211         prompt "!! database for you.  -miker              !!";
212         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
213         prompt "";
214         prompt "";
215
216         prompt "To write a new config, run 'make config'";
217         prompt "";
218         prompt "To edit individual install locations (e.g. changing the lib directory),"
219         prompt "edit the install.conf file generated from this script"
220         prompt ""
221
222 }
223
224 function _write {
225         echo "$*" >> "$CONFIG_FILE";
226 }
227
228
229
230 buildConfig;