Changing CanBookBeRenewed to pass back the reason a renewal cannot proceed
[koha.git] / rewrite-config.PL
bloba55ed1f81cfdaffd164eb25a368ac8f61f3af478
1 # Copyright 2007 MJ Ray
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
18 # Current maintainer MJR http://mjr.towers.org.uk/
19 # See http://www.koha.org/wiki/?page=KohaInstaller
20
21 # 2007/11/12    Added DB_PORT and changed other keywords to reflect multi-dbms support. -fbcit
23 use Sys::Hostname;
24 use Socket;
26 =head1 NAME
28 rewrite-config.PL - helper for the Koha packager and installer
30 =head1 SYNOPSIS
32         perl rewrite-config.PL configurationfile
34 =head1 DESCRIPTION
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.
42 =head2 KEYWORDS
44 The following configuration keywords are available:
46 PREFIX,
47 BASE_DIR, CGI_DIR, LOG_DIR, INSTALL_BASE,
48 DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
49 WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
51 =head1 EXAMPLES
53 To override the guessed hostname and email address, run:
55         WEBSERVER_HOST=mysecrethostname.com.invalid \
56         WEBMASTER_EMAIL=webmaster@publichost.com make install
58 Note that if WEBSERVER_HOST does not resolve to an IP address, you will
59 also need to override WEBSERVER_IP.
61 =cut
63 $myhost = hostname();
64 $mydomain = $myhost;
65 $mydomain =~ s/^.*?\.//;
66 # This is set here to rescue systems with broken DNS
67 $myip = $ENV{'WEBSERVER_IP'} || inet_ntoa(scalar gethostbyname($myhost||'localhost')) || die "Cannot get our own IP address: DNS fault?";
68 $prefix = $ENV{'INSTALL_BASE'} || "/usr";
70 # These are our configuration guesses
71 # Keys were extracted by
72 # <grep -o '__.*__' etc/* | cut -f2 -d: | sort -u | sed -e 's/^/  "/;s/$/" => "",/'
73 %configuration = (
74   "__LOG_DIR__" => "/var/log",
75   "__DB_TYPE__" => "mysql",
76   "__DB_NAME__" => "koha",
77   "__DB_HOST__" => $myhost,
78   "__DB_PORT__" => "3306",
79   "__DB_USER__" => "kohaadmin",
80   "__DB_PASS__" => "katikoan",
81   "__WEBMASTER_EMAIL__" => 'webmaster@'.$mydomain,
82   "__WEBSERVER_DOMAIN__" => $mydomain,
83   "__WEBSERVER_HOST__" => $myhost,
84   "__WEBSERVER_IP__" => $myip,
85   "__WEBSERVER_PORT__" => "80",
86   "__WEBSERVER_PORT_LIBRARIAN__" => "8080",
87   "__ZEBRA_SRU_HOST__" => $myhost,
88   "__ZEBRA_SRU_BIBLIOS_PORT__" => "9998",
89   "__ZEBRA_SRU_AUTHORITIES_PORT__" => "9999",
90   "__KOHA_USER__" => "koha",
91   "__KOHA_GROUP__" => "koha",
92   "__ZEBRA_PASS__" => "zebrastripes",
93   "__ZEBRA_USER__" => "kohauser",
94   '__INTRANET_CGI_DIR__' => "$prefix/intranet/cgi-bin",
95   '__INTRANET_TMPL_DIR__' => "$prefix/intranet/templates",
96   '__INTRANET_WWW_DIR__' => "$prefix/intranet/www",
97   '__OPAC_CGI_DIR__' => "$prefix/opac/cgi-bin",
98   '__OPAC_TMPL_DIR__' => "$prefix/opac/templates",
99   '__OPAC_WWW_DIR__' => "$prefix/opac/www",
100   '__PERL_MODULE_DIR__' =>  ($ENV{'INSTALLSITELIB'} || sprintf($prefix."/lib/perl5/site_perl/%vd",$^V))."/koha",
101   '__KOHA_CONF_DIR__' => "$prefix/etc/koha",
102   '__ZEBRA_CONF_DIR__' => "$prefix/etc/koha/zebradb",
103   '__MISC_DIR__' => "$prefix/misc",
104   '__SCRIPT_DIR__' => "$prefix/bin",
105   '__MAN_DIR__' => "$prefix/man",
106   '__DOC_DIR__' => "$prefix/doc",
107   '__ZEBRA_LOCK_DIR__' => "$prefix/var/lock/zebradb",
108   '__ZEBRA_DATA_DIR__' => "$prefix/var/lib/zebradb",
109   '__ZEBRA_RUN_DIR__' => "$prefix/var/run/zebradb",
110   '__ZEBRA_MARC_FORMAT__' => 'marc21',
111   '__ZEBRA_LANGUAGE__' => 'en',
114 # Override configuration from the environment
115 foreach $key (keys %configuration) {
116   if (defined($ENV{$key})) {
117     $configuration{$key} = $ENV{$key};
118   }
121 $fname = $ARGV[0];
122 $file = read_file($fname);
123 $file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg;
125 # At this point, file is in 'blib' and by default
126 # has mode a-w.  Therefore, must change permission
127 # to make it writable.  Note that stat and chmod
128 # (the Perl functions) should work on Win32
129 my $old_perm;
130 $old_perm = (stat $fname)[2] & 07777;
131 my $new_perm = $old_perm | 0200;
132 chmod $new_perm, $fname;
134 open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
135 print OUTPUT $file;
136 close(OUTPUT);
138 chmod $old_perm, $fname;
140 # Idea taken from perlfaq5
141 sub read_file($) {
142   local(*INPUT,$/);
143   open(INPUT,$_[0]) || die "Can't open $_[0] for read";
144   my $file = <INPUT>;
145   return $file;
148 __END__
151 =head1 SEE ALSO
153 Makefile.PL, ExtUtils::MakeMaker(3)
155 =head1 AUTHOR
157 MJ Ray mjr at phonecoop.coop
159 =cut