[OpenWrt-Devel] [PATCH 2/2] script/feeds: add a new command that allows generating a new feeds.conf

Jo-Philipp Wich jo at mein.io
Tue Jun 4 03:31:49 EDT 2019


Hi,

comments inline.

On 6/4/19 7:55 AM, John Crispin wrote:
> This can be used inside build setups for easy feeds.conf generation.
> 
> Signed-off-by: John Crispin <john at phrozen.org>
> ---
>  scripts/feeds | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/scripts/feeds b/scripts/feeds
> index 304ef6cbaf..6f8c7be31d 100755
> --- a/scripts/feeds
> +++ b/scripts/feeds
> @@ -7,6 +7,7 @@ use metadata;
>  use warnings;
>  use strict;
>  use Cwd 'abs_path';
> +use File::Copy

Missing semicolon.

>  
>  chdir "$FindBin::Bin/..";
>  $ENV{TOPDIR} //= getcwd();
> @@ -819,6 +820,37 @@ sub update {
>  	return $failed;
>  }
>  
> +sub setup {
> +	my %opts;
> +
> +	getopts('bh', \%opts);
> +
> +	if ($opts{h}) {
> +		usage();
> +		return 0;
> +	}
> +
> +	if ($opts{b}) {
> +		copy("feeds.conf.default", "feeds.conf") or die "Copy failed: $!"
> +	} else {
> +		unlink "feeds.conf"
> +	}
> +
> +	open(my $fd, ">>feeds.conf");
> +	while (my $entry = shift @ARGV) {
> +		my ($type, $name, $src) = split /,/, $entry;

I think it would make sense to check $name and $src to not contain whitespace here,
for example like this:

if ($name =~ /\s/ || $src =~ /\s/) {
	warn "Feed names or sources may not contain whitespace characters in parameter $entry\n";
	unlink "feeds.conf";
	return 1;
}

> +
> +		$update_method{$type} or do {
> +			warn "Unknown type '$type' in parameter $entry\n";
> +			unlink "feeds.conf";
> +			return 1;
> +		};
> +		printf $fd "%s %s %s\n", $type, $name, $src;
> +	}
> +
> +	return 0;
> +}
> +
>  sub feed_config() {
>  	foreach my $feed (@feeds) {
>  		my $installed = (-f "feeds/$feed->[1].index");
> @@ -870,6 +902,10 @@ Commands:
>  	    -i :           Recreate the index only. No feed update from repository is performed.
>  	    -f :           Force updating feeds even if there are changed, uncommitted files.
>  
> +	setup [options] <type,name,link> <type,name,link> ...: generate feeds.conf
> +	Options:
> +	    -b :           Use feeds.conf.default as base for new feeds.conf.
> +
>  	clean:             Remove downloaded/generated files.
>  
>  EOF
> @@ -883,6 +919,7 @@ my %commands = (
>  	'search' => \&search,
>  	'uninstall' => \&uninstall,
>  	'feed_config' => \&feed_config,
> +	'setup' => \&setup,
>  	'clean' => sub {
>  		system("rm -rf ./feeds ./package/feeds");
>  	}
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20190604/1149724b/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list