Bug 17229: Check if patron is expired in CanItemBeReserved
[koha.git] / rewrite-config.PL
1 # Copyright 2007 MJ Ray
2 #
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17 #
18 # Current maintainer MJR http://mjr.towers.org.uk/
19
20 # 2007/11/12    Added DB_PORT and changed other keywords to reflect multi-dbms support. -fbcit
21
22 use Modern::Perl;
23 use Sys::Hostname;
24 use Socket;
25
26 =head1 NAME
27
28 rewrite-config.PL - helper for the Koha packager and installer
29
30 =head1 SYNOPSIS
31
32         perl rewrite-config.PL configurationfile
33
34 =head1 DESCRIPTION
35
36 This helper script replaces keywords in the
37 configuration files with value either supplied through
38 the environment (with export, or by putting them on
39 the start of the make command line) or with reasonable
40 guesses worked out by the script.
41
42 =head2 KEYWORDS
43
44 The following configuration keywords are available:
45
46 PREFIX,
47 BASE_DIR, CGI_DIR, LOG_DIR, PLUGINS_DIR, INSTALL_BASE,
48 DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, DB_USE_TLS, DB_TLS_CA_CERT, DB_TLS_CLIENT_KEY, DB_TLS_CLIENT_CERT, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
49 WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
50
51 =head1 EXAMPLES
52
53 To override the guessed hostname and email address, run:
54
55         WEBSERVER_HOST=mysecrethostname.com.invalid \
56         WEBMASTER_EMAIL=webmaster@publichost.com make install
57
58 Note that if WEBSERVER_HOST does not resolve to an IP address, you will
59 also need to override WEBSERVER_IP.
60
61 =cut
62
63 my $myhost;
64 my $mydomain;
65 if ( $myhost = $ENV{WEBSERVER_HOST} || hostname ) {
66     ( $mydomain = $myhost ) =~ s/.*?\.//;
67 } else {
68     $myhost   = 'localhost';
69     $mydomain = 'localdomain';
70 }
71
72 my $myip;
73 unless ( $myip = $ENV{WEBSERVER_IP} ) {
74     my $byname = gethostbyname( $myhost )
75         or die "Could not get the IP address of $myhost, DNS fault? ($!)";
76     $myip = inet_ntoa $byname
77         or die "can't inet_ntoa ($!)";
78 }
79
80
81 my $prefix = $ENV{'INSTALL_BASE'} || "/usr";
82
83 # These are our configuration guesses
84 # Keys were extracted by
85 # <grep -o '__.*__' etc/* | cut -f2 -d: | sort -u | sed -e 's/^/  "/;s/$/" => "",/'
86 my %configuration = (
87   "__KOHA_INSTALLED_VERSION__" => "no_version_found",
88   "__LOG_DIR__" => "/var/log",
89   "__PLUGINS_DIR__" => "/var/lib/koha/plugins",
90   "__DB_TYPE__" => "mysql",
91   "__DB_NAME__" => "koha",
92   "__DB_HOST__" => $myhost,
93   "__DB_PORT__" => "3306",
94   "__DB_USER__" => "kohaadmin",
95   "__DB_PASS__" => "katikoan",
96   "__DB_USE_TLS__" => "no",
97   "__DB_TLS_CA_CERTIFICATE__" => "",
98   "__DB_TLS_CLIENT_CERTIFICATE__" => "",
99   "__DB_TLS_CLIENT_KEY__"=>"",
100   "__WEBMASTER_EMAIL__" => 'webmaster@'.$mydomain,
101   "__WEBSERVER_DOMAIN__" => $mydomain,
102   "__WEBSERVER_HOST__" => $myhost,
103   "__WEBSERVER_IP__" => $myip,
104   "__WEBSERVER_PORT__" => "80",
105   "__WEBSERVER_PORT_LIBRARIAN__" => "8080",
106   "__ZEBRA_SRU_HOST__" => $myhost,
107   "__ZEBRA_SRU_BIBLIOS_PORT__" => "9998",
108   "__ZEBRA_SRU_AUTHORITIES_PORT__" => "9999",
109   "__KOHA_USER__" => "koha",
110   "__KOHA_GROUP__" => "koha",
111   "__ZEBRA_PASS__" => "zebrastripes",
112   "__ZEBRA_USER__" => "kohauser",
113   '__BACKUP_DIR__' => "$prefix/var/spool",
114   '__API_CGI_DIR__' => "$prefix/api",
115   '__INTRANET_CGI_DIR__' => "$prefix/intranet/cgi-bin",
116   '__INTRANET_TMPL_DIR__' => "$prefix/intranet/templates",
117   '__INTRANET_WWW_DIR__' => "$prefix/intranet/www",
118   '__OPAC_CGI_DIR__' => "$prefix/opac/cgi-bin",
119   '__OPAC_TMPL_DIR__' => "$prefix/opac/templates",
120   '__OPAC_WWW_DIR__' => "$prefix/opac/www",
121   '__PERL_MODULE_DIR__' =>  ($ENV{'INSTALLSITELIB'} || sprintf($prefix."/lib/perl5/site_perl/%vd",$^V))."/koha",
122   '__KOHA_CONF_DIR__' => "$prefix/etc/koha",
123   '__ZEBRA_CONF_DIR__' => "$prefix/etc/koha/zebradb",
124   '__PAZPAR2_CONF_DIR__' => "$prefix/etc/koha/pazpar2",
125   '__MISC_DIR__' => "$prefix/misc",
126   '__SCRIPT_DIR__' => "$prefix/bin",
127   '__SCRIPT_NONDEV_DIR__' => "$prefix/bin",
128   '__MAN_DIR__' => "$prefix/man",
129   '__DOC_DIR__' => "$prefix/doc",
130   '__ZEBRA_LOCK_DIR__' => "$prefix/var/lock/zebradb",
131   '__ZEBRA_DATA_DIR__' => "$prefix/var/lib/zebradb",
132   '__ZEBRA_RUN_DIR__' => "$prefix/var/run/zebradb",
133   '__ZEBRA_MARC_FORMAT__' => 'marc21',
134   '__ZEBRA_LANGUAGE__' => 'en',
135   '__ZEBRA_TOKENIZER__' => 'chr',
136   '__ZEBRA_TOKENIZER_STMT__' => 'charmap word-phrase-utf.chr',
137   '__ZEBRA_PTOKENIZER_STMT__' => 'charmap word-phrase-utf.chr',
138   '__AUTH_RETRIEVAL_CFG__' => 'retrieval-info-auth-dom.xml',
139   '__BIB_RETRIEVAL_CFG__' => 'retrieval-info-bib-dom.xml',
140   '__ZEBRA_AUTH_CFG__' => 'zebra-authorities-dom.cfg',
141   '__ZEBRA_BIB_CFG__' => 'zebra-biblios-dom.cfg',
142   "__MERGE_SERVER_HOST__" => $myhost,
143   "__MERGE_SERVER_PORT__" => '11001',
144   "__PAZPAR2_HOST__" => $myhost,
145   "__PAZPAR2_PORT__" => '11002',
146   "__INSTALL_MODE__" => 'standard',
147   "__INSTALL_BASE__" => '/usr/share/koha',
148   "__INSTALL_SRU__" => 'yes',
149   "__INSTALL_PAZPAR2__" => 'no',
150   "__PAZPAR2_TOGGLE_XML_PRE__" => '<!--',
151   "__PAZPAR2_TOGGLE_XML_POST__" => '-->',
152   "__RUN_DATABASE_TESTS__" => 'no',
153   "__PATH_TO_ZEBRA__" => "",
154   "__USE_MEMCACHED__" => 'yes',
155   "__MEMCACHED_SERVERS__" => "",
156   "__MEMCACHED_NAMESPACE__" => "",
157   "__USE_ELASTICSEARCH__" => 'no',
158   "__ELASTICSEARCH_SERVERS__" => "localhost:9200",
159   "__ELASTICSEARCH_INDEX__" => "koha",
160   "__FONT_DIR__" => "/usr/share/fonts/truetype/dejavu",
161   "__TEMPLATE_CACHE_DIR__" => "/tmp/koha",
162   '__SMTP_HOST__'      => 'localhost',
163   '__SMTP_PORT__'      => '25',
164   '__SMTP_TIMEOUT__'   => '120',
165   '__SMTP_SSL_MODE__'  => 'disabled',
166   '__SMTP_USER_NAME__' => '',
167   '__SMTP_PASSWORD__'  => '',
168   '__SMTP_DEBUG__'     => '0',
169 );
170
171 # Override configuration from the environment
172 foreach my $key (keys %configuration) {
173   if (defined($ENV{$key})) {
174     $configuration{$key} = $ENV{$key};
175   }
176 }
177
178 # munge commenting out the PazPar2 mergeserver
179 # entry in koha-conf.xml if necessary
180 if ($configuration{'__INSTALL_PAZPAR2__'} eq 'yes') {
181     $configuration{'__PAZPAR2_TOGGLE_XML_PRE__'} = '';
182     $configuration{'__PAZPAR2_TOGGLE_XML_POST__'} = '';
183 }
184
185 my $fname = $ARGV[0];
186 my $file = &read_file($fname);
187 $file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg;
188
189 # At this point, file is in 'blib' and by default
190 # has mode a-w.  Therefore, must change permission
191 # to make it writable.  Note that stat and chmod
192 # (the Perl functions) should work on Win32
193 my $old_perm;
194 $old_perm = (stat $fname)[2] & oct(7777);
195 my $new_perm = $old_perm | oct(200);
196 chmod $new_perm, $fname;
197
198 open(my $output, ">", $fname) || die "Can't open $fname for write: $!";
199 print $output $file;
200 close($output);
201
202 chmod $old_perm, $fname;
203
204 # Idea taken from perlfaq5
205 sub read_file {
206   local $/;
207   open(my $fh , '<', $_[0]) || die "Can't open $_[0] for read";
208   my $file = <$fh>;
209   close $fh;
210   return $file;
211 }
212
213 __END__
214
215
216 =head1 SEE ALSO
217
218 Makefile.PL, ExtUtils::MakeMaker(3)
219
220 =head1 AUTHOR
221
222 MJ Ray mjr at phonecoop.coop
223
224 =cut