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