-
Notifications
You must be signed in to change notification settings - Fork 36
/
Makefile.PL
196 lines (171 loc) · 6.41 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
use strict;
my @ALLOWED_ARGS = ('LOGFILE','BINDIR','ETCDIR', 'CONFDIR','HTMLDIR','BASEURL','DOCDIR','MANDIR','QUIET','INSTALLDIRS','DESTDIR');
# Parse command line arguments and store them as environment variables
while ($_ = shift) {
my ($k,$v) = split(/=/, $_, 2);
if (grep(/^$k$/, @ALLOWED_ARGS)) {
$ENV{$k} = $v;
}
}
$ENV{DESTDIR} =~ s/\/$//;
# Search for default log dir
my $default_log = '/var/log/squid/access.log';
if (! -d $default_log ) {
$default_log = '/var/log/squid3/access.log';
}
# Default install path
my $LOGFILE = $ENV{LOGFILE} || $default_log;
my $BINDIR = $ENV{BINDIR} || '/usr/local/bin';
my $CONFDIR = $ENV{CONFDIR} || '/etc/squidanalyzer';
my $ETCDIR = $ENV{ETCDIR} || $CONFDIR;
my $HTMLDIR = $ENV{HTMLDIR} || '/var/www/squidanalyzer';
my $BASEURL = $ENV{BASEURL} || '/squidreport';
my $DOCDIR = $ENV{DOCDIR} || '';
my $MANDIR = $ENV{MANDIR} || '/usr/local/man/man3';
my $DESTDIR = $ENV{DESTDIR} || '';
my $INSTALLDIRS = $ENV{INSTALLDIRS} ||= 'site';
unless(open(INST, ">install_all.sh")) {
print "\nError: can't write post install file install_all.sh, $!\n";
exit 0;
}
print INST qq{#!/bin/sh
test ! -d "$DESTDIR$BINDIR" && mkdir -p $DESTDIR$BINDIR
test ! -d "$DESTDIR$ETCDIR" && mkdir -p $DESTDIR$ETCDIR
test ! -d "$DESTDIR$ETCDIR/lang" && mkdir -p $DESTDIR$ETCDIR/lang
test ! -d "$DESTDIR$HTMLDIR" && mkdir -p $DESTDIR$HTMLDIR
test ! -d "$DESTDIR$HTMLDIR/images" && mkdir -p $DESTDIR$HTMLDIR/images
};
if ($DOCDIR ne '') {
print INST qq{
test ! -d "$DESTDIR$DOCDIR" && mkdir -p $DESTDIR$DOCDIR
};
}
print INST qq{
test ! -d "$DESTDIR$MANDIR" && mkdir -p $DESTDIR$MANDIR
# Copy files that must not be overriden
for file in squidanalyzer.conf network-aliases user-aliases url-aliases excluded included; do
if [ -r $DESTDIR$ETCDIR/\$file ]; then
install -m 644 etc/\$file $DESTDIR$ETCDIR/\$file.sample
else
install -m 644 etc/\$file $DESTDIR$ETCDIR/\$file
fi
done
install -m 755 squid-analyzer $DESTDIR$BINDIR/
install -m 644 resources/sorttable.js $DESTDIR$HTMLDIR/
install -m 644 resources/squidanalyzer.css $DESTDIR$HTMLDIR/
install -m 644 resources/flotr2.js $DESTDIR$HTMLDIR/
install -m 644 resources/images/logo-squidanalyzer.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/cursor.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/domain.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/back-arrow.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/info.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/network.png $DESTDIR$HTMLDIR/images/
install -m 644 resources/images/user.png $DESTDIR$HTMLDIR/images/
install -m 644 lang/* $DESTDIR$ETCDIR/lang/
pod2text doc/SquidAnalyzer.pod README
pod2man doc/SquidAnalyzer.pod squid-analyzer.3
};
if ($DOCDIR ne '') {
print INST qq{
install -m 644 README $DESTDIR$DOCDIR/
install -m 644 INSTALL $DESTDIR$DOCDIR/
install -m 644 ChangeLog $DESTDIR$DOCDIR/
};
}
if ($MANDIR ne '') {
print INST qq{
install -m 644 squid-analyzer.3 $DESTDIR$MANDIR/
};
}
if (!$ENV{QUIET}) {
print INST qq{
echo "
-----------------------------------------------------------------------------
1. Modify your httpd.conf to allow access to HTML output like follow:
Alias /squidreport $HTMLDIR
<Directory $HTMLDIR>
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
2. If necessary, give additional host access to SquidAnalyzer in httpd.conf.
Restart and ensure that httpd is running.
3. Browse to http://my.host.dom/squidreport/ to ensure that things are working
properly.
4. Setup a cronjob to run squid-analyzer daily:
# SquidAnalyzer log reporting daily
0 2 * * * $BINDIR/squid-analyzer > /dev/null 2>&1
or run it manually. For more information, see $DOCDIR/README file.
-----------------------------------------------------------------------------
"
};
}
close(INST);
`chmod 755 install_all.sh`;
# Change path into the default configuration file
`perl -p -i -e 's#/.*/squidanalyzer.conf#$ETCDIR/squidanalyzer.conf#' etc/squidanalyzer.conf squid-analyzer`;
`perl -p -i -e 's#^Output.*#Output $HTMLDIR#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^LogFile.*#LogFile $LOGFILE#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^WebUrl.*#WebUrl $BASEURL#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^NetworkAlias.*#NetworkAlias $ETCDIR/network-aliases#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^UserAlias.*#UserAlias $ETCDIR/user-aliases#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^Exclude.*#Exclude $ETCDIR/excluded#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#^Include.*#Include $ETCDIR/included#' etc/squidanalyzer.conf`;
`perl -p -i -e 's#Lang.*\.txt#Lang $ETCDIR/lang/en_US.txt#' etc/squidanalyzer.conf`;
my $zcat = `which zcat`;
chomp($zcat);
`perl -p -i -e 's#^\\\$ZCAT_PROG.*#\\\$ZCAT_PROG = "$zcat";#' SquidAnalyzer.pm`;
my $bzcat = `which bzcat`;
chomp($bzcat);
`perl -p -i -e 's#^\\\$BZCAT_PROG.*#\\\$BZCAT_PROG = "$bzcat";#' SquidAnalyzer.pm`;
my $xzcat = `which xzcat`;
chomp($xzcat);
`perl -p -i -e 's#^\\\$XZCAT_PROG.*#\\\$XZCAT_PROG = "$xzcat";#' SquidAnalyzer.pm`;
WriteMakefile(
'DISTNAME' => 'SquidAnalyzer',
'NAME' => 'SquidAnalyzer',
'VERSION_FROM' => 'SquidAnalyzer.pm',
'dist' => {
'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz',
'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl'
},
'AUTHOR' => 'Gilles Darold ([email protected])',
'ABSTRACT' => 'Squid log analyzer',
'EXE_FILES' => [ qw(squid-analyzer) ],
'MAN3PODS' => { 'doc/SquidAnalyzer.pod' => 'blib/man3/SquidAnalyzer.3pm' },
'DESTDIR' => $DESTDIR,
'INSTALLDIRS' => $INSTALLDIRS,
'clean' => { FILES => "install_all.sh lib/blib/ squid-analyzer.3" },
'META_MERGE' => {
resources => {
homepage => 'http://squidanalyzer.darold.net/',
repository => {
type => 'git',
git => '[email protected]:darold/squidanalyzer.git',
web => 'https://github.com/darold/squidanalyzer',
},
},
}
);
sub MY::install {
my $self = shift;
my $string = $self->MM::install;
$string =~ s/(pure_install\s+)(.*)/$1 install_all $2/;
return $string;
}
sub MY::postamble {
my $postamble = <<'END';
install_all: install_all.sh
sh install_all.sh
END
return $postamble;
}
if (!$ENV{QUIET}) {
print "Done...\n\n";
print "Now type 'make && make install'\n\n";
}