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