Make arguments to the configure script optional

- Scripts detects vendor
- Scripts Annotate the shorewallrc file with version and argument info
- configure detects BASH version
This commit is contained in:
Tom Eastep 2012-04-12 14:43:02 -07:00
parent 69a133083c
commit 32264c2e7e
2 changed files with 137 additions and 32 deletions

View File

@ -21,10 +21,24 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Usage: ./configure <option>=<setting> ...
# Usage: ./configure [ <option>=<setting> ] ...
#
#
################################################################################################
#
# Build updates this
#
VERSION=4.5.2.1
case "$BASH_VERSION" in
[4-9].*)
;;
*)
echo "ERROR: This program requires Bash 4.0 or later" >&2
exit 1
;;
esac
declare -A params
declare -A options
@ -46,21 +60,17 @@ getfileparams() {
return 0
}
if [ $# -eq 0 ]; then
echo "Usage: $0 <var>=<val> ..." >&2
exit 1
fi
for p in $@; do
p=${p#--}
if [ -n "${p}" ]; then
declare -u pn
pn=${p%=*}
pn=${pn#--}
pv=${p#*=}
if [ -n "${pn}" ]; then
case ${pn} in
VENDOR)
pn=HOST
@ -77,6 +87,9 @@ for p in $@; do
esac
params[${pn}]="${pv}"
else
echo "ERROR: Invalid option ($p)" >&2
exit 1
fi
fi
done
@ -84,22 +97,75 @@ done
vendor=${params[HOST]}
if [ -z "$vendor" ]; then
case `uname` in
Darwin)
$params[HOST]=apple
rcfile=shorewallrc.apple
;;
cygwin*)
$params[HOST]=cygwin
rcfile=shorewallrc.cygwin
;;
*)
if [ -f /etc/debian_version ]; then
params[HOST]=debian
rcfile=shorewallrc.debian
elif [ -f /etc/redhat-release ]; then
params[HOST]=redhat
rcfile=shorewallrc.redhat
elif [ -f /etc/slackware-version ] ; then
params[HOST]=slackware
rcfile=shorewallrc.slackware
elif [ -f /etc/SuSE-release ]; then
params[HOST]=suse
rcfile=shorewallrc.suse
elif [ -f /etc/arch-release ] ; then
params[HOST]=archlinux
rcfile=shorewallrc.archlinux
else
params[HOST]=linux
rcfile=shorewallrc.default
vendor=linux
fi
;;
esac
vendor=${params[HOST]}
elif [ $vendor = linux ]; then
rcfile=$shorewallrc.default;
else
rcfile=shorewallrc.$vendor
if [ ! -f $rcfile ]; then
echo "ERROR: $vendor is not a recognized host type" >&2
exit 1
fi
fi
if [ $vendor = linux ]; then
echo "INFO: Creating a generic Linux installation - " `date`;
else
echo "INFO: Creating a ${vendor}-specific installation - " `date`;
fi
echo
getfileparams < $rcfile || exit 1
for p in ${!params[@]}; do
options[${p}]="${params[${p}]}"
options[${p}]="${params[${p}]}"
done
echo "HOST=$vendor" > shorewallrc
echo '#' > shorewallrc
echo "# Created by Shorewall Core version $VERSION configure - " `date` >> shorewallrc
echo '#' >> shorewallrc
if [ -n "$@" ]; then
echo "# Input: $@" >> shorewallrc
echo '#' >> shorewallrc
fi
for on in \
HOST \
PREFIX \
SHAREDIR \
LIBEXECDIR \
@ -118,7 +184,6 @@ for on in \
ANNOTATED \
VARDIR
do
echo "$on=${options[${on}]}"
echo "$on=${options[${on}]}" >> shorewallrc
done
cat shorewallrc

View File

@ -27,6 +27,13 @@
################################################################################################
use strict;
#
# Build updates this
#
use constant {
VERSION => '4.5.2.1'
};
my %params;
my %options;
@ -35,14 +42,8 @@ my %aliases = ( VENDOR => 'HOST',
DATADIR => 'SHAREDIR',
SYSCONFDIR => 'CONFDIR' );
die "Usage: $0 <var>=<val> ..." unless @ARGV;
for ( @ARGV) {
s/^--//;
next unless defined $_ && $_ ne '';
die "Invalid option specification ( $_ )" unless /^(\w+)=(.*)$/;
for ( @ARGV ) {
die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/;
my $pn = uc $1;
my $pv = $2 || '';
@ -57,21 +58,56 @@ my $rcfile;
my $rcfilename;
if ( defined $vendor ) {
$rcfilename = 'shorewallrc.' . $vendor;
$rcfilename = $vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $vendor;
die qq("ERROR: $vendor" is not a recognized host type) unless -f $rcfilename;
} else {
if ( -f '/etc/debian_version' ) {
$vendor = 'debian';
$rcfilename = 'shorewallrc.debian';
} 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' ) {
$vendor = 'cygwin';
$rcfilename = 'shorewallrc.cygwin';
} else {
$vendor = 'linux';
$rcfilename = 'shorewallrc.default';
$params{HOST} = 'linux';
}
$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", $vendor, $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> ) {
next if /^\s*#/;
s/\s*#.*//;
next if /^\s*$/;
unless ( /^\s*$/ ) {
chomp;
die "Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
$options{$1} = $2;
}
}
close $rcfile;
@ -84,6 +120,10 @@ my $outfile;
open $outfile, '>', 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!";
printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s %2d %04d %02d:%02d:%02d\n#\n", VERSION, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];
print $outfile "# Input: @ARGV\n#\n" if @ARGV;
for ( qw/ HOST
PREFIX
SHAREDIR