Lines 19-29
Link Here
|
19 |
|
19 |
|
20 |
set -e |
20 |
set -e |
21 |
|
21 |
|
22 |
usage="Usage: $0 [--create-db|--request-db|--populate-db] \ |
22 |
usage="Usage: $0 [--create-db|--request-db|--populate-db|--use-db] \ |
23 |
[--marcflavor marc21|normarc|unimarc] \ |
23 |
[--marcflavor marc21|normarc|unimarc] \ |
24 |
[--zebralang en|nb|fr] \ |
24 |
[--zebralang en|nb|fr] \ |
25 |
[--defaultsql /path/to/some.sql] \ |
25 |
[--defaultsql /path/to/some.sql] \ |
26 |
[--configfile /path/to/config] [--adminuser n] instancename" |
26 |
[--configfile /path/to/config] [--passwdfile /path/to/passwd] \ |
|
|
27 |
[--database database] [--adminuser n] instancename" |
27 |
|
28 |
|
28 |
die() { |
29 |
die() { |
29 |
echo "$@" 1>&2 |
30 |
echo "$@" 1>&2 |
Lines 76-81
getinstancemysqldatabase() {
Link Here
|
76 |
# Set defaults and read config file, if it exists. |
77 |
# Set defaults and read config file, if it exists. |
77 |
DOMAIN="" |
78 |
DOMAIN="" |
78 |
OPACPORT="80" |
79 |
OPACPORT="80" |
|
|
80 |
OPACPREFIX="" |
81 |
OPACSUFFIX="" |
79 |
INTRAPORT="8080" |
82 |
INTRAPORT="8080" |
80 |
INTRAPREFIX="" |
83 |
INTRAPREFIX="" |
81 |
INTRASUFFIX="" |
84 |
INTRASUFFIX="" |
Lines 83-96
DEFAULTSQL=""
Link Here
|
83 |
ZEBRA_MARC_FORMAT="marc21" |
86 |
ZEBRA_MARC_FORMAT="marc21" |
84 |
ZEBRA_LANGUAGE="en" |
87 |
ZEBRA_LANGUAGE="en" |
85 |
ADMINUSER="1" |
88 |
ADMINUSER="1" |
|
|
89 |
PASSWDFILE="/etc/koha/passwd" |
86 |
if [ -e /etc/koha/koha-sites.conf ] |
90 |
if [ -e /etc/koha/koha-sites.conf ] |
87 |
then |
91 |
then |
88 |
. /etc/koha/koha-sites.conf |
92 |
. /etc/koha/koha-sites.conf |
89 |
fi |
93 |
fi |
90 |
|
94 |
|
91 |
[ $# -ge 2 ] && [ $# -le 12 ] || die $usage |
95 |
[ $# -ge 2 ] && [ $# -le 16 ] || die $usage |
92 |
|
96 |
|
93 |
TEMP=`getopt -o crpm:l:d:f:a: -l create-db,request-db,populate-db,marcflavor:,zebralang:,defaultsql:,configfile:,adminuser: \ |
97 |
TEMP=`getopt -o crpm:l:d:f:a: -l create-db,request-db,populate-db,use-db,marcflavor:,zebralang:,defaultsql:,configfile:,passwdfile:,adminuser: \ |
94 |
-n "$0" -- "$@"` |
98 |
-n "$0" -- "$@"` |
95 |
|
99 |
|
96 |
# Note the quotes around `$TEMP': they are essential! |
100 |
# Note the quotes around `$TEMP': they are essential! |
Lines 107-116
while true ; do
Link Here
|
107 |
-c|--create-db) op=create ; shift ;; |
111 |
-c|--create-db) op=create ; shift ;; |
108 |
-r|--request-db) op=request ; shift ;; |
112 |
-r|--request-db) op=request ; shift ;; |
109 |
-p|--populate-db) op=populate ; shift ;; |
113 |
-p|--populate-db) op=populate ; shift ;; |
|
|
114 |
-u|--use-db) op=use ; shift ;; |
110 |
-m|--marcflavor) CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; |
115 |
-m|--marcflavor) CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; |
111 |
-l|--zebralang) CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; |
116 |
-l|--zebralang) CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; |
112 |
-d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; |
117 |
-d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; |
113 |
-f|--configfile) configfile="$2" ; shift 2 ;; |
118 |
-f|--configfile) configfile="$2" ; shift 2 ;; |
|
|
119 |
-s|--passwdfile) CLO_PASSWDFILE="$2" ; shift 2 ;; |
120 |
-b|--database) CLO_DATABASE="$2" ; shift 2 ;; |
114 |
-a|--adminuser) CLO_ADMINUSER="$2" ; shift 2 ;; |
121 |
-a|--adminuser) CLO_ADMINUSER="$2" ; shift 2 ;; |
115 |
--) shift ; break ;; |
122 |
--) shift ; break ;; |
116 |
*) die "Internal error processing command line arguments" ;; |
123 |
*) die "Internal error processing command line arguments" ;; |
Lines 145-170
if [ "$CLO_ADMINUSER" != "" ]
Link Here
|
145 |
then |
152 |
then |
146 |
ADMINUSER="$CLO_ADMINUSER" |
153 |
ADMINUSER="$CLO_ADMINUSER" |
147 |
fi |
154 |
fi |
|
|
155 |
if [ "$CLO_PASSWDFILE" != "" ] |
156 |
then |
157 |
PASSWDFILE="$CLO_PASSWDFILE" |
158 |
fi |
148 |
|
159 |
|
149 |
name="$1" |
160 |
name="$1" |
150 |
|
161 |
|
151 |
opacdomain="$name$DOMAIN" |
162 |
opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN" |
152 |
intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" |
163 |
intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" |
153 |
|
164 |
|
154 |
|
165 |
|
155 |
mysqldb="koha_$name" |
166 |
if [ `cat $PASSWDFILE | grep "^$name:"` ] |
|
|
167 |
then |
168 |
passwdline=`cat $PASSWDFILE | grep "^$name:"` |
169 |
mysqluser=`echo $passwdline | cut -d ":" -f 2` |
170 |
mysqlpwd=`echo $passwdline | cut -d ":" -f 3` |
171 |
mysqldb=`echo $passwdline | cut -d ":" -f 4` |
172 |
fi |
173 |
|
174 |
# The order of precedence for MySQL database name is: |
175 |
# default < passwd file < command line |
176 |
if [ "$mysqldb" = "" ] |
177 |
then |
178 |
mysqldb="koha_$name" |
179 |
fi |
180 |
if [ "$CLO_DATABASE" != "" ] |
181 |
then |
182 |
mysqldb="$CLO_DATABASE" |
183 |
fi |
184 |
|
185 |
if [ "$mysqluser" = "" ] |
186 |
then |
187 |
mysqluser="koha_$name" |
188 |
fi |
156 |
mysqlhost="$(getmysqlhost)" |
189 |
mysqlhost="$(getmysqlhost)" |
157 |
mysqluser="koha_$name" |
|
|
158 |
|
190 |
|
159 |
if [ "$op" = create ] || [ "$op" = request ] |
191 |
if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ] |
160 |
then |
192 |
then |
161 |
mysqlpwd="$(pwgen -1)" |
193 |
if [ "$mysqlpwd" = "" ] |
|
|
194 |
then |
195 |
mysqlpwd="$(pwgen -1)" |
196 |
fi |
162 |
else |
197 |
else |
163 |
mysqlpwd="$(getinstancemysqlpassword $name)" |
198 |
mysqlpwd="$(getinstancemysqlpassword $name)" |
164 |
fi |
199 |
fi |
165 |
|
200 |
|
166 |
|
201 |
|
167 |
if [ "$op" = create ] || [ "$op" = request ] |
202 |
if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ] |
168 |
then |
203 |
then |
169 |
# Create new user and group. |
204 |
# Create new user and group. |
170 |
username="$name-koha" |
205 |
username="$name-koha" |
Lines 197-202
FLUSH PRIVILEGES;
Link Here
|
197 |
eof |
232 |
eof |
198 |
fi #` |
233 |
fi #` |
199 |
|
234 |
|
|
|
235 |
if [ "$op" = use ] |
236 |
then |
237 |
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <<eof |
238 |
CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd'; |
239 |
GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`; |
240 |
FLUSH PRIVILEGES; |
241 |
eof |
242 |
fi #` |
243 |
|
200 |
# Generate and install Apache site-available file and log dir. |
244 |
# Generate and install Apache site-available file and log dir. |
201 |
generate_config_file apache-site.conf.in \ |
245 |
generate_config_file apache-site.conf.in \ |
202 |
"/etc/apache2/sites-available/$name" |
246 |
"/etc/apache2/sites-available/$name" |
Lines 283-289
eof
Link Here
|
283 |
fi |
327 |
fi |
284 |
|
328 |
|
285 |
|
329 |
|
286 |
if [ "$op" = create ] || [ "$op" = populate ] |
330 |
if [ "$op" = create ] || [ "$op" = populate ] || [ "$op" = use ] |
287 |
then |
331 |
then |
288 |
# Reconfigure Apache. |
332 |
# Reconfigure Apache. |
289 |
a2ensite "$name" |
333 |
a2ensite "$name" |