]> git.evergreen-ils.org Git - Evergreen.git/blob - config.sh
83b894794702a74aa5b3c01298de27fe49ea7563
[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         PENALTYRULESDIR="$PREFIX/var/penalty";
58         XSLDIR="$PREFIX/var/xsl";
59         REPORTERDIR="$PREFIX/var/reporter";
60         TMP="$(pwd)/.tmp";
61
62         prompt "Web domain for OPAC in Staff Client [$NEW_OPAC_URL] "
63         read X; if [ ! -z "$X" ]; then NEW_OPAC_URL="$X"; fi;
64
65         prompt "Package Name for Staff Client [$NEW_XUL_PACKAGE_NAME] "
66         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_NAME="$X"; fi;
67
68         prompt "Package Label for Staff Client [$NEW_XUL_PACKAGE_LABEL] "
69         read X; if [ ! -z "$X" ]; then NEW_XUL_PACKAGE_LABEL="$X"; fi;
70
71         prompt "Apache2 apxs binary [$APXS2] "
72         read X; if [ ! -z "$X" ]; then APXS2="$X"; fi;
73
74         prompt "Apache2 headers directory [$APACHE2_HEADERS] "
75         read X; if [ ! -z "$X" ]; then APACHE2_HEADERS="$X"; fi;
76
77         prompt "Apache2 APR headers directory [$APR_HEADERS] "
78         read X; if [ ! -z "$X" ]; then APR_HEADERS="$X"; fi;
79
80         prompt "Libxml2 headers directory [$LIBXML2_HEADERS] "
81         read X; if [ ! -z "$X" ]; then LIBXML2_HEADERS="$X"; fi;
82
83         prompt "Build targets [${TARGETS[@]:0}] "
84         read X; if [ ! -z "$X" ]; then TARGETS=("$X"); fi;
85
86         prompt "Bootstrapping Database Driver [$DBDRVR] "
87         read X; if [ ! -z "$X" ]; then DBDRVR="$X"; fi;
88
89         prompt "Bootstrapping Database Host [$DBHOST] "
90         read X; if [ ! -z "$X" ]; then DBHOST="$X"; fi;
91
92         prompt "Bootstrapping Database Port [$DBPORT] "
93         read X; if [ ! -z "$X" ]; then DBPORT="$X"; fi;
94
95         prompt "Bootstrapping Database Name [$DBNAME] "
96         read X; if [ ! -z "$X" ]; then DBNAME="$X"; fi;
97
98         prompt "Bootstrapping Database User [$DBUSER] "
99         read X; if [ ! -z "$X" ]; then DBUSER="$X"; fi;
100
101         prompt "Bootstrapping Database Password [$DBPW] "
102         read X; if [ ! -z "$X" ]; then DBPW="$X"; fi;
103
104         prompt "Reporter Template Directory [$REPORTERDIR] "
105         read X; if [ ! -z "$X" ]; then REPORTERDIR="$X"; fi;
106
107         writeConfig;
108 }
109
110 function prompt { echo ""; echo -n "$*"; }
111
112 function writeConfig {
113
114         rm -f "$CONFIG_FILE";
115         echo "Writing installation config to $CONFIG_FILE...";
116
117         _write "PREFIX=\"$PREFIX\"";
118         _write "BINDIR=\"$BINDIR\"";
119         _write "LIBDIR=\"$LIBDIR\"";
120         _write "PERLDIR=\"$PERLDIR\"";
121         _write "INCLUDEDIR=\"$INCLUDEDIR\"";
122         _write "SOCK=\"$PREFIX/var/sock\"";
123         _write "PID=\"$PREFIX/var/pid\"";
124         _write "LOG=\"$PREFIX/var/log\"";
125         _write "DATADIR=\"$DATADIR\"";
126
127         _write "TMP=\"$TMP\"";
128         _write "APXS2=\"$APXS2\"";
129         _write "APACHE2_HEADERS=\"$APACHE2_HEADERS\"";
130         _write "APR_HEADERS=\"$APR_HEADERS\"";
131         _write "LIBXML2_HEADERS=\"$LIBXML2_HEADERS\"";
132
133         _write "WEBDIR=\"$WEBDIR\"";
134         _write "TEMPLATEDIR=\"$TEMPLATEDIR\"";
135         _write "ETCDIR=\"$ETCDIR\"";
136         _write "CIRCRULESDIR=\"$CIRCRULESDIR\"";
137         _write "PENALTYRULESDIR=\"$PENALTYRULESDIR\"";
138         _write "XSLDIR=\"$XSLDIR\"";
139
140         _write "NEW_OPAC_URL=\"$NEW_OPAC_URL\"";
141         _write "NEW_XUL_PACKAGE_NAME=\"$NEW_XUL_PACKAGE_NAME\"";
142         _write "NEW_XUL_PACKAGE_LABEL=\"$NEW_XUL_PACKAGE_LABEL\"";
143
144         # print out the targets
145         STR="TARGETS=(";
146         for target in ${TARGETS[@]:0}; do
147                 STR="$STR \"$target\"";
148         done;
149         STR="$STR)";
150         _write "$STR";
151
152         _write "OPENSRFDIR=\"OpenSRF/src/\"";
153         _write "OPENILSDIR=\"Open-ILS/src/\"";
154         _write "EVERGREENDIR=\"Evergreen/\"";
155
156
157         _write "CGIDIR=\"$CGIDIR\"";
158
159         # db vars
160         _write "DBDRVR=\"$DBDRVR\"";
161         _write "DBHOST=\"$DBHOST\"";
162         _write "DBPORT=\"$DBPORT\"";
163         _write "DBNAME=\"$DBNAME\"";
164         _write "DBUSER=\"$DBUSER\"";
165         _write "DBPW=\"$DBPW\"";
166         _write "REPORTERDIR=\"$REPORTERDIR\"";
167
168
169         # Now we'll write out the DB bootstrapping config
170         CONFIG_FILE='Open-ILS/src/cgi-bin/setup.pl';
171         rm -f "$CONFIG_FILE";
172         echo "Writing bootstrapping config to $CONFIG_FILE...";
173
174         STR='$main::config{dsn} =';
175                 STR="$STR 'dbi:${DBDRVR}:host=";
176                 STR="${STR}${DBHOST};dbname=";
177                 STR="${STR}${DBNAME};port=";
178                 STR="${STR}${DBPORT}';";
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         prompt "To edit individual install locations (e.g. changing the lib directory),"
208         prompt "edit the install.conf file generated from this script"
209         prompt ""
210
211 }
212
213 function _write {
214         echo "$*" >> "$CONFIG_FILE";
215 }
216
217
218
219 buildConfig;