changes for staff client
[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
28 function buildConfig {
29
30 #       if [ -f "$CONFIG_FILE" ]; then
31 #               echo "";
32 #               echo "Using existing config file \"$CONFIG_FILE\""; 
33 #               echo "To generate a new config, remove \"$CONFIG_FILE\"";
34 #               echo "";
35 #               sleep 3;        
36 #               exit 0;
37 #       fi
38
39
40         if [ -f "$DEFAULT_CONFIG_FILE" ]; then
41                 source "$DEFAULT_CONFIG_FILE";
42         fi;
43
44
45         echo "";
46         echo "-----------------------------------------------------------------------";
47         echo "Type Enter to select the default"
48         echo "-----------------------------------------------------------------------";
49
50         prompt "Temporary files directory [$TMP] "
51         read X; if [ ! -z "$X" ]; then TMP="$X"; fi;
52
53         prompt "Install prefix [$PREFIX] ";
54         read X; if [ ! -z "$X" ]; then PREFIX="$X"; fi
55
56         BINDIR="$PREFIX/bin/";
57         LIBDIR="$PREFIX/lib/";
58         PERLDIR="$LIBDIR/perl5/";
59         INCLUDEDIR="$PREFIX/include/";
60         ETCDIR="$PREFIX/conf";
61         WEBDIR="$PREFIX/var/web";
62         CGIDIR="$PREFIX/var/cgi-bin";
63         TEMPLATEDIR="$PREFIX/var/templates";
64         CIRCRULESDIR="$PREFIX/var/circ";
65         XSLDIR="$PREFIX/var/xsl";
66
67         prompt "Executables directory [$BINDIR] "
68         read X; if [ ! -z "$X" ]; then BINDIR="$X"; fi;
69
70         prompt "Lib directory [$LIBDIR] "
71         read X; if [ ! -z "$X" ]; then LIBDIR="$X"; fi;
72
73         prompt "Perl directory [$PERLDIR] "
74         read X; if [ ! -z "$X" ]; then PERLDIR="$X"; fi;
75
76         prompt "Include files directory [$INCLUDEDIR] "
77         read X; if [ ! -z "$X" ]; then INCLUDEDIR="$X"; fi;
78
79         prompt "Config files directory [$ETCDIR] "
80         read X; if [ ! -z "$X" ]; then ETCDIR="$X"; fi;
81
82         prompt "Web Root Directory [$WEBDIR] "
83         read X; if [ ! -z "$X" ]; then WEBDIR="$X"; fi;
84
85         prompt "Web CGI Directory [$CGIDIR] "
86         read X; if [ ! -z "$X" ]; then CGIDIR="$X"; fi;
87
88         prompt "Web domain for OPAC in Staff Client [$NEW_OPAC_URL] "
89         read X; if [ ! -z "$X" ]; then NEW_OPAC_URL="$X"; fi;
90
91         prompt "Package Name for Staff Client [$NEW_XUL_PACKAGE_NAME] "
92         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_NAME="$X"; fi;
93
94         prompt "Package Label for Staff Client [$NEW_XUL_PACKAGE_LABEL] "
95         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_LABEL="$X"; fi;
96
97         prompt "Templates directory [$TEMPLATEDIR] "
98         read X; if [ ! -z "$X" ]; then TEMPLATEDIR="$X"; fi;
99
100         prompt "XSL Stylesheets directory [$XSLDIR] "
101         read X; if [ ! -z "$X" ]; then XSLDIR="$X"; fi;
102
103         prompt "Custom circulation rules directory [$CIRCRULESDIR] "
104         read X; if [ ! -z "$X" ]; then CIRCRULESDIR="$X"; fi;
105
106         prompt "Apache2 apxs binary [$APXS2] "
107         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
108
109         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
110         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
111
112         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
113         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
114
115         prompt "Build targets [${TARGETS[@]:0}] "
116         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
117
118         prompt "Bootstrapping Database Driver [$DBDRVR] "
119         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
120
121         prompt "Bootstrapping Database Host [$DBHOST] "
122         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
123
124         prompt "Bootstrapping Database Name [$DBNAME] "
125         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
126
127         prompt "Bootstrapping Database User [$DBUSER] "
128         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
129
130         prompt "Bootstrapping Database Password [$DBPW] "
131         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
132
133         writeConfig;
134 }
135
136 function prompt { echo ""; echo -n "$*"; }
137
138 function writeConfig {
139
140         rm -f "$CONFIG_FILE";
141         echo "Writing installation config to $CONFIG_FILE...";
142
143         _write "PREFIX=\"$PREFIX\"";
144         _write "BINDIR=\"$BINDIR\"";
145         _write "LIBDIR=\"$LIBDIR\"";
146         _write "PERLDIR=\"$PERLDIR\"";
147         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
148
149         _write "TMP=\"$TMP\"";
150         _write "APXS2=\"$APXS2\"";
151         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
152         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
153
154         _write "WEBDIR=\"$WEBDIR\"";
155         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
156         _write "ETCDIR=\"$ETCDIR\"";
157         _write "CIRCRULESDIR=\"$CIRCRULESDIR\"";
158         _write "XSLDIR=\"$XSLDIR\"";
159
160         _write "NEW_OPAC_URL=\"$NEW_OPAC_URL\"";
161         _write "NEW_XUL_PACKAGE_NAME=\"$NEW_XUL_PACKAGE_NAME\"";
162         _write "NEW_XUL_PACKAGE_LABEL=\"$NEW_XUL_PACKAGE_LABEL\"";
163
164         # print out the targets
165         STR="TARGETS=(";
166         for target in ${TARGETS[@]:0}; do
167                 STR="$STR \"$target\"";
168         done;
169         STR="$STR)";
170         _write "$STR";
171
172         _write "OPENSRFDIR=\"OpenSRF/src/\"";
173         _write "OPENILSDIR=\"Open-ILS/src/\"";
174         _write "EVERGREENDIR=\"Evergreen/\"";
175
176
177         _write "CGIDIR=\"$CGIDIR\"";
178
179         # db vars
180         _write "DBDRVR=\"$DBDRVR\"";
181         _write "DBHOST=\"$DBHOST\"";
182         _write "DBNAME=\"$DBNAME\"";
183         _write "DBUSER=\"$DBUSER\"";
184         _write "DBPW=\"$DBPW\"";
185
186
187         # Now we'll write out the DB bootstrapping config
188         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
189         rm -f "$CONFIG_FILE";
190         echo "Writing bootstrapping config to $CONFIG_FILE...";
191
192         STR='$main::config{dsn} =';
193                 STR="$STR 'dbi:${DBDRVR}:host=";
194                 STR="${STR}${DBHOST};dbname=";
195                 STR="${STR}${DBNAME}';";
196         _write "$STR"
197
198         STR='$main::config{usr} =';
199                 STR="$STR '$DBUSER';";
200         _write "$STR"
201         
202         STR='$main::config{pw} =';
203                 STR="$STR '$DBPW';";
204         _write "$STR"
205         
206         _write '$main::config{index} = "config.cgi";';
207
208
209         prompt "";
210         prompt "";
211         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
212         prompt "!! If installing openils_all / openils_db !!";
213         prompt "!! Before running 'make install' you MUST !!";
214         prompt "!! create a database for Open-ILS.  Use   !!";
215         prompt "!! the settings that you listed above and !!";
216         prompt "!! the install scripts will create the    !!";
217         prompt "!! database for you.  -miker              !!";
218         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
219         prompt "";
220         prompt "";
221
222         prompt "To write a new config, run 'make config'";
223         prompt "";
224
225 }
226
227 function _write {
228         echo "$*" >> "$CONFIG_FILE";
229 }
230
231
232
233 buildConfig;