File: configure.pl

package info (click to toggle)
shorewall-lite 5.2.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 392 kB
  • sloc: sh: 1,171; xml: 262; perl: 168; makefile: 29
file content (233 lines) | stat: -rwxr-xr-x 6,187 bytes parent folder | download | duplicates (6)
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
#! /usr/bin/perl -w
#
#     Shorewall Packet Filtering Firewall configuration program - V5.2
#
#     (c) 2012, 2014 - Tom Eastep (teastep@shorewall.net)
#
#	Shorewall documentation is available at http://www.shorewall.net
#
#       This program is part of Shorewall.
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by the
#       Free Software Foundation, either version 2 of the license or, at your
#       option, any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#       Usage: ./configure.pl <option>=<setting> ...
#
#
################################################################################################
use strict;

#
# Build updates this
#
use constant {
    VERSION => '5.2.3.4'
};

my %params;
my %options;

my %aliases = ( VENDOR         => 'HOST',
		SHAREDSTATEDIR => 'VARLIB',
		DATADIR        => 'SHAREDIR' );

for ( @ARGV ) {
    die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/;

    my $pn = uc $1;
    my $pv = $2 || '';

    $pn = $aliases{$pn} if exists $aliases{$pn};

    $params{$pn} = $pv;
}

use File::Basename;
chdir dirname($0);

my $vendor = $params{HOST};
my $rcfile;
my $rcfilename;

unless ( defined $vendor ) {
    if ( -f '/etc/os-release' ) {
	my $id = `cat /etc/os-release | grep ^ID=`;

	chomp $id;

	$id =~ s/ID=//;
	
	if ( $id eq 'fedora' || $id eq 'rhel' ) {
	    $vendor = 'redhat';
	} elsif ( $id eq 'opensuse' ) {
	    $vendor = 'suse';
	} elsif ( $id eq 'ubuntu' || $id eq 'debian' ) {
	    my $init = `ls -l /sbin/init`;
	    $vendor = $init =~ /systemd/ ? 'debian.systemd' : 'debian.sysvinit';
	} elsif ( $id eq 'alt' || $id eq 'basealt' || $id eq 'altlinux' ) {
	    $vendor = 'alt';
	} else {
	    $vendor = $id;
	}
    }

    $params{HOST} = $vendor;
    $params{HOST} =~ s/\..*//;
}

if ( defined $vendor ) {
    if ( $vendor eq 'debian' && -f '/etc/debian_version' ) {
	if ( -l '/sbin/init' ) {
	    if ( readlink('/sbin/init') =~ /systemd/ ) {
		$rcfilename = 'shorewallrc.debian.systemd';
	    } else {
		$rcfilename = 'shorewallrc.debian.sysvinit';
	    }
	} else {
	    $rcfilename = 'shorewallrc.debian.sysvinit';
	}
    } else {
	$rcfilename = $vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $vendor;
    }

    unless ( -f $rcfilename ) {
	die qq("ERROR: $vendor" is not a recognized host type);
    } elsif ( $vendor eq 'default' ) {
	$params{HOST} = $vendor = 'linux';
    } elsif ( $vendor =~ /^debian\./ ) {
	$params{HOST} = $vendor = 'debian';
    }
} else {
    if ( -f '/etc/debian_version' ) {
	$vendor = 'debian';
	if ( -l '/sbin/init' ) {
	    if ( readlink( '/sbin/init' ) =~ /systemd/ ) {
		$rcfilename = 'shorewallrc.debian.systemd';
	    } else {
		$rcfilename = 'shorewallrc.debian.sysvinit';
	    }
	} else {
	    $rcfilename = 'shorewallrc.debian.sysvinit';
	}
    } elsif ( -f '/etc/altlinux-release' ){
	$vendor = 'alt';
	$rcfilename = 'shorewallrc.alt';
    } elsif ( -f '/etc/redhat-release' ){
	$vendor = 'redhat';
	$rcfilename = 'shorewallrc.redhat';
    } elsif ( -f '/etc/slackware-version' ) {
	$vendor = 'slackware';
	$rcfilename = 'shorewallrc.slackware';
    } elsif ( -f '/etc/SuSE-release' ) {
	$vendor = 'suse';
	$rcfilename = 'shorewallrc.suse';
    } elsif ( -f '/etc/arch-release' ) {
	$vendor = 'archlinux';
	$rcfilename = 'shorewallrc.archlinux';
    } elsif ( `uname` =~ '^Darwin' ) {
	$vendor = 'apple';
	$rcfilename = 'shorewallrc.apple';
    } elsif ( `uname` =~ /^Cygwin/i ) {
	$vendor = 'cygwin';
	$rcfilename = 'shorewallrc.cygwin';
    } else {
	$vendor = 'linux';
	$rcfilename = 'shorewallrc.default';
    }

    $params{HOST} = $vendor;
}

my @localtime = localtime;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );

if ( $vendor eq 'linux' ) {
    printf "INFO: Creating a generic Linux installation - %s %2d %04d %02d:%02d:%02d\n\n", $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
} else {
    printf "INFO: Creating a %s-specific installation - %s %2d %04d %02d:%02d:%02d\n\n", $params{HOST}, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
}

open $rcfile, '<', $rcfilename or die "Unable to open $rcfilename for input: $!";

while ( <$rcfile> ) {
    s/\s*#.*//;
    unless ( /^\s*$/ ) {
	chomp;
	die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
	$options{$1} = $2;
    }
}

close $rcfile;

while ( my ( $p, $v ) = each %params ) {
    $options{$p} = ${v};
}

my $outfile;

open $outfile, '>', 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!";

if ( $ENV{SOURCE_DATE_EPOCH} ) {
    printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s\n", VERSION, `date  --utc --date=\"\@$ENV{SOURCE_DATE_EPOCH}\"`;
} else {
    printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s %2d %04d %02d:%02d:%02d\n", VERSION, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];
}

print $outfile "# rc file: $rcfilename\n#\n";

print  $outfile "# Input: @ARGV\n#\n" if @ARGV;

if ( $options{VARLIB} ) {
    unless ( $options{VARDIR} ) {
	$options{VARDIR} = '${VARLIB}/${PRODUCT}';
    }
} elsif ( $options{VARDIR} ) {
    $options{VARLIB} = $options{VARDIR};
    $options{VARDIR} = '${VARLIB}/${PRODUCT}';
}

$options{SERVICEDIR}=$options{SYSTEMD} unless $options{SERVICEDIR};

for ( qw/ HOST
	  PREFIX
	  SHAREDIR
	  LIBEXECDIR
	  PERLLIBDIR
	  CONFDIR
	  SBINDIR
	  MANDIR
	  INITDIR
	  INITSOURCE
	  INITFILE
	  AUXINITSOURCE
	  AUXINITFILE
	  SERVICEDIR
	  SERVICEFILE
	  SYSCONFFILE
	  SYSCONFDIR
	  SPARSE
	  ANNOTATED
	  VARLIB
	  VARDIR
          DEFAULT_PAGER / ) {

    my $val = $options{$_} || '';

    print          "$_=$val\n";
    print $outfile "$_=$val\n";
}

close $outfile;

1;