"Fossies" - the Fresh Open Source Software Archive

Member "shorewall6-5.2.8/configure.pl" (24 Sep 2020, 6182 Bytes) of package /linux/misc/shorewall/shorewall6-5.2.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "configure.pl": 5.2.7_vs_5.2.8.

    1 #! /usr/bin/perl -w
    2 #
    3 #     Shorewall Packet Filtering Firewall configuration program - V5.2
    4 #
    5 #     (c) 2012, 2014 - Tom Eastep (teastep@shorewall.net)
    6 #
    7 #   Shorewall documentation is available at https://shorewall.org
    8 #
    9 #       This program is part of Shorewall.
   10 #
   11 #   This program is free software; you can redistribute it and/or modify
   12 #   it under the terms of the GNU General Public License as published by the
   13 #       Free Software Foundation, either version 2 of the license or, at your
   14 #       option, any later version.
   15 #
   16 #   This program is distributed in the hope that it will be useful,
   17 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
   18 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   19 #   GNU General Public License for more details.
   20 #
   21 #   You should have received a copy of the GNU General Public License
   22 #   along with this program; if not, see <http://www.gnu.org/licenses/>.
   23 #
   24 #       Usage: ./configure.pl <option>=<setting> ...
   25 #
   26 #
   27 ################################################################################################
   28 use strict;
   29 
   30 #
   31 # Build updates this
   32 #
   33 use constant {
   34     VERSION => '5.2.8'
   35 };
   36 
   37 my %params;
   38 my %options;
   39 
   40 my %aliases = ( VENDOR         => 'HOST',
   41         SHAREDSTATEDIR => 'VARLIB',
   42         DATADIR        => 'SHAREDIR' );
   43 
   44 for ( @ARGV ) {
   45     die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/;
   46 
   47     my $pn = uc $1;
   48     my $pv = $2 || '';
   49 
   50     $pn = $aliases{$pn} if exists $aliases{$pn};
   51 
   52     $params{$pn} = $pv;
   53 }
   54 
   55 use File::Basename;
   56 chdir dirname($0);
   57 
   58 my $vendor = $params{HOST};
   59 my $rcfile;
   60 my $rcfilename;
   61 
   62 unless ( defined $vendor ) {
   63     if ( -f '/etc/os-release' ) {
   64     my $id = `cat /etc/os-release | grep ^ID=`;
   65 
   66     chomp $id;
   67 
   68     $id =~ s/ID=//;
   69     
   70     if ( $id eq 'fedora' || $id eq 'rhel' ) {
   71         $vendor = 'redhat';
   72     } elsif ( $id eq 'opensuse' ) {
   73         $vendor = 'suse';
   74     } elsif ( $id eq 'ubuntu' || $id eq 'debian' ) {
   75         my $init = `ls -l /sbin/init`;
   76         $vendor = $init =~ /systemd/ ? 'debian.systemd' : 'debian.sysvinit';
   77     } elsif ( $id eq 'alt' || $id eq 'basealt' || $id eq 'altlinux' ) {
   78         $vendor = 'alt';
   79     } else {
   80         $vendor = $id;
   81     }
   82     }
   83 
   84     $params{HOST} = $vendor;
   85     $params{HOST} =~ s/\..*//;
   86 }
   87 
   88 if ( defined $vendor ) {
   89     if ( $vendor eq 'debian' && -f '/etc/debian_version' ) {
   90     if ( -l '/sbin/init' ) {
   91         if ( readlink('/sbin/init') =~ /systemd/ ) {
   92         $rcfilename = 'shorewallrc.debian.systemd';
   93         } else {
   94         $rcfilename = 'shorewallrc.debian.sysvinit';
   95         }
   96     } else {
   97         $rcfilename = 'shorewallrc.debian.sysvinit';
   98     }
   99     } else {
  100     $rcfilename = $vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $vendor;
  101     }
  102 
  103     unless ( -f $rcfilename ) {
  104     die qq("ERROR: $vendor" is not a recognized host type);
  105     } elsif ( $vendor eq 'default' ) {
  106     $params{HOST} = $vendor = 'linux';
  107     } elsif ( $vendor =~ /^debian\./ ) {
  108     $params{HOST} = $vendor = 'debian';
  109     }
  110 } else {
  111     if ( -f '/etc/debian_version' ) {
  112     $vendor = 'debian';
  113     if ( -l '/sbin/init' ) {
  114         if ( readlink( '/sbin/init' ) =~ /systemd/ ) {
  115         $rcfilename = 'shorewallrc.debian.systemd';
  116         } else {
  117         $rcfilename = 'shorewallrc.debian.sysvinit';
  118         }
  119     } else {
  120         $rcfilename = 'shorewallrc.debian.sysvinit';
  121     }
  122     } elsif ( -f '/etc/altlinux-release' ){
  123     $vendor = 'alt';
  124     $rcfilename = 'shorewallrc.alt';
  125     } elsif ( -f '/etc/redhat-release' ){
  126     $vendor = 'redhat';
  127     $rcfilename = 'shorewallrc.redhat';
  128     } elsif ( -f '/etc/slackware-version' ) {
  129     $vendor = 'slackware';
  130     $rcfilename = 'shorewallrc.slackware';
  131     } elsif ( -f '/etc/SuSE-release' ) {
  132     $vendor = 'suse';
  133     $rcfilename = 'shorewallrc.suse';
  134     } elsif ( -f '/etc/arch-release' ) {
  135     $vendor = 'archlinux';
  136     $rcfilename = 'shorewallrc.archlinux';
  137     } elsif ( `uname` =~ '^Darwin' ) {
  138     $vendor = 'apple';
  139     $rcfilename = 'shorewallrc.apple';
  140     } elsif ( `uname` =~ /^Cygwin/i ) {
  141     $vendor = 'cygwin';
  142     $rcfilename = 'shorewallrc.cygwin';
  143     } else {
  144     $vendor = 'linux';
  145     $rcfilename = 'shorewallrc.default';
  146     }
  147 
  148     $params{HOST} = $vendor;
  149 }
  150 
  151 my @localtime = localtime;
  152 my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
  153 
  154 if ( $vendor eq 'linux' ) {
  155     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];;
  156 } else {
  157     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];;
  158 }
  159 
  160 open $rcfile, '<', $rcfilename or die "Unable to open $rcfilename for input: $!";
  161 
  162 while ( <$rcfile> ) {
  163     s/\s*#.*//;
  164     unless ( /^\s*$/ ) {
  165     chomp;
  166     die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
  167     $options{$1} = $2;
  168     }
  169 }
  170 
  171 close $rcfile;
  172 
  173 while ( my ( $p, $v ) = each %params ) {
  174     $options{$p} = ${v};
  175 }
  176 
  177 my $outfile;
  178 
  179 open $outfile, '>', 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!";
  180 
  181 if ( $ENV{SOURCE_DATE_EPOCH} ) {
  182     printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s\n", VERSION, `date  --utc --date=\"\@$ENV{SOURCE_DATE_EPOCH}\"`;
  183 } else {
  184     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];
  185 }
  186 
  187 print $outfile "# rc file: $rcfilename\n#\n";
  188 
  189 print  $outfile "# Input: @ARGV\n#\n" if @ARGV;
  190 
  191 if ( $options{VARLIB} ) {
  192     unless ( $options{VARDIR} ) {
  193     $options{VARDIR} = '${VARLIB}/${PRODUCT}';
  194     }
  195 } elsif ( $options{VARDIR} ) {
  196     $options{VARLIB} = $options{VARDIR};
  197     $options{VARDIR} = '${VARLIB}/${PRODUCT}';
  198 }
  199 
  200 $options{SERVICEDIR}=$options{SYSTEMD} unless $options{SERVICEDIR};
  201 
  202 for ( qw/ HOST
  203       PREFIX
  204       SHAREDIR
  205       LIBEXECDIR
  206       PERLLIBDIR
  207       CONFDIR
  208       SBINDIR
  209       MANDIR
  210       INITDIR
  211       INITSOURCE
  212       INITFILE
  213       AUXINITSOURCE
  214       AUXINITFILE
  215       SERVICEDIR
  216       SERVICEFILE
  217       SYSCONFFILE
  218       SYSCONFDIR
  219       SPARSE
  220       ANNOTATED
  221       VARLIB
  222       VARDIR
  223           DEFAULT_PAGER / ) {
  224 
  225     my $val = $options{$_} || '';
  226 
  227     print          "$_=$val\n";
  228     print $outfile "$_=$val\n";
  229 }
  230 
  231 close $outfile;
  232 
  233 1;