Skip to content
Newer
Older
100644 120 lines (91 sloc) 3.31 KB
e449c13 @mjray Add configuration file helper to the installer
mjray authored
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
61190e9 @mjray New installation instructions and release notes.
mjray authored
34 This helper script replaces keywords in the
e449c13 @mjray Add configuration file helper to the installer
mjray authored
35 configuration files with value either supplied through
36 the environment (with export, or by putting them on
61190e9 @mjray New installation instructions and release notes.
mjray authored
37 the start of the make command line) or with reasonable
e449c13 @mjray Add configuration file helper to the installer
mjray authored
38 guesses worked out by the script.
39
61190e9 @mjray New installation instructions and release notes.
mjray authored
40 =head2 KEYWORDS
e449c13 @mjray Add configuration file helper to the installer
mjray authored
41
61190e9 @mjray New installation instructions and release notes.
mjray authored
42 The following configuration keywords are available:
e449c13 @mjray Add configuration file helper to the installer
mjray authored
43
28695e9 @mjray Add missing auto_install features to new installer
mjray authored
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
e449c13 @mjray Add configuration file helper to the installer
mjray authored
46
61190e9 @mjray New installation instructions and release notes.
mjray authored
47 =head1 EXAMPLES
48
49 To override the guessed hostname and email address, run:
50
51 WEBSERVER_HOST=mysecrethostname.com.invalid \
52 WEBMASTER_EMAIL=webmaster@publichost.com make install
53
54 Note that if WEBSERVER_HOST does not resolve to an IP address, you will
55 also need to override WEBSERVER_IP.
56
e449c13 @mjray Add configuration file helper to the installer
mjray authored
57 =cut
58
59 $myhost = hostname();
60 $mydomain = $myhost;
61 $mydomain =~ s/^.*?\.//;
cecd7ef @mjray BUGFIX: set all configuration keys - die terminated the hash
mjray authored
62 # This is set here to rescue systems with broken DNS
63 $myip = $ENV{'WEBSERVER_IP'} || inet_ntoa(scalar gethostbyname($myhost||'localhost')) || die "Cannot get our own IP address: DNS fault?";
e449c13 @mjray Add configuration file helper to the installer
mjray authored
64
65 # These are our configuration guesses
66 # Keys were extracted by
67 # <grep -o '__.*__' etc/* | cut -f2 -d: | sort -u | sed -e 's/^/ "/;s/$/" => "",/'
68 %configuration = (
69 "__BASE_DIR__" => sprintf("/usr/lib/perl5/site-perl/%vd/koha",$^V),
70 "__MYSQL_DB__" => "koha",
71 "__MYSQL_HOST__" => $myhost,
72 "__MYSQL_PASS__" => "katikoan",
73 "__MYSQL_USER__" => "kohaadmin",
28695e9 @mjray Add missing auto_install features to new installer
mjray authored
74 "__WEBMASTER_EMAIL__" => 'webmaster@'.$mydomain,
e449c13 @mjray Add configuration file helper to the installer
mjray authored
75 "__WEBSERVER_DOMAIN__" => $mydomain,
76 "__WEBSERVER_HOST__" => $myhost,
cecd7ef @mjray BUGFIX: set all configuration keys - die terminated the hash
mjray authored
77 "__WEBSERVER_IP__" => $myip,
78 "__WEBSERVER_PORT__" => "80",
79 "__WEBSERVER_PORT_LIBRARIAN__" => "8080",
e449c13 @mjray Add configuration file helper to the installer
mjray authored
80 "__ZEBRA_PASS__" => "zebrastripes",
81 "__ZEBRA_USER__" => "kohauser",
82 );
83
84 # Override configuration from the environment
85 foreach $key (keys %configuration) {
86 if (defined($ENV{$key})) {
87 $configuration{$key} = $ENV{$key};
88 }
89 }
90
91 $fname = $ARGV[0];
92 $file = read_file($fname);
93 $file =~ s/__.*?__/$configuration{$&}/seg;
94 chmod 0644, $fname;
95 open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
96 print OUTPUT $file;
97 close(OUTPUT);
98
99 # Idea taken from perlfaq5
100 sub read_file($) {
101 local(*INPUT,$/);
102 open(INPUT,$_[0]) || die "Can't open $_[0] for read";
103 my $file = <INPUT>;
104 return $file;
105 }
106
107 __END__
108
109
110 =head1 SEE ALSO
111
112 Makefile.PL, ExtUtils::MakeMaker(3)
113
114 =head1 AUTHOR
115
116 MJ Ray mjr at phonecoop.coop
117
118 =cut
119
Something went wrong with that request. Please try again.