350abaa1fd29d76c2d628800be1aa9db265b7b80
[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         ADMINDIR="$PREFIX/var/admin";
63
64         prompt "Web domain for OPAC in Staff Client [$NEW_OPAC_URL] "
65         read X; if [ ! -z "$X" ]; then NEW_OPAC_URL="$X"; fi;
66
67         prompt "Package Name for Staff Client [$NEW_XUL_PACKAGE_NAME] "
68         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_NAME="$X"; fi;
69
70         prompt "Package Label for Staff Client [$NEW_XUL_PACKAGE_LABEL] "
71         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_LABEL="$X"; fi;
72
73         prompt "Apache2 apxs binary [$APXS2] "
74         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
75
76         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
77         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
78
79         prompt "Apache2 APR headers directory [$APR_HEADERS] "
80         read X; if [ ! -z "$X" ]; then APR_HEADERS="$X"; fi;
81
82         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
83         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
84
85         prompt "Build targets [${TARGETS[@]:0}] "
86         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
87
88         prompt "Bootstrapping Database Driver [$DBDRVR] "
89         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
90
91         prompt "Bootstrapping Database Host [$DBHOST] "
92         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
93
94         prompt "Bootstrapping Database Port [$DBPORT] "
95         read X; if [ ! -z "$X" ]; then DBPORT="$X"; fi;
96
97         prompt "Bootstrapping Database Name [$DBNAME] "
98         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
99
100         prompt "Bootstrapping Database User [$DBUSER] "
101         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
102
103         prompt "Bootstrapping Database Password [$DBPW] "
104         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
105
106         prompt "Reporter Template Directory [$REPORTERDIR] "
107         read X; if [ ! -z "$X" ]; then REPORTERDIR="$X"; fi;
108
109         writeConfig;
110 }
111
112 function prompt { echo ""; echo -n "$*"; }
113
114 function writeConfig {
115
116         rm -f "$CONFIG_FILE";
117         echo "Writing installation config to $CONFIG_FILE...";
118
119         _write "PREFIX=\"$PREFIX\"";
120         _write "BINDIR=\"$BINDIR\"";
121         _write "LIBDIR=\"$LIBDIR\"";
122         _write "PERLDIR=\"$PERLDIR\"";
123         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
124         _write "SOCK=\"$PREFIX/var/sock\"";
125         _write "PID=\"$PREFIX/var/pid\"";
126         _write "LOG=\"$PREFIX/var/log\"";
127         _write "DATADIR=\"$DATADIR\"";
128
129         _write "TMP=\"$TMP\"";
130         _write "APXS2=\"$APXS2\"";
131         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
132         _write "APR_HEADERS=\"$APR_HEADERS\"";
133         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
134
135         _write "WEBDIR=\"$WEBDIR\"";
136         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
137         _write "ETCDIR=\"$ETCDIR\"";
138         _write "CIRCRULESDIR=\"$CIRCRULESDIR\"";
139         _write "CATALOGSCRIPTDIR=\"$CATALOGSCRIPTDIR\"";
140         _write "PENALTYRULESDIR=\"$PENALTYRULESDIR\"";
141         _write "XSLDIR=\"$XSLDIR\"";
142
143         _write "NEW_OPAC_URL=\"$NEW_OPAC_URL\"";
144         _write "NEW_XUL_PACKAGE_NAME=\"$NEW_XUL_PACKAGE_NAME\"";
145         _write "NEW_XUL_PACKAGE_LABEL=\"$NEW_XUL_PACKAGE_LABEL\"";
146
147         # print out the targets
148         STR="TARGETS=(";
149         for target in ${TARGETS[@]:0}; do
150                 STR="$STR \"$target\"";
151         done;
152         STR="$STR)";
153         _write "$STR";
154
155         _write "OPENSRFDIR=\"OpenSRF/src/\"";
156         _write "OPENILSDIR=\"Open-ILS/src/\"";
157         _write "EVERGREENDIR=\"Evergreen/\"";
158
159
160         _write "CGIDIR=\"$CGIDIR\"";
161
162         # db vars
163         _write "DBDRVR=\"$DBDRVR\"";
164         _write "DBHOST=\"$DBHOST\"";
165         _write "DBPORT=\"$DBPORT\"";
166         _write "DBNAME=\"$DBNAME\"";
167         _write "DBUSER=\"$DBUSER\"";
168         _write "DBPW=\"$DBPW\"";
169         _write "REPORTERDIR=\"$REPORTERDIR\"";
170         _write "ADMINDIR=\"$ADMINDIR\"";
171
172
173         # Now we'll write out the DB bootstrapping config
174         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
175         rm -f "$CONFIG_FILE";
176         echo "Writing bootstrapping config to $CONFIG_FILE...";
177
178         STR='$main::config{dsn} =';
179                 STR="$STR 'dbi:${DBDRVR}:host=";
180                 STR="${STR}${DBHOST};dbname=";
181                 STR="${STR}${DBNAME};port=";
182                 STR="${STR}${DBPORT}';";
183         _write "$STR"
184
185         STR='$main::config{usr} =';
186                 STR="$STR '$DBUSER';";
187         _write "$STR"
188         
189         STR='$main::config{pw} =';
190                 STR="$STR '$DBPW';";
191         _write "$STR"
192         
193         _write '$main::config{index} = "config.cgi";';
194
195
196         prompt "";
197         prompt "";
198         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
199         prompt "!! If installing openils_all / openils_db !!";
200         prompt "!! Before running 'make install' you MUST !!";
201         prompt "!! create a database for Open-ILS.  Use   !!";
202         prompt "!! the settings that you listed above and !!";
203         prompt "!! the install scripts will create the    !!";
204         prompt "!! database for you.  -miker              !!";
205         prompt "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
206         prompt "";
207         prompt "";
208
209         prompt "To write a new config, run 'make config'";
210         prompt "";
211         prompt "To edit individual install locations (e.g. changing the lib directory),"
212         prompt "edit the install.conf file generated from this script"
213         prompt ""
214
215 }
216
217 function _write {
218         echo "$*" >> "$CONFIG_FILE";
219 }
220
221
222
223 buildConfig;