fix off=by-one in closed days
[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                 source "$CONFIG_FILE";
32         else
33                 if [ -f "$DEFAULT_CONFIG_FILE" ]; then
34                         source "$DEFAULT_CONFIG_FILE";
35                 fi;
36         fi;
37
38
39         echo "";
40         echo "-----------------------------------------------------------------------";
41         echo "Type Enter to select the default"
42         echo "-----------------------------------------------------------------------";
43
44         prompt "Install prefix [$PREFIX] ";
45         read X; if [ ! -z "$X" ]; then PREFIX="$X"; fi
46
47         BINDIR="$PREFIX/bin/";
48         LIBDIR="$PREFIX/lib/";
49         PERLDIR="$LIBDIR/perl5/";
50         INCLUDEDIR="$PREFIX/include/";
51         ETCDIR="$PREFIX/conf";
52         WEBDIR="$PREFIX/var/web";
53         DATADIR="$PREFIX/var/data";
54         CGIDIR="$PREFIX/var/cgi-bin";
55         TEMPLATEDIR="$PREFIX/var/templates";
56         CIRCRULESDIR="$PREFIX/var/circ";
57         CATALOGSCRIPTDIR="$PREFIX/var/catalog";
58         PENALTYRULESDIR="$PREFIX/var/penalty";
59         XSLDIR="$PREFIX/var/xsl";
60         REPORTERDIR="$PREFIX/var/reporter";
61         TMP="$(pwd)/.tmp";
62
63         prompt "Web domain for OPAC in Staff Client [$NEW_OPAC_URL] "
64         read X; if [ ! -z "$X" ]; then NEW_OPAC_URL="$X"; fi;
65
66         prompt "Package Name for Staff Client [$NEW_XUL_PACKAGE_NAME] "
67         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_NAME="$X"; fi;
68
69         prompt "Package Label for Staff Client [$NEW_XUL_PACKAGE_LABEL] "
70         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_LABEL="$X"; fi;
71
72         prompt "Apache2 apxs binary [$APXS2] "
73         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
74
75         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
76         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
77
78         prompt "Apache2 APR headers directory [$APR_HEADERS] "
79         read X; if [ ! -z "$X" ]; then APR_HEADERS="$X"; fi;
80
81         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
82         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
83
84         prompt "Build targets [${TARGETS[@]:0}] "
85         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
86
87         prompt "Bootstrapping Database Driver [$DBDRVR] "
88         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
89
90         prompt "Bootstrapping Database Host [$DBHOST] "
91         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
92
93         prompt "Bootstrapping Database Port [$DBPORT] "
94         read X; if [ ! -z "$X" ]; then DBPORT="$X"; fi;
95
96         prompt "Bootstrapping Database Name [$DBNAME] "
97         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
98
99         prompt "Bootstrapping Database User [$DBUSER] "
100         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
101
102         prompt "Bootstrapping Database Password [$DBPW] "
103         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
104
105         prompt "Reporter Template Directory [$REPORTERDIR] "
106         read X; if [ ! -z "$X" ]; then REPORTERDIR="$X"; fi;
107
108         writeConfig;
109 }
110
111 function prompt { echo ""; echo -n "$*"; }
112
113 function writeConfig {
114
115         rm -f "$CONFIG_FILE";
116         echo "Writing installation config to $CONFIG_FILE...";
117
118         _write "PREFIX=\"$PREFIX\"";
119         _write "BINDIR=\"$BINDIR\"";
120         _write "LIBDIR=\"$LIBDIR\"";
121         _write "PERLDIR=\"$PERLDIR\"";
122         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
123         _write "SOCK=\"$PREFIX/var/sock\"";
124         _write "PID=\"$PREFIX/var/pid\"";
125         _write "LOG=\"$PREFIX/var/log\"";
126         _write "DATADIR=\"$DATADIR\"";
127
128         _write "TMP=\"$TMP\"";
129         _write "APXS2=\"$APXS2\"";
130         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
131         _write "APR_HEADERS=\"$APR_HEADERS\"";
132         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
133
134         _write "WEBDIR=\"$WEBDIR\"";
135         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
136         _write "ETCDIR=\"$ETCDIR\"";
137         _write "CIRCRULESDIR=\"$CIRCRULESDIR\"";
138         _write "CATALOGSCRIPTDIR=\"$CATALOGSCRIPTDIR\"";
139         _write "PENALTYRULESDIR=\"$PENALTYRULESDIR\"";
140         _write "XSLDIR=\"$XSLDIR\"";
141
142         _write "NEW_OPAC_URL=\"$NEW_OPAC_URL\"";
143         _write "NEW_XUL_PACKAGE_NAME=\"$NEW_XUL_PACKAGE_NAME\"";
144         _write "NEW_XUL_PACKAGE_LABEL=\"$NEW_XUL_PACKAGE_LABEL\"";
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 "DBPORT=\"$DBPORT\"";
165         _write "DBNAME=\"$DBNAME\"";
166         _write "DBUSER=\"$DBUSER\"";
167         _write "DBPW=\"$DBPW\"";
168         _write "REPORTERDIR=\"$REPORTERDIR\"";
169
170
171         # Now we'll write out the DB bootstrapping config
172         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
173         rm -f "$CONFIG_FILE";
174         echo "Writing bootstrapping config to $CONFIG_FILE...";
175
176         STR='$main::config{dsn} =';
177                 STR="$STR 'dbi:${DBDRVR}:host=";
178                 STR="${STR}${DBHOST};dbname=";
179                 STR="${STR}${DBNAME};port=";
180                 STR="${STR}${DBPORT}';";
181         _write "$STR"
182
183         STR='$main::config{usr} =';
184                 STR="$STR '$DBUSER';";
185         _write "$STR"
186         
187         STR='$main::config{pw} =';
188                 STR="$STR '$DBPW';";
189         _write "$STR"
190         
191         _write '$main::config{index} = "config.cgi";';
192
193
194         prompt "";
195         prompt "";
196         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
197         prompt "!! If installing openils_all / openils_db !!";
198         prompt "!! Before running 'make install' you MUST !!";
199         prompt "!! create a database for Open-ILS.  Use   !!";
200         prompt "!! the settings that you listed above and !!";
201         prompt "!! the install scripts will create the    !!";
202         prompt "!! database for you.  -miker              !!";
203         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
204         prompt "";
205         prompt "";
206
207         prompt "To write a new config, run 'make config'";
208         prompt "";
209         prompt "To edit individual install locations (e.g. changing the lib directory),"
210         prompt "edit the install.conf file generated from this script"
211         prompt ""
212
213 }
214
215 function _write {
216         echo "$*" >> "$CONFIG_FILE";
217 }
218
219
220
221 buildConfig;