+sub update_feed($$$$)
+{
+ my $type=shift;
+ my $name=shift;
+ my $src=shift;
+ my $perform_update=shift;
+ my $force_relocate=update_location( $name, "@$src" );
+
+ if( $force_relocate ) {
+ warn "Source of feed $name has changed, replacing copy\n";
+ }
+ $update_method{$type} or do {
+ warn "Unknown type '$type' in feed $name\n";
+ return 1;
+ };
+ $perform_update and do {
+ my $failed = 1;
+ foreach my $feedsrc (@$src) {
+ warn "Updating feed '$name' from '$feedsrc' ...\n";
+ next unless update_feed_via($type, $name, $feedsrc, $force_relocate) == 0;
+ $failed = 0;
+ last;
+ }
+ $failed and do {
+ warn "failed.\n";
+ return 1;
+ };
+ };
+ warn "Create index file './feeds/$name.index' \n";
+ update_index($name) == 0 or do {
+ warn "failed.\n";
+ return 1;
+ };
+ return 0;
+}
+
+sub update {
+ my %opts;
+ my $feed_name;
+ my $perform_update=1;
+
+ $ENV{SCAN_COOKIE} = $$;
+ $ENV{KBUILD_VERBOSE} = 99;
+
+ getopts('ahi', \%opts);
+
+ if ($opts{h}) {
+ usage();
+ return 0;
+ }
+
+ if ($opts{i}) {
+ # don't update from (remote) repository
+ # only re-create index information
+ $perform_update=0;
+ }
+
+ -d "feeds" or do {
+ mkdir "feeds" or die "Unable to create the feeds directory";
+ };
+
+ if ( ($#ARGV == -1) or $opts{a}) {
+ foreach my $feed (@feeds) {
+ my ($type, $name, $src) = @$feed;
+ update_feed($type, $name, $src, $perform_update);
+ }
+ } else {
+ while ($feed_name = shift @ARGV) {
+ foreach my $feed (@feeds) {
+ my ($type, $name, $src) = @$feed;
+ if($feed_name ne $name) {
+ next;
+ }
+ update_feed($type, $name, $src, $perform_update);
+ }
+ }
+ }
+
+ refresh_config();
+
+ return 0;
+}
+