pf-tools/pf-tools: Coding style for sbin/mk_grubopt : remake due...
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Sep 15 14:05:19 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/2dbf713e764a
changeset: 770:2dbf713e764a
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Sep 15 15:50:24 2010 +0200
description:
Coding style for sbin/mk_grubopt : remake due to misuse of mergurial :)
diffstat:
1 file changed, 2 insertions(+)
sbin/mk_grubopt | 2 ++
diffs (148 lines):
diff -r 746c549ca865 -r 2dbf713e764a sbin/mk_grubopt
--- a/sbin/mk_grubopt Tue Sep 14 19:37:06 2010 +0200
+++ b/sbin/mk_grubopt Wed Sep 15 15:50:24 2010 +0200
@@ -44,19 +44,13 @@
my $options = {
'config' => '',
+ 'host' => hostname,
'help' => 0,
'grub' => 2,
'src' => '',
+ 'output' => '-',
};
-my $GRUB_VERSION = 2;
-my $MENU_GRUB = "";
-my $HOSTNAME = "";
-my $SITE = "";
-my $OUTPUT = "";
-my $HELP = 0;
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
my $PF_CONFIG = {};
my $GLOBAL_STRUCT = {};
@@ -75,7 +69,7 @@
-s --site : the site where the hostname is defined
--src : the source for grub configuration
--grub : version of grub default value is 2
- -o --output : destination for modified GRUB configuration
+ -o --output : destination for modified GRUB configuration default is STDOUT
--store : path for accessing storable file containing the global configuration
-c --config : path for accessing pf-tools.conf file
# ENDHELP
@@ -84,75 +78,57 @@
#######################################################""
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'h|host=s' => \$HOSTNAME,
- 'site|s=s' => \$SITE,
- 'src=s' => \$MENU_GRUB,
- 'grub=s' => \$GRUB_VERSION,
- 'o|output=s' => \$OUTPUT,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $options->{'host'},
+ $options->{'config'},
+ $options->{'store'}
+);
-if ( $OUTPUT eq "" ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "You MUST define a valid output for this command use '-' if you want to use STDOUT"
- );
+unless( $options->{'site'} ) {
+ unless( $PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = Get_site_from_hostname(
+ $options->{'host'},
+ $GLOBAL_STRUCT
+ );
+ unless( $site_list ) {
+ Abort( $CODE->{'UNDEF_KEY'},
+ "Unknown hostname $options->{'host'}" );
+ }
+ if ( scalar @{$site_list} > 1 ) {
+ Abort( $CODE->{'DUPLICATE_VALUE'},
+ "Multiple sites for hostname $options->{'host'}" );
+ }
+ ($options->{'site'}) = @{$site_list};
+ }
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
-if ( $HOSTNAME eq "" ) {
+unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to modify grub options for an undefined hostname" );
+ "Unknown DHCP site $options->{'site'}" );
}
-if ( $SITE eq '' ) {
- if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
- if ( !defined $site_list ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname not defined" );
- }
- elsif ( scalar @{$site_list} > 1 ) {
- Abort( $CODE->{'DUPLICATE_VALUE'},
- "Unable to retrieve site for hostname "
- . $HOSTNAME
- . " : hostname appeared in multiple sites : "
- . join( ",", @{$site_list} ) . ".\n"
- . "Please relaunch this command with the right site" );
- }
- else {
- ($SITE) = @{$site_list};
- }
- }
- else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
- }
-}
-
-if ( !defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Site " . $SITE . " is not defined into global configuration" );
-}
-
-if (!Change_kopt_for_hostname(
- $HOSTNAME, $SITE, $MENU_GRUB, $OUTPUT,
- $GRUB_VERSION, $GLOBAL_STRUCT, $PF_CONFIG
+if (
+ !Change_kopt_for_hostname(
+ $options->{'host'},
+ $options->{'site'},
+ $options->{'src'},
+ $options->{'output'},
+ $options->{'grub'},
+ $GLOBAL_STRUCT,
+ $PF_CONFIG
)
- )
-{
+) {
Abort( $CODE->{'EXEC'},
- "Unable to change kernel options(s) into file " . $MENU_GRUB );
+ "Unable to change kernel options(s) into file $options->{'src'}" );
}
exit 0;
More information about the pf-tools-commits
mailing list