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

John Crispin john at phrozen.org
Tue Jun 4 01:55:52 EDT 2019


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
 
 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;
+
+		$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");
 	}
-- 
2.20.1


_______________________________________________
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