Bug 11592: Add should_hide_marc method to filter
[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 Sys::Hostname;
23 use Socket;
24
25 =head1 NAME
26
27 rewrite-config.PL - helper for the Koha packager and installer
28
29 =head1 SYNOPSIS
30
31         perl rewrite-config.PL configurationfile
32
33 =head1 DESCRIPTION
34
35 This helper script replaces keywords in the
36 configuration files with value either supplied through
37 the environment (with export, or by putting them on
38 the start of the make command line) or with reasonable
39 guesses worked out by the script.
40
41 =head2 KEYWORDS
42
43 The following configuration keywords are available:
44
45 PREFIX,
46 BASE_DIR, CGI_DIR, LOG_DIR, PLUGINS_DIR, INSTALL_BASE,
47 DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
48 WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
49
50 =head1 EXAMPLES
51
52 To override the guessed hostname and email address, run:
53
54         WEBSERVER_HOST=mysecrethostname.com.invalid \
55         WEBMASTER_EMAIL=webmaster@publichost.com make install
56
57 Note that if WEBSERVER_HOST does not resolve to an IP address, you will
58 also need to override WEBSERVER_IP.
59
60 =cut
61
62 if ( $myhost = $ENV{WEBSERVER_HOST} || hostname ) {
63     ( $mydomain = $myhost ) =~ s/.*?\.//;
64 } else {
65     $myhost   = 'localhost';
66     $mydomain = 'localdomain';
67 }
68
69 unless ( $myip = $ENV{WEBSERVER_IP} ) {
70     my $byname = gethostbyname( $myhost )
71         or die "Could not get the IP address of $myhost, DNS fault? ($!)";
72     $myip = inet_ntoa $byname
73         or die "can't inet_ntoa ($!)";
74 }
75
76
77 $prefix = $ENV{'INSTALL_BASE'} || "/usr";
78
79 # These are our configuration guesses
80 # Keys were extracted by
81 # <grep -o '__.*__' etc/* | cut -f2 -d: | sort -u | sed -e 's/^/  "/;s/$/" => "",/'
82 %configuration = (
83   "__KOHA_INSTALLED_VERSION__" => "no_version_found",
84   "__LOG_DIR__" => "/var/log",
85   "__PLUGINS_DIR__" => "/var/lib/koha/plugins",
86   "__DB_TYPE__" => "mysql",
87   "__DB_NAME__" => "koha",
88   "__DB_HOST__" => $myhost,
89   "__DB_PORT__" => "3306",
90   "__DB_USER__" => "kohaadmin",
91   "__DB_PASS__" => "katikoan",
92   "__WEBMASTER_EMAIL__" => 'webmaster@'.$mydomain,
93   "__WEBSERVER_DOMAIN__" => $mydomain,
94   "__WEBSERVER_HOST__" => $myhost,
95   "__WEBSERVER_IP__" => $myip,
96   "__WEBSERVER_PORT__" => "80",
97   "__WEBSERVER_PORT_LIBRARIAN__" => "8080",
98   "__ZEBRA_SRU_HOST__" => $myhost,
99   "__ZEBRA_SRU_BIBLIOS_PORT__" => "9998",
100   "__ZEBRA_SRU_AUTHORITIES_PORT__" => "9999",
101   "__KOHA_USER__" => "koha",
102   "__KOHA_GROUP__" => "koha",
103   "__ZEBRA_PASS__" => "zebrastripes",
104   "__ZEBRA_USER__" => "kohauser",
105   '__BACKUP_DIR__' => "$prefix/var/spool",
106   '__API_CGI_DIR__' => "$prefix/api",
107   '__INTRANET_CGI_DIR__' => "$prefix/intranet/cgi-bin",
108   '__INTRANET_TMPL_DIR__' => "$prefix/intranet/templates",
109   '__INTRANET_WWW_DIR__' => "$prefix/intranet/www",
110   '__OPAC_CGI_DIR__' => "$prefix/opac/cgi-bin",
111   '__OPAC_TMPL_DIR__' => "$prefix/opac/templates",
112   '__OPAC_WWW_DIR__' => "$prefix/opac/www",
113   '__PERL_MODULE_DIR__' =>  ($ENV{'INSTALLSITELIB'} || sprintf($prefix."/lib/perl5/site_perl/%vd",$^V))."/koha",
114   '__KOHA_CONF_DIR__' => "$prefix/etc/koha",
115   '__ZEBRA_CONF_DIR__' => "$prefix/etc/koha/zebradb",
116   '__PAZPAR2_CONF_DIR__' => "$prefix/etc/koha/pazpar2",
117   '__MISC_DIR__' => "$prefix/misc",
118   '__SCRIPT_DIR__' => "$prefix/bin",
119   '__SCRIPT_NONDEV_DIR__' => "$prefix/bin",
120   '__MAN_DIR__' => "$prefix/man",
121   '__DOC_DIR__' => "$prefix/doc",
122   '__ZEBRA_LOCK_DIR__' => "$prefix/var/lock/zebradb",
123   '__ZEBRA_DATA_DIR__' => "$prefix/var/lib/zebradb",
124   '__ZEBRA_RUN_DIR__' => "$prefix/var/run/zebradb",
125   '__ZEBRA_MARC_FORMAT__' => 'marc21',
126   '__ZEBRA_LANGUAGE__' => 'en',
127   '__ZEBRA_TOKENIZER__' => 'chr',
128   '__ZEBRA_TOKENIZER_STMT__' => 'charmap word-phrase-utf.chr',
129   '__ZEBRA_PTOKENIZER_STMT__' => 'charmap word-phrase-utf.chr',
130   '__ZEBRA_AUTH_CFG__' => 'zebra-authorities.cfg',
131   '__ZEBRA_BIB_CFG__' => 'zebra-biblios.cfg',
132   '__AUTH_RETRIEVAL_CFG__' => 'retrieval-info-auth-grs1.xml',
133   '__BIB_RETRIEVAL_CFG__' => 'retrieval-info-bib-grs1.xml',
134   "__MERGE_SERVER_HOST__" => $myhost,
135   "__MERGE_SERVER_PORT__" => '11001',
136   "__PAZPAR2_HOST__" => $myhost,
137   "__PAZPAR2_PORT__" => '11002',
138   "__INSTALL_MODE__" => 'standard',
139   "__INSTALL_BASE__" => '/usr/share/koha',
140   "__INSTALL_SRU__" => 'yes',
141   "__INSTALL_PAZPAR2__" => 'no',
142   "__PAZPAR2_TOGGLE_XML_PRE__" => '<!--',
143   "__PAZPAR2_TOGGLE_XML_POST__" => '-->',
144   "__AUTH_INDEX_MODE__" => 'grs1',
145   "__BIB_INDEX_MODE__" => 'grs1',
146   "__RUN_DATABASE_TESTS__" => 'no',
147   "__PATH_TO_ZEBRA__" => "",
148   "__USE_MEMCACHED__" => 'no',
149   "__MEMCACHED_SERVERS__" => "",
150   "__MEMCACHED_NAMESPACE__" => "",
151   "__FONT_DIR__" => "/usr/share/fonts/truetype/ttf-dejavu",
152 );
153
154 # Override configuration from the environment
155 foreach $key (keys %configuration) {
156   if (defined($ENV{$key})) {
157     $configuration{$key} = $ENV{$key};
158   }
159 }
160
161 # munge commenting out the PazPar2 mergeserver
162 # entry in koha-conf.xml if necessary
163 if ($configuration{'__INSTALL_PAZPAR2__'} eq 'yes') {
164     $configuration{'__PAZPAR2_TOGGLE_XML_PRE__'} = '';
165     $configuration{'__PAZPAR2_TOGGLE_XML_POST__'} = '';
166 }
167
168 $fname = $ARGV[0];
169 $file = &read_file($fname);
170 $file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg;
171
172 # At this point, file is in 'blib' and by default
173 # has mode a-w.  Therefore, must change permission
174 # to make it writable.  Note that stat and chmod
175 # (the Perl functions) should work on Win32
176 my $old_perm;
177 $old_perm = (stat $fname)[2] & 07777;
178 my $new_perm = $old_perm | 0200;
179 chmod $new_perm, $fname;
180
181 open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
182 print OUTPUT $file;
183 close(OUTPUT);
184
185 chmod $old_perm, $fname;
186
187 # Idea taken from perlfaq5
188 sub read_file($) {
189   local(*INPUT,$/);
190   open(INPUT,$_[0]) || die "Can't open $_[0] for read";
191   my $file = <INPUT>;
192   return $file;
193 }
194
195 __END__
196
197
198 =head1 SEE ALSO
199
200 Makefile.PL, ExtUtils::MakeMaker(3)
201
202 =head1 AUTHOR
203
204 MJ Ray mjr at phonecoop.coop
205
206 =cut