pf-tools commit: r791 [ccaillet-guest] - in /branches/next-gen: debian/changelog sbin/mk_sourceslist templates/sources.list

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Jul 29 15:21:06 UTC 2010


Author: ccaillet-guest
Date: Thu Jul 29 15:20:58 2010
New Revision: 791

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=791
Log:
sbin/mk_sourceslist : rewrite according to new global structure, using
Getopt::Long for handling command line option(s) and Template::Tiny for
handling templates

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/sbin/mk_sourceslist
    branches/next-gen/templates/sources.list

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=791&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Jul 29 15:20:58 2010
@@ -54,13 +54,16 @@
   * sbin/mk_pxelinuxcfg : rewrite according to new global structure, using
   Getopt::Long for handling command line option(s) and Template::Tiny for
   handling templates
+  * sbin/mk_sourceslist : rewrite according to new global structure, using
+  Getopt::Long for handling command line option(s) and Template::Tiny for
+  handling templates
   * debian/control
     - deps update according to usage of NetAddr::IP, Net::DNS, Template::Tiny
     - uploaders and maintainers update
   * debian/compat
     - update level for avoiding warning during package build
 
- -- Christophe Caillet <quadchris at free.fr>  Thu, 29 Jul 2010 11:09:46 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Thu, 29 Jul 2010 17:20:12 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/sbin/mk_sourceslist
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_sourceslist?rev=791&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_sourceslist (original)
+++ branches/next-gen/sbin/mk_sourceslist Thu Jul 29 15:20:58 2010
@@ -24,68 +24,77 @@
 use strict;
 use warnings;
 
-use PFTools::Net;
 use PFTools::Conf;
-use PFTools::Update;
-use File::Compare ;
-use File::Copy ;
-use Getopt::Long qw( :config ignore_case_always bundling ) ;
-
-my $HELP		= 0 ;
-my $SRC 		= "" ;
-my $DST 		= "" ;
-my $TPL			= "" ;
-my $SECTIONS	= "common" ;
-my $HOST		= '' ;
-my $BACKPORTS	= 0 ;
-
-my $DEF_SECTIONS = {} ;
-$DEF_SECTIONS->{'debian'}	= "main contrib non-free" ;
-$DEF_SECTIONS->{'ubuntu'}	= "main universe restricted" ;
-
-chomp ( $HOST ) ;
+# use PFTools::Host;
+use PFTools::Logger;
+use File::Compare;
+use File::Copy;
+use Template::Tiny;
+use Getopt::Long qw( :config ignore_case_always bundling );
+
+############################################
+# Vars
+
+my $HELP				= 0;
+my $HOSTNAME			= "";
+my $OUTPUT_FILE			= "";
+my $TEMPLATE			= "";
+my $SITE				= "";
+my $SECTIONS			= "common" ;
+my $TO_ADD				= "";
+my $BACKPORTS			= 0;
+my $GLOBAL_STORE_FILE	= '';
+my $PF_CONFIG_FILE		= '';
+my $PF_CONFIG			= {};
+my $GLOBAL_STRUCT		= {};
 
 my $program = $0;
 $program =~ s%.*/%%; # cheap basename
 
 my $version = sprintf("svn-r%s", q$Revision$ =~ /([\d.]+)/);
 
-
-sub Usage () {
+############################################
+# Functions
+
+sub Do_help () {
 
 print <<EOF
 
 $program - version $version
 
-Synopsis : $program [-h|--help] [-s|--src <private-network source] [-d|--dst <sources.list dest>]
-		[ -t|--tpl <sources.list template>] [-b|--backports] [--host <hostname>] [[section] [section]]
+Synopsis : $program [--help] [-h|--host hostname <hostname>] [-s|--site <site_name>]
+			[-o|--output <sources.list dest>] [ -t|--tpl <sources.list template>] [-b|--backports]
+			[-a|--add <sections to add>] [-c|--config <pf_tools_file>] [--store <filename>]
 
 	This tool permits to build the sources.list file according to distribution defined
 	in private-network file from PF-Tools configuration. It can also add some sections
 	to custom repository
 
-	-h | --help		Displays this message and exits
-
-	-s | --src		Defines here where to find the private-network file
-
-	-d | --dst		Defines here where to build the sources.list file
+	--help			Displays this message and exits
+
+	-h | --host		Defines here the hostname you want to build the sources.list
+
+	-s | --site		Defines here the site on which the hostname is defined
+
+	-o | --output		Defines here where to build the sources.list file
 
 	-t | --tpl		Defines here where to find the sources.list template. If not defined
-				the program will use /usr/share/pf-tools/templates/sources.list.tpl
+				the program will use template path issued from pf-tools.conf file
 
 	-a | --add		Defines here the list(comma-separated) of sections you want to add into custom repository
 
-	-b | --backports	Adds the backport repository from debian-backports
-
-	--host		Defines for which hostname you want to build the sources.list. This
-			option is mainly for debugging
-
+	-b | --backports	Adds the backport repository from offical source according to hostname's
+				deployment mode
+
+	-c | --config		Define here where is the pf-tools.conf file
+
+	--store			Define here where the storable file which contains the global structure is
 
 	You can add on CLI some sections to add to the "common" section for custom repository
 	
 	Sample use :
 	
-	$program -s GLOBAL:private-network -d /tmp/sources.list -h stream-tv00 -a stream
+	$program -s mysite -o /tmp/sources.list -h stream-tv00 -a stream
 
 	This command generate the sources.list file on /tmp for stream-tv00 host and adds the
 	section stream to the custom packages repository
@@ -94,34 +103,34 @@
 }
 
 sub Mk_sourceslist ($$$$) {
-	my ( $host_props, $dst, $tpl, $sections ) = @_ ;
-	
-	if ( ! open ( SOURCESTPL, $tpl ) ) {
-		warn "Unable to get sources.list template from file ".$tpl."\n" ;
-		return 1 ;
-	}
-	my $sources_content = join '', <SOURCESTPL> ;
-	close ( SOURCESTPL ) ;
+	my ( $host_props, $dst, $sections, $template ) = @_ ;
 
 	my $tpl			= Template::Tiny->new ( TRIM => 1 );
 	my $mode		= $host_props->{'deployment'}->{'mode'};
-	$sources_subst	= {
+	if ( $template eq "" ) {
+		$template = $PF_CONFIG->{'path'}->{'templates_dir'}.'/'.$PF_CONFIG->{$mode}->{'sources_list'};
+	}
+	
+	if ( ! open ( SOURCESTPL, $template ) ) {
+		Abort ( $CODE->{'OPEN'},
+			"Unable to get sources.list template from file ".$template );
+		return 1 ;
+	}
+	my $sources_content = join '', <SOURCESTPL>;
+	close ( SOURCESTPL );
+
+	my $sources_subst	= {
 		'mode'				=> $host_props->{'deployment'}->{'mode'},
 		'distrib'			=> $host_props->{'deployment'}->{'distrib'},
 		'default_sections'	=> $PF_CONFIG->{$mode}->{'default_sections'},
-		'custom_sections'	=> $SECTIONS
+		'custom_sections'	=> $sections
 	};
 	$sources_content = $tpl->process ( \$sources_content, $sources_subst );
 
 	if ( $BACKPORTS ) {
-		my $back_src ;
-		my $back_sections ;
-		if ( $mode eq 'debian' ) {
-			$back_src = $mode."-backports" ;
-		}
-		elsif ( $mode eq 'ubuntu' ) {
-			$back_src = $mode ;
-		}
+		my $back_src = ( $mode eq 'debian' )
+			? $mode."-backports"
+			: $mode;
 		$sources_content .=
 			"\ndeb http://mirrors.private/".$back_src." ".$host_props->{'deployment'}->{'distrib'}."-backports ".$PF_CONFIG->{$mode}->{'default_sections'}."\n" ;
 	}
@@ -135,52 +144,63 @@
 	return 0 ;
 }
 
+#############################################################
+### MAIN
+
 GetOptions (
-	'h|help'	=> \$HELP,
-	'host=s'	=> \$HOST,
-	's|src=s'	=> \$SRC,
-	'd|dst=s'	=> \$DST,
-	't|tpl=s'	=> \$TPL,
-	'a|add=s'	=> \$SECTIONS,
-	'b|backports'	=> \$BACKPORTS
-) || die "Didn't grok options on CLI\n" ;
+	'help'			=> \$HELP,
+	'host|h=s'		=> \$HOSTNAME,
+	'site|s=s'		=> \$SITE,
+	'tpl|t=s'		=> \$TEMPLATE,
+	'a|add=s'		=> \$TO_ADD,
+	'config|c=s'	=> \$PF_CONFIG_FILE,
+	'store=s'		=> \$GLOBAL_STORE_FILE,
+	'backport|b'	=> \$BACKPORTS,
+	'output|o=s'	=> \$OUTPUT_FILE
+) or die "Didn't grok options (see --help).\n";
 
 if ( $HELP ) {
-	Usage () ;
-	exit 0 ;
-}
-
-my $TPL_DIR		= "/usr/share/pf-tools/templates/" ;
-my $DEFAULT_TPL	= "sources.list.tpl";
-
-
-if ( $SRC eq "" || $DST eq "" ) {
-	warn "Source or/and destination are not defined : cannot build sources.list file\n" ;
-	Usage () ;
-	exit 1 ;
-}
-
-$ADD_SECTIONS .= " ".join ( " ", @ARGV ) ; }
-
-my $PF_NET	= Init_lib_net ( Get_source ( $SRC ) ) ;
-
-my $hosttype ;
-if ( $HOST ne '' ) {
-	my %tmp_subst ;
-	Init_SUBST ( \%tmp_subst, $HOST, 'private' ) ;
-	$hosttype	= $tmp_subst{'HOSTTYPE'} ;
+	Do_help ();
+	exit 0;
+}
+
+if ( $HOSTNAME eq "" ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"Unable to build sources.list for an undefined hostname" );
+}
+
+if ( $PF_CONFIG_FILE ne '' ) {
+	if ( ! -e $PF_CONFIG_FILE ) {
+		Abort ( $CODE->{'OPEN'},
+			"Unable to open configuration file ".$PF_CONFIG_FILE." : no such file or directory" );
+	}
+	$PF_CONFIG = Init_PF_CONFIG ( $PF_CONFIG_FILE );
 }
 else {
-	$HOST		= $SUBST{'HOSTNAME'} ;
-	$hosttype	= $SUBST{'HOSTTYPE'} ;
-}
-my $SRV		= $PF_NET->{'SERVERS'}->{'BY_NAME'}->{$hosttype}->{'SRVLIST'}->{$HOST} ;
-
-if ( $SRV->{'deploymode'} =~ /^ubuntu/ && $TPL eq "" ) {
-	$TPL = $TPL_DIR."ubuntu-sources.list.tpl";
-}
-elsif ( $TPL eq "" ) {
-	$TPL = $TPL_DIR.$DEFAULT_TPL;
-}
-
-Mk_sourceslist ( $SRV, $DST, $TPL, $SECTIONS ) ;
+	$PF_CONFIG = Init_PF_CONFIG ();
+}
+
+$GLOBAL_STORE_FILE	= $PF_CONFIG->{'path'}->{'global_struct'} if ( $GLOBAL_STORE_FILE eq '' );
+$GLOBAL_STRUCT		= Retrieve_GLOBAL ( $GLOBAL_STORE_FILE );
+if ( ! defined $GLOBAL_STRUCT ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"An error occured during retrieve from the storable file ".$GLOBAL_STORE_FILE );
+}
+
+if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"A site MUST BE defined for building DNS zone forward" );
+}
+
+
+my $host_props	= Get_host_config_from_CONFIG ( $HOSTNAME, $GLOBAL_STRUCT, $SITE );
+my $mode		= $host_props->{'deployment'}->{'mode'};
+if ( $TEMPLATE ne "" && ! -e $TEMPLATE ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"Unbale to create sources.list file from template ".$TEMPLATE." : no such file or directory" );
+}
+$TO_ADD		=~ s/,/ /g;
+$SECTIONS	.= " ".$TO_ADD;
+Mk_sourceslist ( $host_props, $OUTPUT_FILE, $SECTIONS, $TEMPLATE ) ;
+
+exit 0;

Modified: branches/next-gen/templates/sources.list
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/sources.list?rev=791&op=diff
==============================================================================
--- branches/next-gen/templates/sources.list (original)
+++ branches/next-gen/templates/sources.list Thu Jul 29 15:20:58 2010
@@ -5,4 +5,4 @@
 
 deb http://mirrors.private/[% mode %]-custom [% distrib %]-custom [% custom_sections %]
 
-deb http://mirrors.private/[% mode %]-security %SECURITY% [% default_sections %]
+deb http://mirrors.private/[% mode %]-security [% distrib %]/updates [% default_sections %]




More information about the pf-tools-commits mailing list