passing down the db and cgi vars
[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;
55         if [ ! -z "$X" ]; then 
56                 PREFIX="$X"; 
57                 BINDIR="$PREFIX/bin/";
58                 LIBDIR="$PREFIX/lib/";
59                 PERLDIR="$LIBDIR/perl5/";
60                 INCLUDEDIR="$PREFIX/include/";
61                 WEBDIR="$PREFIX/web";
62                 CGIDIR="$PREFIX/cgi-bin";
63                 ETCDIR="$PREFIX/etc";
64                 TEMPLATEDIR="$PREFIX/templates";
65         fi
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 "Templates directory [$TEMPLATEDIR] "
89         read X; if [ ! -z "$X" ]; then TEMPLATEDIR="$X"; fi;
90
91         prompt "Apache2 apxs binary [$APXS2] "
92         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
93
94         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
95         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
96
97         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
98         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
99
100         prompt "Build targets [${TARGETS[@]:0}] "
101         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
102
103         prompt "Bootstrapping Database Driver [$DBDRVR] "
104         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
105
106         prompt "Bootstrapping Database Host [$DBHOST] "
107         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
108
109         prompt "Bootstrapping Database Name [$DBNAME] "
110         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
111
112         prompt "Bootstrapping Database User [$DBUSER] "
113         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
114
115         prompt "Bootstrapping Database Password [$DBPW] "
116         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
117
118         writeConfig;
119 }
120
121 function prompt { echo ""; echo -n "$*"; }
122
123 function writeConfig {
124
125         rm -f "$CONFIG_FILE";
126         echo "Writing installation config to $CONFIG_FILE...";
127
128         _write "PREFIX=\"$PREFIX\"";
129         _write "BINDIR=\"$BINDIR\"";
130         _write "LIBDIR=\"$LIBDIR\"";
131         _write "PERLDIR=\"$PERLDIR\"";
132         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
133
134         _write "TMP=\"$TMP\"";
135         _write "APXS2=\"$APXS2\"";
136         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
137         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
138
139         _write "WEBDIR=\"$WEBDIR\"";
140         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
141         _write "ETCDIR=\"$ETCDIR\"";
142
143         # print out the targets
144         STR="TARGETS=(";
145         for target in ${TARGETS[@]:0}; do
146                 STR="$STR \"$target\"";
147         done;
148         STR="$STR)";
149         _write "$STR";
150
151         _write "OPENSRFDIR=\"OpenSRF/src/\"";
152         _write "OPENILSDIR=\"Open-ILS/src/\"";
153         _write "EVERGREENDIR=\"Evergreen/\"";
154
155
156         _write "CGIDIR=\"$CGIDIR\"";
157
158         # db vars
159         _write "DBDRVR=\"$DBDRVR\"";
160         _write "DBHOST=\"$DBHOST\"";
161         _write "DBNAME=\"$DBNAME\"";
162         _write "DBUSER=\"$DBUSER\"";
163         _write "DBPW=\"$DBPW\"";
164
165
166
167         # Now we'll write out the DB bootstrapping config
168         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
169         rm -f "$CONFIG_FILE";
170         echo "Writing bootstrapping config to $CONFIG_FILE...";
171
172         STR='$main::config{dsn} =';
173                 STR="$STR 'dbi:${DBDRVR}:host=";
174                 STR="${STR}${DBHOST};dbname=";
175                 STR="${STR}${DBNAME}';";
176         _write "$STR"
177
178         STR='$main::config{usr} =';
179                 STR="$STR '$DBUSER';";
180         _write "$STR"
181         
182         STR='$main::config{pw} =';
183                 STR="$STR '$DBPW';";
184         _write "$STR"
185         
186         _write '$main::config{index} = "config.cgi";';
187
188
189         prompt "";
190         prompt "";
191         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
192         prompt "!! Before running 'make install' you MUST !!";
193         prompt "!! create a database for Open-ILS.  Use   !!";
194         prompt "!! the settings that you listed above and !!";
195         prompt "!! the install scripts will create the    !!";
196         prompt "!! database for you.  -miker              !!";
197         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
198         prompt "";
199         prompt "";
200
201         prompt "To write a new config, run 'make config'";
202         prompt "";
203
204 }
205
206 function _write {
207         echo "$*" >> "$CONFIG_FILE";
208 }
209
210
211
212 buildConfig;