-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·306 lines (260 loc) · 11.4 KB
/
configure
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw//;
eval "use inc::Module::Install";
if($@ && !-e 'Makefile') {
print STDERR "Module::Install is required to build Thruk from source.\n\n";
print STDERR $@;
exit 1;
}
alarm(180);
my $options = {
'prefix' => '/usr/local',
'htmlurl' => '/thruk',
'unsafeallow3f' => '',
'nounsafeallow3f' => '',
'thruk-user' => `id -un`,
'thruk-group' => `id -gn`,
'httpd-conf' => '',
'logrotatedir' => '',
'bashcompldir' => '',
'quiet' => 0,
};
Getopt::Long::Configure('no_ignore_case');
Getopt::Long::Configure('bundling');
Getopt::Long::Configure('pass_through');
Getopt::Long::GetOptions (
"h|help" => \$options->{'help'},
"v|verbose" => sub { $options->{'verbose'}++ },
"prefix=s" => \$options->{'prefix'},
"exec-prefix=s" => \$options->{'eprefix'},
"bindir=s" => \$options->{'bindir'},
"libdir=s" => \$options->{'libdir'},
"sysconfdir=s" => \$options->{'sysconfdir'},
"localstatedir=s" => \$options->{'localstatedir'},
"datadir=s" => \$options->{'datadir'},
"mandir=s" => \$options->{'mandir'},
"with-tempdir=s" => \$options->{'tmpdir'},
"with-initdir=s" => \$options->{'initdir'},
"with-logrotatedir=s" => \$options->{'logrotatedir'},
"with-logdir=s" => \$options->{'logdir'},
"with-htmlurl=s" => \$options->{'htmlurl'},
"with-httpd-conf=s" => \$options->{'httpd-conf'},
"with-unsafeallow3f" => \$options->{'unsafeallow3f'},
"without-unsafeallow3f" => \$options->{'nounsafeallow3f'},
"with-checkresultdir=s" => \$options->{'checkresultdir'},
"with-bashcompletedir=s" => \$options->{'bashcompldir'},
"with-thruk-user=s" => \$options->{'thruk-user'},
"with-thruk-group=s" => \$options->{'thruk-group'},
"with-thruk-libs=s" => \$options->{'thruk-libs'},
"with-thruk-tempdir=s" => \$options->{'thruk-tempdir'},
"with-thruk-vardir=s" => \$options->{'thruk-vardir'},
"with-thruk-logdir=s" => \$options->{'thruk-logdir'},
"without-compress" => \$options->{'nocompress'},
"without-thruk-libs" => \$options->{'nolibs'},
"quiet|q" => \$options->{'quiet'},
) or warn "error in options";
if($options->{'help'}) {
require Pod::Usage;
Pod::Usage::pod2usage( { -verbose => 2, -exit => 3 } );
}
if($options->{'nocompress'}) {
warn("*** deprecated: --without-compress is deprecated and no longer required.");
}
$options->{'initdir'} = $options->{'initdir'} || $options->{'prefix'}.'/etc/init.d';
$options->{'logdir'} = $options->{'logdir'} || $options->{'prefix'}.'/var/log/thruk';
$options->{'thruk-libs'} = $options->{'thruk-libs'} || $options->{'prefix'}.'/lib/thruk/perl5';
$options->{'checkresultdir'} = $options->{'checkresultdir'} || $options->{'prefix'}.'/var/cache/naemon/checkresults';
$options->{'eprefix'} = $options->{'prefix'} unless $options->{'eprefix'};
$options->{'bindir'} = $options->{'prefix'}.'/bin' unless $options->{'bindir'};
$options->{'sysconfdir'} = $options->{'prefix'}.'/etc' unless $options->{'sysconfdir'};
$options->{'tmpdir'} = $options->{'prefix'}.'/tmp' unless $options->{'tmpdir'};
$options->{'localstatedir'} = $options->{'prefix'}.'/var' unless $options->{'localstatedir'};
$options->{'libdir'} = $options->{'prefix'}.'/lib' unless $options->{'libdir'};
$options->{'datadir'} = $options->{'prefix'}.'/share' unless $options->{'datadir'};
$options->{'mandir'} = $options->{'prefix'}.'/man' unless $options->{'mandir'};
$options->{'tmpdir'} = $options->{'thruk-tempdir'} if $options->{'thruk-tempdir'};
$options->{'localstatedir'} = $options->{'thruk-vardir'} if $options->{'thruk-vardir'};
$options->{'logdir'} = $options->{'thruk-logdir'} if $options->{'thruk-logdir'};
chomp($options->{'thruk-user'});
chomp($options->{'thruk-group'});
$options->{'htmlurl'} =~ s|/+$||mx;
$options->{'htmlurl'} =~ s|^/+||mx;
$options->{'htmlurl'} = '/'.$options->{'htmlurl'};
$options->{'compress'} = $options->{'nocompress'} ? 'disabled' : 'enabled';
$options->{'thruk-libs'} = '' if $options->{'nolibs'};
# recent apaches might require the UnsafeAllow3F flag
if(!$options->{'nounsafeallow3f'} && !$options->{'unsafeallow3f'}) {
# try to autodetect
my($os, $ver) = _get_os();
if($os eq 'rhel' && $ver >= 8) {
$options->{'unsafeallow3f'} = 1;
}
if($os eq 'debian' && ($ver eq 'sid' || $ver >= 11)) {
$options->{'unsafeallow3f'} = 1;
}
}
if($options->{'nounsafeallow3f'}) {
$options->{'unsafeallow3f'} = '';
}
if($options->{'unsafeallow3f'}) {
$options->{'unsafeallow3f'} = ',UnsafeAllow3F';
}
open(my $fh, '>', 'script/Makefile.options') or die("cannot write to: script/Makefile.options:".$!);
print $fh <<EOT;
### THRUK
PREFIX = $options->{'prefix'}
EPREFIX = $options->{'eprefix'}
BINDIR = $options->{'bindir'}
SYSCONFDIR = $options->{'sysconfdir'}
LIBDIR = $options->{'libdir'}
TMPDIR = $options->{'tmpdir'}
LOCALSTATEDIR = $options->{'localstatedir'}
DATADIR = $options->{'datadir'}
MANDIR = $options->{'mandir'}
INITDIR = $options->{'initdir'}
LOGROTATEDIR = $options->{'logrotatedir'}
LOGDIR = $options->{'logdir'}
HTMLURL = $options->{'htmlurl'}
HTTPDCONF = $options->{'httpd-conf'}
BASHCOMPLDIR = $options->{'bashcompldir'}
THRUKUSER = $options->{'thruk-user'}
THRUKGROUP = $options->{'thruk-group'}
THRUKLIBS = $options->{'thruk-libs'}
CHECKRESULTDIR = $options->{'checkresultdir'}
THRUKCOMPRESS = $options->{'compress'}
UNSAFEALLOW3F = $options->{'unsafeallow3f'}
EOT
close($fh);
unlink("Makefile");
my $out = `yes n | $^X Makefile.PL 2>&1`;
if(!-e "Makefile") {
print "configure failed:\n\n";
print $out;
exit 1;
}
# check our modules if not modules are build
if($options->{'nolibs'}) {
$out = `make checkdeps 2>&1`;
if($out =~ m/Warning:\sprerequisite/mx) {
print $out;
unlink("Makefile");
print "ERROR: missing dependencies, see list above for details\n";
exit 1;
}
}
exit if $options->{'quiet'};
$options->{'httpd-conf'} = '** not installed **' unless $options->{'httpd-conf'};
$options->{'logrotatedir'} = '** not installed **' unless $options->{'logrotatedir'};
$options->{'bashcompldir'} = '** not installed **' unless $options->{'bashcompldir'};
print <<EOT;
*************************************
* THRUK - configuration
*************************************
eprefix = $options->{'eprefix'}
bindir = $options->{'bindir'}
sysconfdir = $options->{'sysconfdir'}
libdir = $options->{'libdir'}
tmpdir = $options->{'tmpdir'}
localstatedir = $options->{'localstatedir'}
datadir = $options->{'datadir'}
mandir = $options->{'mandir'}
initdir = $options->{'initdir'}
logrotatedir = $options->{'logrotatedir'}
logdir = $options->{'logdir'}
htmlurl = $options->{'htmlurl'}
httpd-conf = $options->{'httpd-conf'}
unsafeallow3f = $options->{'unsafeallow3f'}
thruk-user = $options->{'thruk-user'}
thruk-group = $options->{'thruk-group'}
thruk-libs = $options->{'thruk-libs'}
checkresultdir = $options->{'checkresultdir'}
now run
make
make install
to install thruk with these settings.
EOT
exit;
# try to detect os and version
sub _get_os {
my($os, $version) = ("", 0);
local $/ = undef;
# right now, we only need rhel/rocky/alma
if(-e '/etc/redhat-release') {
my $release_file = '/etc/redhat-release';
open(my $fh, '<', $release_file) or die("cannot read $release_file: $!");
my $release_info = <$fh>;
close $fh;
if ($release_info =~ /^(.*?)(?: release)? ([\d.]+)/) {
my $version = $2;
$version =~ s/\..*$//gmx; # we only need the major number
return("rhel", 0+$version);
} else {
die(sprintf("Unable to detect distribution and version from %s:\n%s", $release_file, $release_info));
}
} elsif(-e '/etc/os-release') {
my $release_file = '/etc/os-release';
open(my $fh, '<', $release_file) or die("cannot read $release_file: $!");
my $release_info = <$fh>;
close $fh;
for my $line (split/\n/mx, $release_info) {
if($line =~ /^ID="?(.*?)"?$/mx) {
$os = $1;
}
if($line =~ /^VERSION_ID="?(.*?)"?$/mx) {
$version = $1;
$version =~ s/\..*$//gmx; # we only need the major number
}
if($line =~ /^PRETTY_NAME=.*\/sid\"$/mx) {
$version = "sid";
}
}
if ($os && $version) {
return($os, $version) if $version eq 'sid';
return($os, 0+$version);
} else {
die(sprintf("Unable to detect distribution and version from %s:\n%s", $release_file, $release_info));
}
}
return($os, $version);
}
1;
__END__
##############################################
=head1 SYNOPSIS
Usage: configure [options]
Options:
-h, --help Show this help message and exit
-v, --verbose Print verbose output
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local/' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--datadir=DIR read-only architecture-independent data [PREFIX/share]
--mandir=DIR man documentation [DATADIR/man]
Optional Settings:
--with-htmlurl=<local-url> sets URL for public html [/thruk]
--with-tempdir sets the temp folder [PREFIX/tmp]
--with-initdir sets the folder for rc scripts
--with-httpd-conf sets path to Apache conf.d directory
--with-logrotatedir sets path to logrotates.d directory
--with-logdir sets path to log files [PREFIX/var/log/thruk]
--with-thruk-libs sets path to thruk libs directory [PREFIX/lib/thruk/perl5]
--with-thruk-user sets user name to run thruk [thruk]
--with-thruk-group sets group name to run thruk [thruk]
--with-checkresultdir sets path to Naemon/Nagios/Icinga/Shinken checkresult directory [PREFIX/var/cache/naemon/checkresults]
--without-thruk-libs skip building the required perl modules. Make sure you add dependencies accordingly
--with(out)-unsafeallow3f enable/disable apache mod_rewrite flag UnsafeAllow3F
=cut