2012-04-10 19:20:53 +02:00
#! /usr/bin/perl -w
#
2018-06-23 17:29:01 +02:00
# Shorewall Packet Filtering Firewall configuration program - V5.2
2012-04-10 19:20:53 +02:00
#
2014-01-04 18:48:27 +01:00
# (c) 2012, 2014 - Tom Eastep (teastep@shorewall.net)
2012-04-10 19:20:53 +02:00
#
2019-03-25 19:11:51 +01:00
# Shorewall documentation is available at http://www.shorewall.org
2012-04-10 19:20:53 +02:00
#
2014-01-04 18:48:27 +01:00
# This program is part of Shorewall.
#
2012-04-10 19:20:53 +02:00
# This program is free software; you can redistribute it and/or modify
2014-01-04 18:48:27 +01:00
# 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.
2012-04-10 19:20:53 +02:00
#
# 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
2014-01-04 18:48:27 +01:00
# along with this program; if not, see <http://www.gnu.org/licenses/>.
2012-04-10 19:20:53 +02:00
#
# Usage: ./configure.pl <option>=<setting> ...
#
#
################################################################################################
use strict ;
2012-04-12 23:43:02 +02:00
#
# Build updates this
#
2012-04-24 23:52:57 +02:00
use constant {
2015-08-01 20:23:35 +02:00
VERSION = > '4.6.12'
2012-04-12 23:43:02 +02:00
} ;
2012-04-10 19:20:53 +02:00
my % params ;
my % options ;
2012-04-12 23:43:02 +02:00
my % aliases = ( VENDOR = > 'HOST' ,
2012-09-02 23:36:11 +02:00
SHAREDSTATEDIR = > 'VARLIB' ,
2012-06-09 15:26:03 +02:00
DATADIR = > 'SHAREDIR' ) ;
2012-04-10 19:20:53 +02:00
2012-04-12 23:43:02 +02:00
for ( @ ARGV ) {
die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/ ;
2012-04-10 19:20:53 +02:00
my $ pn = uc $ 1 ;
my $ pv = $ 2 || '' ;
$ pn = $ aliases { $ pn } if exists $ aliases { $ pn } ;
$ params { $ pn } = $ pv ;
}
2015-12-06 21:04:34 +01:00
use File::Basename ;
chdir dirname ( $ 0 ) ;
2012-04-10 19:20:53 +02:00
my $ vendor = $ params { HOST } ;
my $ rcfile ;
my $ rcfilename ;
2013-08-09 02:44:40 +02:00
unless ( defined $ vendor ) {
2013-08-10 01:50:30 +02:00
if ( - f '/etc/os-release' ) {
2013-10-09 16:05:06 +02:00
my $ id = `cat /etc/os-release | grep ^ID=` ;
2013-08-09 02:44:40 +02:00
chomp $ id ;
$ id =~ s/ID=// ;
2014-05-20 00:15:52 +02:00
if ( $ id eq 'fedora' || $ id eq 'rhel' ) {
2013-08-09 02:44:40 +02:00
$ vendor = 'redhat' ;
} elsif ( $ id eq 'opensuse' ) {
$ vendor = 'suse' ;
2015-08-01 20:23:35 +02:00
} elsif ( $ id eq 'ubuntu' || $ id eq 'debian' ) {
my $ init = `ls -l /sbin/init` ;
$ vendor = $ init =~ /systemd/ ? 'debian.systemd' : 'debian.sysvinit' ;
2018-05-29 17:13:26 +02:00
} elsif ( $ id eq 'alt' || $ id eq 'basealt' || $ id eq 'altlinux' ) {
$ vendor = 'alt' ;
2013-08-09 02:44:40 +02:00
} else {
$ vendor = $ id ;
}
}
$ params { HOST } = $ vendor ;
2015-08-01 20:23:35 +02:00
$ params { HOST } =~ s/\..*// ;
2013-08-09 02:44:40 +02:00
}
2012-04-10 19:20:53 +02:00
if ( defined $ vendor ) {
2015-11-29 18:06:39 +01:00
if ( $ vendor eq 'debian' && - f '/etc/debian_version' ) {
if ( - l '/sbin/init' ) {
2015-12-06 21:04:34 +01:00
if ( readlink ( '/sbin/init' ) =~ /systemd/ ) {
$ rcfilename = 'shorewallrc.debian.systemd' ;
2015-11-29 18:06:39 +01:00
} else {
$ rcfilename = 'shorewallrc.debian.sysvinit' ;
}
} else {
$ rcfilename = 'shorewallrc.debian.sysvinit' ;
}
} else {
$ rcfilename = $ vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $ vendor ;
}
2015-10-31 21:29:02 +01:00
unless ( - f $ rcfilename ) {
die qq( "ERROR: $vendor" is not a recognized host type ) ;
} elsif ( $ vendor eq 'default' ) {
$ params { HOST } = $ vendor = 'linux' ;
2015-12-12 17:10:34 +01:00
} elsif ( $ vendor =~ /^debian\./ ) {
$ params { HOST } = $ vendor = 'debian' ;
2015-10-31 21:29:02 +01:00
}
2012-04-10 19:20:53 +02:00
} else {
2012-04-12 23:43:02 +02:00
if ( - f '/etc/debian_version' ) {
$ vendor = 'debian' ;
2015-11-29 18:06:39 +01:00
if ( - l '/sbin/init' ) {
2015-12-11 23:37:52 +01:00
if ( readlink ( '/sbin/init' ) =~ /systemd/ ) {
$ rcfilename = 'shorewallrc.debian.systemd' ;
2015-11-29 18:06:39 +01:00
} else {
$ rcfilename = 'shorewallrc.debian.sysvinit' ;
}
} else {
$ rcfilename = 'shorewallrc.debian.sysvinit' ;
}
2018-05-29 17:13:26 +02:00
} elsif ( - f '/etc/altlinux-release' ) {
$ vendor = 'alt' ;
$ rcfilename = 'shorewallrc.alt' ;
2012-04-12 23:43:02 +02:00
} 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' ;
2014-07-09 19:48:03 +02:00
} elsif ( `uname` =~ /^Cygwin/i ) {
2012-04-12 23:43:02 +02:00
$ 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 {
2015-08-01 20:23:35 +02:00
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 ] ; ;
2012-04-10 19:20:53 +02:00
}
open $ rcfile , '<' , $ rcfilename or die "Unable to open $rcfilename for input: $!" ;
while ( <$rcfile> ) {
2012-04-12 15:53:58 +02:00
s/\s*#.*// ;
2012-04-12 23:43:02 +02:00
unless ( /^\s*$/ ) {
chomp ;
die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/ ;
$ options { $ 1 } = $ 2 ;
}
2012-04-10 19:20:53 +02:00
}
close $ rcfile ;
while ( my ( $ p , $ v ) = each % params ) {
$ options { $ p } = $ { v } ;
}
my $ outfile ;
open $ outfile , '>' , 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!" ;
2017-07-20 23:48:40 +02:00
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 ] ;
}
2015-12-06 21:04:34 +01:00
print $ outfile "# rc file: $rcfilename\n#\n" ;
2012-04-12 23:43:02 +02:00
print $ outfile "# Input: @ARGV\n#\n" if @ ARGV ;
2012-09-02 23:36:11 +02:00
if ( $ options { VARLIB } ) {
unless ( $ options { VARDIR } ) {
$ options { VARDIR } = '${VARLIB}/${PRODUCT}' ;
}
} elsif ( $ options { VARDIR } ) {
$ options { VARLIB } = $ options { VARDIR } ;
$ options { VARDIR } = '${VARLIB}/${PRODUCT}' ;
}
2014-10-13 20:56:26 +02:00
$ options { SERVICEDIR } = $ options { SYSTEMD } unless $ options { SERVICEDIR } ;
2014-10-08 01:46:16 +02:00
2012-04-11 17:01:49 +02:00
for ( qw / HOST
PREFIX
2012-04-10 19:20:53 +02:00
SHAREDIR
LIBEXECDIR
PERLLIBDIR
CONFDIR
SBINDIR
2012-04-24 23:52:57 +02:00
MANDIR
2012-04-10 19:20:53 +02:00
INITDIR
INITSOURCE
INITFILE
AUXINITSOURCE
AUXINITFILE
2014-10-13 20:56:26 +02:00
SERVICEDIR
2014-10-20 21:29:45 +02:00
SERVICEFILE
2012-04-10 19:20:53 +02:00
SYSCONFFILE
SYSCONFDIR
2012-05-15 20:32:35 +02:00
SPARSE
2012-04-10 19:20:53 +02:00
ANNOTATED
2012-09-02 23:36:11 +02:00
VARLIB
2016-09-21 19:20:48 +02:00
VARDIR
2017-07-20 21:23:59 +02:00
DEFAULT_PAGER / ) {
2012-04-10 19:20:53 +02:00
my $ val = $ options { $ _ } || '' ;
print "$_=$val\n" ;
print $ outfile "$_=$val\n" ;
}
close $ outfile ;
1 ;