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