Add missing auto_install features to new installer
[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 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.
9 #
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.
13 #
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
17 #
18 # Current maintainer MJR http://mjr.towers.org.uk/
19 # See http://www.koha.org/wiki/?page=KohaInstaller
20
21 use Sys::Hostname;
22 use Socket;
23
24 =head1 NAME
25
26 rewrite-config.PL - helper for the Koha packager and installer
27
28 =head1 SYNOPSIS
29
30         perl rewrite-config.PL configurationfile
31
32 =head1 DESCRIPTION
33
34 This helper script replaces placeholders in the
35 configuration files with value either supplied through
36 the environment (with export, or by putting them on
37 the start of the make command linke) or with reasonable
38 guesses worked out by the script.
39
40 =head2 KEYS
41
42 The following configuration keys are available:
43
44 BASE_DIR, MYSQL_DB, MYSQL_HOST, MYSQL_PASS, MYSQL_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
45 WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
46
47 =cut
48
49 $myhost = hostname();
50 $mydomain = $myhost;
51 $mydomain =~ s/^.*?\.//;
52
53 # These are our configuration guesses
54 # Keys were extracted by
55 # <grep -o '__.*__' etc/* | cut -f2 -d: | sort -u | sed -e 's/^/  "/;s/$/" => "",/'
56 %configuration = (
57   "__BASE_DIR__" => sprintf("/usr/lib/perl5/site-perl/%vd/koha",$^V),
58   "__MYSQL_DB__" => "koha",
59   "__MYSQL_HOST__" => $myhost,
60   "__MYSQL_PASS__" => "katikoan",
61   "__MYSQL_USER__" => "kohaadmin",
62   "__WEBMASTER_EMAIL__" => 'webmaster@'.$mydomain,
63   "__WEBSERVER_DOMAIN__" => $mydomain,
64   "__WEBSERVER_HOST__" => $myhost,
65   # This is set like this to rescue systems with broken DNS
66   "__WEBSERVER_IP__" => $ENV{'WEBSERVER_IP'} || inet_ntoa(scalar gethostbyname($myhost||'localhost')) || die "Cannot get our own IP address: DNS fault?",
67   "__WEBSERVER_PORT__" => 80,
68   "__WEBSERVER_PORT_LIBRARIAN__" => 8080,
69   "__ZEBRA_PASS__" => "zebrastripes",
70   "__ZEBRA_USER__" => "kohauser",
71 );
72
73 # Override configuration from the environment
74 foreach $key (keys %configuration) {
75   if (defined($ENV{$key})) {
76     $configuration{$key} = $ENV{$key};
77   }
78 }
79
80 $fname = $ARGV[0];
81 $file = read_file($fname);
82 $file =~ s/__.*?__/$configuration{$&}/seg;
83 chmod 0644, $fname;
84 open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
85 print OUTPUT $file;
86 close(OUTPUT);
87
88 # Idea taken from perlfaq5
89 sub read_file($) {
90   local(*INPUT,$/);
91   open(INPUT,$_[0]) || die "Can't open $_[0] for read";
92   my $file = <INPUT>;
93   return $file;
94 }
95
96 __END__
97
98
99 =head1 SEE ALSO
100
101 Makefile.PL, ExtUtils::MakeMaker(3)
102
103 =head1 AUTHOR
104
105 MJ Ray mjr at phonecoop.coop
106
107 =cut
108