ramips: add switch port index for I-O DATA WN-GX300GR
[openwrt/openwrt.git] / scripts / feeds
1 #!/usr/bin/env perl
2 use Getopt::Std;
3 use FindBin;
4 use Cwd;
5 use lib "$FindBin::Bin";
6 use metadata;
7 use warnings;
8 use strict;
9 use Cwd 'abs_path';
10
11 chdir "$FindBin::Bin/..";
12 $ENV{TOPDIR} //= getcwd();
13 chdir $ENV{TOPDIR};
14 $ENV{GIT_CONFIG_PARAMETERS}="'core.autocrlf=false'";
15 $ENV{GREP_OPTIONS}="";
16
17 my $mk=`which gmake 2>/dev/null`; # select the right 'make' program
18 chomp($mk); # trim trailing newline
19 $mk or $mk = "make"; # default to 'make'
20
21 # check version of make
22 my @mkver = split /\s+/, `$mk -v`, 4;
23 my $valid_mk = 1;
24 $mkver[0] =~ /^GNU/ or $valid_mk = 0;
25 $mkver[1] =~ /^Make/ or $valid_mk = 0;
26
27 my ($mkv1, $mkv2) = split /\./, $mkver[2];
28 ($mkv1 >= 4 || ($mkv1 == 3 && $mkv2 >= 81)) or $valid_mk = 0;
29
30 $valid_mk or die "Unsupported version of make found: $mk\n";
31
32 my @feeds;
33 my %build_packages;
34 my %installed;
35 my %installed_pkg;
36 my %installed_targets;
37 my %feed_cache;
38
39 my $feed_package = {};
40 my $feed_src = {};
41 my $feed_target = {};
42 my $feed_vpackage = {};
43
44 sub parse_config() {
45 my $line = 0;
46 my %name;
47
48 open FEEDS, "feeds.conf" or
49 open FEEDS, "feeds.conf.default" or
50 die "Unable to open feeds configuration";
51 while (<FEEDS>) {
52 chomp;
53 s/#.+$//;
54 next unless /\S/;
55 my @line = split /\s+/, $_, 3;
56 my @src;
57 $line++;
58
59 my $valid = 1;
60 $line[0] =~ /^src-[\w-]+$/ or $valid = 0;
61 $line[1] =~ /^\w+$/ or $valid = 0;
62 @src = split /\s+/, $line[2];
63 $valid or die "Syntax error in feeds.conf, line: $line\n";
64
65 $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n";
66 $name{$line[1]} = 1;
67
68 push @feeds, [$line[0], $line[1], \@src];
69 }
70 close FEEDS;
71 }
72
73 sub update_location($$)
74 {
75 my $name = shift;
76 my $url = shift;
77 my $old_url;
78
79 -d "./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
80
81 if( open LOC, "< ./feeds/$name.tmp/location" )
82 {
83 chomp($old_url = readline LOC);
84 close LOC;
85 }
86
87 if( !$old_url || $old_url ne $url )
88 {
89 if( open LOC, "> ./feeds/$name.tmp/location" )
90 {
91 print LOC $url, "\n";
92 close LOC;
93 }
94 return $old_url ? 1 : 0;
95 }
96
97 return 0;
98 }
99
100 sub update_index($)
101 {
102 my $name = shift;
103
104 -d "./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
105 -d "./feeds/$name.tmp/info" or mkdir "./feeds/$name.tmp/info" or return 1;
106
107 system("$mk -s prepare-mk OPENWRT_BUILD= TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
108 system("$mk -s -f include/scan.mk IS_TTY=1 SCAN_TARGET=\"packageinfo\" SCAN_DIR=\"feeds/$name\" SCAN_NAME=\"package\" SCAN_DEPS=\"$ENV{TOPDIR}/include/package*.mk\" SCAN_DEPTH=5 SCAN_EXTRA=\"\" TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
109 system("$mk -s -f include/scan.mk IS_TTY=1 SCAN_TARGET=\"targetinfo\" SCAN_DIR=\"feeds/$name\" SCAN_NAME=\"target\" SCAN_DEPS=\"profiles/*.mk $ENV{TOPDIR}/include/target.mk\" SCAN_DEPTH=5 SCAN_EXTRA=\"\" SCAN_MAKEOPTS=\"TARGET_BUILD=1\" TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
110 system("ln -sf $name.tmp/.packageinfo ./feeds/$name.index");
111 system("ln -sf $name.tmp/.targetinfo ./feeds/$name.targetindex");
112
113 return 0;
114 }
115
116 my %update_method = (
117 'src-svn' => {
118 'init' => "svn checkout '%s' '%s'",
119 'update' => "svn update",
120 'controldir' => ".svn",
121 'revision' => "svn info | grep 'Revision' | cut -d ' ' -f 2 | tr -d '\n'"},
122 'src-cpy' => {
123 'init' => "cp -Rf '%s' '%s'",
124 'update' => "",
125 'revision' => "echo -n 'local'"},
126 'src-link' => {
127 'init' => "ln -s '%s' '%s'",
128 'update' => "",
129 'revision' => "echo -n 'local'"},
130 'src-git' => {
131 'init' => "git clone --depth 1 '%s' '%s'",
132 'init_branch' => "git clone --depth 1 --branch '%s' '%s' '%s'",
133 'init_commit' => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
134 'update' => "git pull --ff",
135 'update_force' => "git pull --ff || (git reset --hard HEAD; git pull --ff; exit 1)",
136 'post_update' => "git submodule update --init --recursive",
137 'controldir' => ".git",
138 'revision' => "git rev-parse --short HEAD | tr -d '\n'"},
139 'src-git-full' => {
140 'init' => "git clone '%s' '%s'",
141 'init_branch' => "git clone --branch '%s' '%s' '%s'",
142 'init_commit' => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
143 'update' => "git pull --ff",
144 'update_force' => "git pull --ff || (git reset --hard HEAD; git pull --ff; exit 1)",
145 'post_update' => "git submodule update --init --recursive",
146 'controldir' => ".git",
147 'revision' => "git rev-parse --short HEAD | tr -d '\n'"},
148 'src-gitsvn' => {
149 'init' => "git svn clone -r HEAD '%s' '%s'",
150 'update' => "git svn rebase",
151 'controldir' => ".git",
152 'revision' => "git rev-parse --short HEAD | tr -d '\n'"},
153 'src-bzr' => {
154 'init' => "bzr checkout --lightweight '%s' '%s'",
155 'update' => "bzr update",
156 'controldir' => ".bzr"},
157 'src-hg' => {
158 'init' => "hg clone '%s' '%s'",
159 'update' => "hg pull --update",
160 'controldir' => ".hg"},
161 'src-darcs' => {
162 'init' => "darcs get '%s' '%s'",
163 'update' => "darcs pull -a",
164 'controldir' => "_darcs"},
165 );
166
167 # src-git: pull broken
168 # src-cpy: broken if `basename $src` != $name
169
170 sub update_feed_via($$$$$) {
171 my $type = shift;
172 my $name = shift;
173 my $src = shift;
174 my $relocate = shift;
175 my $force = shift;
176
177 my $m = $update_method{$type};
178 my $localpath = "./feeds/$name";
179 my $safepath = $localpath;
180 $safepath =~ s/'/'\\''/;
181 my ($base_branch, $branch) = split(/;/, $src, 2);
182 my ($base_commit, $commit) = split(/\^/, $src, 2);
183
184 if( $relocate || !$m->{'update'} || !-d "$localpath/$m->{'controldir'}" ) {
185 system("rm -rf '$safepath'");
186 if ($m->{'init_branch'} and $branch) {
187 system(sprintf($m->{'init_branch'}, $branch, $base_branch, $safepath)) == 0 or return 1;
188 } elsif ($m->{'init_commit'} and $commit) {
189 system(sprintf($m->{'init_commit'}, $base_commit, $safepath, $safepath, $commit, $commit)) == 0 or return 1;
190 } else {
191 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
192 }
193 } elsif ($m->{'init_commit'} and $commit) {
194 # in case git hash has been provided don't update the feed
195 } else {
196 my $update_cmd = $m->{'update'};
197 if ($force && exists $m->{'update_force'}) {
198 $update_cmd = $m->{'update_force'};
199 }
200 system("cd '$safepath'; $update_cmd") == 0 or return 1;
201 }
202 if ($m->{'post_update'}) {
203 my $cmd = $m->{'post_update'};
204 system("cd '$safepath'; $cmd") == 0 or return 1;
205 }
206
207 return 0;
208 }
209
210 sub get_targets($) {
211 my $file = shift;
212 my @target = parse_target_metadata($file);
213 my %target;
214 foreach my $target (@target) {
215 $target{$target->{id}} = $target;
216 }
217 return %target
218 }
219
220 sub get_feed($) {
221 my $feed = shift;
222
223 if (!defined($feed_cache{$feed})) {
224 my $file = "./feeds/$feed.index";
225
226 clear_packages();
227 -f $file or do {
228 print "Ignoring feed '$feed' - index missing\n";
229 return;
230 };
231 parse_package_metadata($file) or return;
232 my %target = get_targets("./feeds/$feed.targetindex");
233
234 $feed_cache{$feed} = [ { %package }, { %srcpackage }, { %target }, { %vpackage } ];
235 }
236
237 $feed_package = $feed_cache{$feed}->[0];
238 $feed_src = $feed_cache{$feed}->[1];
239 $feed_target = $feed_cache{$feed}->[2];
240 $feed_vpackage = $feed_cache{$feed}->[3];
241 }
242
243 sub get_installed() {
244 system("$mk -s prepare-tmpinfo OPENWRT_BUILD=");
245 clear_packages();
246 parse_package_metadata("./tmp/.packageinfo");
247 %installed_pkg = %vpackage;
248 %installed = %srcpackage;
249 %installed_targets = get_targets("./tmp/.targetinfo");
250 }
251
252 sub search_feed {
253 my $feed = shift;
254 my @substr = @_;
255 my $display;
256
257 return unless @substr > 0;
258 get_feed($feed);
259 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
260 my $pkg = $feed_package->{$name};
261 my $substr;
262 my $pkgmatch = 1;
263
264 foreach my $substr (@substr) {
265 my $match;
266 foreach my $key (qw(name title description src)) {
267 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
268 }
269 $match or undef $pkgmatch;
270 };
271 $pkgmatch and do {
272 $display or do {
273 print "Search results in feed '$feed':\n";
274 $display = 1;
275 };
276 printf "\%-25s\t\%s\n", $pkg->{name}, $pkg->{title};
277 };
278 }
279
280 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_target) {
281 my $target = $feed_target->{$name};
282 my $targetmatch = 1;
283
284 foreach my $substr (@substr) {
285 my $match;
286 foreach my $key (qw(id name description)) {
287 $target->{$key} and $substr and $target->{$key} =~ m/$substr/i and $match = 1;
288 }
289 $match or undef $targetmatch;
290 };
291 $targetmatch and do {
292 $display or do {
293 print "Search results in feed '$feed':\n";
294 $display = 1;
295 };
296 printf "TARGET: \%-17s\t\%s\n", $target->{id}, $target->{name};
297 };
298 }
299 return 0;
300 }
301
302 sub search {
303 my %opts;
304
305 getopt('r:', \%opts);
306 foreach my $feed (@feeds) {
307 search_feed($feed->[1], @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]);
308 }
309 }
310
311 sub list_feed {
312 my $feed = shift;
313
314 get_feed($feed);
315 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
316 my $pkg = $feed_package->{$name};
317 if($pkg->{name}) {
318 printf "\%-32s\t\%s\n", $pkg->{name}, $pkg->{title};
319 }
320 }
321
322 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_target) {
323 my $target = $feed_target->{$name};
324 if($target->{name}) {
325 printf "TARGET: \%-24s\t\%s\n", $target->{id}, $target->{name};
326 }
327 }
328
329 return 0;
330 }
331
332 sub list {
333 my %opts;
334
335 getopts('r:d:nshf', \%opts);
336 if ($opts{h}) {
337 usage();
338 return 0;
339 }
340 if ($opts{n}) {
341 foreach my $feed (@feeds) {
342 printf "%s\n", $feed->[1];
343 }
344 return 0;
345 }
346 if ($opts{s}) {
347 foreach my $feed (@feeds) {
348 my $localpath = "./feeds/$feed->[1]";
349 my $m = $update_method{$feed->[0]};
350 my $revision;
351 if (!-d "$localpath" || !$m->{'revision'}) {
352 $revision = "X";
353 }
354 elsif( $m->{'controldir'} && -d "$localpath/$m->{'controldir'}" ) {
355 $revision = `cd '$localpath'; $m->{'revision'}`;
356 }
357 else {
358 $revision = "local";
359 }
360 if ($opts{d}) {
361 printf "%s%s%s%s%s%s%s\n", $feed->[1], $opts{d}, $feed->[0], $opts{d}, $revision, $opts{d}, join(", ", @{$feed->[2]});
362 }
363 elsif ($opts{f}) {
364 my $uri = join(", ", @{$feed->[2]});
365 if ($revision ne "local" && $revision ne "X") {
366 $uri =~ s/[;^].*//;
367 $uri .= "^" . $revision;
368 }
369 printf "%s %s %s\n", $feed->[0], $feed->[1], $uri;
370 }
371 else {
372 printf "\%-10s \%-8s \%-8s \%s\n", $feed->[1], $feed->[0], $revision, join(", ", @{$feed->[2]});
373 }
374 }
375 return 0;
376 }
377 foreach my $feed (@feeds) {
378 list_feed($feed->[1], @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]);
379 }
380 return 0;
381 }
382
383 sub do_install_src($$) {
384 my $feed = shift;
385 my $src = shift;
386
387 my $path = $src->{makefile};
388 if ($path) {
389 $path =~ s/\/Makefile$//;
390
391 -d "./package/feeds" or mkdir "./package/feeds";
392 -d "./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
393 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
394 } else {
395 warn "Package is not valid\n";
396 return 1;
397 }
398
399 return 0;
400 }
401
402 sub do_install_target($) {
403 my $target = shift;
404 my $path = $target->{makefile};
405
406 if ($path) {
407 $path =~ s/\/Makefile$//;
408 my $name = $path;
409 $name =~ s/.*\///;
410 my $dest = "./target/linux/$name";
411
412 -e $dest and do {
413 warn "Path $dest already exists";
414 return 1;
415 };
416
417 system("ln -sf ../../$path ./target/linux/");
418 } else {
419 warn "Target is not valid\n";
420 return 1;
421 }
422
423 return 0;
424 }
425
426 sub lookup_src($$) {
427 my $feed = shift;
428 my $src = shift;
429
430 foreach my $feed ($feed, @feeds) {
431 next unless $feed->[1];
432 next unless $feed_cache{$feed->[1]};
433 $feed_cache{$feed->[1]}->[1]->{$src} and return $feed;
434 }
435 return;
436 }
437
438 sub lookup_package($$) {
439 my $feed = shift;
440 my $package = shift;
441
442 foreach my $feed ($feed, @feeds) {
443 next unless $feed->[1];
444 next unless $feed_cache{$feed->[1]};
445 $feed_cache{$feed->[1]}->[3]->{$package} and return $feed;
446 }
447 return;
448 }
449
450 sub lookup_target($$) {
451 my $feed = shift;
452 my $target = shift;
453
454 foreach my $feed ($feed, @feeds) {
455 next unless $feed->[1];
456 next unless $feed_cache{$feed->[1]};
457 $feed_cache{$feed->[1]}->[2]->{$target} and return $feed;
458 }
459 return;
460 }
461
462 sub is_core_src($) {
463 my $src = shift;
464 foreach my $file ("tmp/info/.packageinfo-$src", glob("tmp/info/.packageinfo-*_$src")) {
465 next unless index($file, "tmp/info/.packageinfo-feeds_");
466 return 1 if -s $file;
467 }
468 return 0;
469 }
470
471 sub install_target {
472 my $feed = shift;
473 my $name = shift;
474
475 $installed_targets{$name} and return 0;
476
477 $feed = $feed_cache{$feed->[1]}->[2];
478 $feed or return 0;
479
480 my $target = $feed->{$name};
481 $target or return 0;
482
483 warn "Installing target '$name'\n";
484 return do_install_target($target);
485 }
486
487 sub install_src {
488 my $feed = shift;
489 my $name = shift;
490 my $force = shift;
491 my $ret = 0;
492
493 $feed = lookup_src($feed, $name);
494 unless ($feed) {
495 $installed{$name} and return 0;
496 $feed_src->{$name} or warn "WARNING: No feed for source package '$name' found\n";
497 return 0;
498 }
499
500 # switch to the metadata for the selected feed
501 get_feed($feed->[1]);
502 my $src = $feed_src->{$name} or return 1;
503
504 # If it's a core package and we don't want to override, just return
505 my $override = 0;
506 if (is_core_src($name)) {
507 return 0 unless $force;
508 $override = 1;
509 }
510
511 if ($installed{$name}) {
512 # newly installed packages set the source package to 1
513 return 0 if ($installed{$name} == 1);
514 return 0 unless ($override);
515 }
516
517 $installed{$name} = 1;
518 foreach my $pkg (@{$src->{packages}}) {
519 foreach my $vpkg (@{$pkg->{provides}}) {
520 $installed_pkg{$vpkg} = 1;
521 }
522 }
523
524 if ($override) {
525 warn "Overriding core package '$name' with version from $feed->[1]\n";
526 } else {
527 warn "Installing package '$name' from $feed->[1]\n";
528 }
529
530 do_install_src($feed, $src) == 0 or do {
531 warn "failed.\n";
532 return 1;
533 };
534
535 # install all dependencies referenced from the source package
536 foreach my $dep (
537 @{$src->{builddepends}},
538 @{$src->{'builddepends/host'}},
539 ) {
540 next if $dep =~ /@/;
541 $dep =~ s/^.+://;
542 $dep =~ s/\/.+$//;
543 next unless $dep;
544 install_src($feed, $dep, 0) == 0 or $ret = 1;
545 }
546
547 foreach my $pkg (@{$src->{packages}}) {
548 foreach my $dep (@{$pkg->{depends}}) {
549 next if $dep =~ /@/;
550 $dep =~ s/^\+//;
551 $dep =~ s/^.+://;
552 next unless $dep;
553 install_package($feed, $dep, 0) == 0 or $ret = 1;
554 }
555 }
556
557 return $ret;
558 }
559
560 sub install_package {
561 my $feed = shift;
562 my $name = shift;
563 my $force = shift;
564
565 $feed = lookup_package($feed, $name);
566 unless ($feed) {
567 $installed_pkg{$name} and return 0;
568 $feed_vpackage->{$name} or warn "WARNING: No feed for package '$name' found\n";
569 return 0;
570 }
571
572 # switch to the metadata for the selected feed
573 get_feed($feed->[1]);
574 my $pkg = $feed_vpackage->{$name} or return 1;
575 return install_src($feed, $pkg->[0]{src}{name}, $force);
576 }
577
578 sub install_target_or_package {
579 my $feed = shift;
580 my $name = shift;
581 my $force = shift;
582
583 my $this_feed_target = lookup_target($feed, $name);
584 $this_feed_target and do {
585 return install_target($this_feed_target, $name);
586 };
587
588 my $this_feed_src = lookup_src($feed, $name);
589 $this_feed_src and do {
590 return install_src($this_feed_src, $name, $force);
591 };
592
593 return install_package($feed, $name, $force);
594 }
595
596 sub refresh_config {
597 my $default = shift;
598
599 # Don't create .config if it doesn't already exist so that making a
600 # config only occurs when the user intends it do (however we do
601 # want to refresh an existing config).
602 return if not (-e '.config');
603
604 # workaround for timestamp check
605 system("rm -f tmp/.packageinfo");
606
607 # refresh the config
608 if ($default) {
609 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
610 } else {
611 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
612 }
613 }
614
615 sub install {
616 my $name;
617 my %opts;
618 my $feed;
619 my $ret = 0;
620
621 getopts('ap:d:fh', \%opts);
622
623 if ($opts{h}) {
624 usage();
625 return 0;
626 }
627
628 get_installed();
629
630 foreach my $f (@feeds) {
631 # fetch all feeds
632 get_feed($f->[1]);
633
634 # look up the preferred feed
635 $opts{p} and $f->[1] eq $opts{p} and $feed = $f;
636 }
637
638 if($opts{a}) {
639 foreach my $f (@feeds) {
640 if (!defined($opts{p}) or $opts{p} eq $f->[1]) {
641 printf "Installing all packages from feed %s.\n", $f->[1];
642 get_feed($f->[1]);
643 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_src) {
644 install_src($feed, $name, exists($opts{f})) == 0 or $ret = 1;
645 get_feed($f->[1]);
646 }
647 }
648 }
649 } else {
650 while ($name = shift @ARGV) {
651 install_target_or_package($feed, $name, exists($opts{f})) == 0 or $ret = 1;
652 }
653 }
654
655 # workaround for timestamp check
656
657 # set the defaults
658 if ($opts{d} and $opts{d} =~ /^[ymn]$/) {
659 refresh_config($opts{d});
660 }
661
662 return $ret;
663 }
664
665 sub uninstall_target($) {
666 my $dir = shift;
667 my $name = $dir;
668 $name =~ s/.*\///g;
669
670 my $dest = readlink $dir;
671 return unless $dest =~ /..\/..\/feeds/;
672 warn "Uninstalling target '$name'\n";
673 unlink "$dir";
674 }
675
676 sub uninstall {
677 my %opts;
678 my $name;
679 my $uninstall;
680
681 getopts('ah', \%opts);
682
683 if ($opts{h}) {
684 usage();
685 return 0;
686 }
687
688 if ($opts{a}) {
689 system("rm -rvf ./package/feeds");
690 foreach my $dir (glob "target/linux/*") {
691 next unless -l $dir;
692 uninstall_target($dir);
693 }
694 $uninstall = 1;
695 } else {
696 if($#ARGV == -1) {
697 warn "WARNING: no package to uninstall\n";
698 return 0;
699 }
700 get_installed();
701 while ($name = shift @ARGV) {
702 my $target = "target/linux/$name";
703 -l "$target" and do {
704 uninstall_target($target);
705 $uninstall = 1;
706 next;
707 };
708
709 my $pkg = $installed{$name};
710 $pkg or do {
711 warn "WARNING: $name not installed\n";
712 next;
713 };
714 $pkg->{src} and $name = $pkg->{src}{name};
715 warn "Uninstalling package '$name'\n";
716 system("rm -f ./package/feeds/*/$name");
717 $uninstall = 1;
718 }
719 }
720 $uninstall and refresh_config();
721 return 0;
722 }
723
724 sub update_feed($$$$$)
725 {
726 my $type=shift;
727 my $name=shift;
728 my $src=shift;
729 my $perform_update=shift;
730 my $force_update=shift;
731 my $force_relocate=update_location( $name, "@$src" );
732 my $rv=0;
733
734 if( $force_relocate ) {
735 warn "Source of feed $name has changed, replacing copy\n";
736 }
737 $update_method{$type} or do {
738 warn "Unknown type '$type' in feed $name\n";
739 return 1;
740 };
741 $perform_update and do {
742 my $failed = 1;
743 foreach my $feedsrc (@$src) {
744 warn "Updating feed '$name' from '$feedsrc' ...\n";
745 if (update_feed_via($type, $name, $feedsrc, $force_relocate, $force_update) != 0) {
746 if ($force_update) {
747 $rv=1;
748 $failed=0;
749 warn "failed, ignore.\n";
750 next;
751 }
752 last;
753 }
754 $failed = 0;
755 }
756 $failed and do {
757 warn "failed.\n";
758 return 1;
759 };
760 };
761 warn "Create index file './feeds/$name.index' \n";
762 update_index($name) == 0 or do {
763 warn "failed.\n";
764 return 1;
765 };
766 return $rv;
767 }
768
769 sub update {
770 my %opts;
771 my $feed_name;
772 my $perform_update=1;
773 my $failed=0;
774
775 $ENV{SCAN_COOKIE} = $$;
776 $ENV{OPENWRT_VERBOSE} = 's';
777
778 getopts('ahif', \%opts);
779
780 if ($opts{h}) {
781 usage();
782 return 0;
783 }
784
785 if ($opts{i}) {
786 # don't update from (remote) repository
787 # only re-create index information
788 $perform_update=0;
789 }
790
791 -d "feeds" or do {
792 mkdir "feeds" or die "Unable to create the feeds directory";
793 };
794
795 if ( ($#ARGV == -1) or $opts{a}) {
796 foreach my $feed (@feeds) {
797 my ($type, $name, $src) = @$feed;
798 update_feed($type, $name, $src, $perform_update, $opts{f}) == 0 or $failed=1;
799 }
800 } else {
801 while ($feed_name = shift @ARGV) {
802 foreach my $feed (@feeds) {
803 my ($type, $name, $src) = @$feed;
804 if($feed_name ne $name) {
805 next;
806 }
807 update_feed($type, $name, $src, $perform_update, $opts{f}) == 0 or $failed=1;
808 }
809 }
810 }
811
812 refresh_config();
813
814 return $failed;
815 }
816
817 sub feed_config() {
818 foreach my $feed (@feeds) {
819 my $installed = (-f "feeds/$feed->[1].index");
820
821 printf "\tconfig FEED_%s\n", $feed->[1];
822 printf "\t\tbool \"Enable feed %s\"\n", $feed->[1];
823 printf "\t\tdepends on PER_FEED_REPO\n";
824 printf "\t\tdefault y\n" if $installed;
825 printf "\t\thelp\n";
826 printf "\t\t Enable the \\\"%s\\\" feed at %s.\n", $feed->[1], $feed->[2][0];
827 printf "\n";
828 }
829
830 return 0;
831 }
832
833 sub usage() {
834 print <<EOF;
835 Usage: $0 <command> [options]
836
837 Commands:
838 list [options]: List feeds, their content and revisions (if installed)
839 Options:
840 -n : List of feed names.
841 -s : List of feed names and their URL.
842 -r <feedname>: List packages of specified feed.
843 -d <delimiter>: Use specified delimiter to distinguish rows (default: spaces)
844 -f : List feeds in feeds.conf compatible format (when using -s).
845
846 install [options] <package>: Install a package
847 Options:
848 -a : Install all packages from all feeds or from the specified feed using the -p option.
849 -p <feedname>: Prefer this feed when installing packages.
850 -d <y|m|n>: Set default for newly installed packages.
851 -f : Install will be forced even if the package exists in core OpenWrt (override)
852
853 search [options] <substring>: Search for a package
854 Options:
855 -r <feedname>: Only search in this feed
856
857 uninstall -a|<package>: Uninstall a package
858 Options:
859 -a : Uninstalls all packages.
860
861 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
862 Options:
863 -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
864 -i : Recreate the index only. No feed update from repository is performed.
865 -f : Force updating feeds even if there are changed, uncommitted files.
866
867 clean: Remove downloaded/generated files.
868
869 EOF
870 exit(1);
871 }
872
873 my %commands = (
874 'list' => \&list,
875 'update' => \&update,
876 'install' => \&install,
877 'search' => \&search,
878 'uninstall' => \&uninstall,
879 'feed_config' => \&feed_config,
880 'clean' => sub {
881 system("rm -rf ./feeds ./package/feeds");
882 }
883 );
884
885 my $arg = shift @ARGV;
886 $arg or usage();
887 parse_config;
888 foreach my $cmd (keys %commands) {
889 $arg eq $cmd and do {
890 exit(&{$commands{$cmd}}());
891 };
892 }
893 usage();