feeds 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. chdir "$FindBin::Bin/..";
  11. $ENV{TOPDIR}=getcwd();
  12. $ENV{GIT_CONFIG_PARAMETERS}="'core.autocrlf=false'";
  13. $ENV{GREP_OPTIONS}="";
  14. my $mk=`which gmake 2>/dev/null`; # select the right 'make' program
  15. chomp($mk); # trim trailing newline
  16. $mk or $mk = "make"; # default to 'make'
  17. # check version of make
  18. my @mkver = split /\s+/, `$mk -v`, 4;
  19. my $valid_mk = 1;
  20. $mkver[0] =~ /^GNU/ or $valid_mk = 0;
  21. $mkver[1] =~ /^Make/ or $valid_mk = 0;
  22. $mkver[2] >= "3.81" or $valid_mk = 0;
  23. $valid_mk or die "Unsupported version of make found: $mk\n";
  24. my @feeds;
  25. my %build_packages;
  26. my %installed;
  27. my %feed_cache;
  28. my $feed_package = {};
  29. my $feed_src = {};
  30. sub parse_config() {
  31. my $line = 0;
  32. my %name;
  33. open FEEDS, "feeds.conf" or
  34. open FEEDS, "feeds.conf.default" or
  35. die "Unable to open feeds configuration";
  36. while (<FEEDS>) {
  37. chomp;
  38. s/#.+$//;
  39. next unless /\S/;
  40. my @line = split /\s+/, $_, 3;
  41. my @src;
  42. $line++;
  43. my $valid = 1;
  44. $line[0] =~ /^src-\w+$/ or $valid = 0;
  45. $line[1] =~ /^\w+$/ or $valid = 0;
  46. @src = split /\s+/, $line[2];
  47. $valid or die "Syntax error in feeds.conf, line: $line\n";
  48. $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n";
  49. $name{$line[1]} = 1;
  50. push @feeds, [$line[0], $line[1], \@src];
  51. }
  52. close FEEDS;
  53. }
  54. sub update_location($$)
  55. {
  56. my $name = shift;
  57. my $url = shift;
  58. my $old_url;
  59. -d "./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
  60. if( open LOC, "< ./feeds/$name.tmp/location" )
  61. {
  62. chomp($old_url = readline LOC);
  63. close LOC;
  64. }
  65. if( !$old_url || $old_url ne $url )
  66. {
  67. if( open LOC, "> ./feeds/$name.tmp/location" )
  68. {
  69. print LOC $url, "\n";
  70. close LOC;
  71. }
  72. return $old_url ? 1 : 0;
  73. }
  74. return 0;
  75. }
  76. sub update_index($)
  77. {
  78. my $name = shift;
  79. -d "./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
  80. -d "./feeds/$name.tmp/info" or mkdir "./feeds/$name.tmp/info" or return 1;
  81. system("$mk -s prepare-mk OPENWRT_BUILD= TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
  82. 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\"");
  83. system("ln -sf $name.tmp/.packageinfo ./feeds/$name.index");
  84. return 0;
  85. }
  86. my %update_method = (
  87. 'src-svn' => {
  88. 'init' => "svn checkout '%s' '%s'",
  89. 'update' => "svn update",
  90. 'controldir' => ".svn",
  91. 'revision' => "svn info | grep 'Revision' | cut -d ' ' -f 2 | tr -d '\n'"},
  92. 'src-cpy' => {
  93. 'init' => "cp -Rf '%s' '%s'",
  94. 'update' => "",
  95. 'revision' => "echo -n 'local'"},
  96. 'src-link' => {
  97. 'init' => "ln -s '%s' '%s'",
  98. 'update' => "",
  99. 'revision' => "echo -n 'local'"},
  100. 'src-git' => {
  101. 'init' => "git clone --depth 1 '%s' '%s'",
  102. 'init_branch' => "git clone --depth 1 --branch '%s' '%s' '%s'",
  103. 'init_commit' => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
  104. 'update' => "git pull --ff",
  105. 'controldir' => ".git",
  106. 'revision' => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
  107. 'src-gitsvn' => {
  108. 'init' => "git svn clone -r HEAD '%s' '%s'",
  109. 'update' => "git svn rebase",
  110. 'controldir' => ".git",
  111. 'revision' => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
  112. 'src-bzr' => {
  113. 'init' => "bzr checkout --lightweight '%s' '%s'",
  114. 'update' => "bzr update",
  115. 'controldir' => ".bzr"},
  116. 'src-hg' => {
  117. 'init' => "hg clone '%s' '%s'",
  118. 'update' => "hg pull --update",
  119. 'controldir' => ".hg"},
  120. 'src-darcs' => {
  121. 'init' => "darcs get '%s' '%s'",
  122. 'update' => "darcs pull -a",
  123. 'controldir' => "_darcs"},
  124. );
  125. # src-git: pull broken
  126. # src-cpy: broken if `basename $src` != $name
  127. sub update_feed_via($$$$) {
  128. my $type = shift;
  129. my $name = shift;
  130. my $src = shift;
  131. my $relocate = shift;
  132. my $m = $update_method{$type};
  133. my $localpath = "./feeds/$name";
  134. my $safepath = $localpath;
  135. $safepath =~ s/'/'\\''/;
  136. my ($base_branch, $branch) = split(/;/, $src, 2);
  137. my ($base_commit, $commit) = split(/\^/, $src, 2);
  138. if( $relocate || !$m->{'update'} || !-d "$localpath/$m->{'controldir'}" ) {
  139. system("rm -rf '$safepath'");
  140. if ($m->{'init_branch'} and $branch) {
  141. system(sprintf($m->{'init_branch'}, $branch, $base_branch, $safepath)) == 0 or return 1;
  142. } elsif ($m->{'init_commit'} and $commit) {
  143. system(sprintf($m->{'init_commit'}, $base_commit, $safepath, $safepath, $commit, $commit)) == 0 or return 1;
  144. } else {
  145. system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
  146. }
  147. } elsif ($m->{'init_commit'} and $commit) {
  148. # in case git hash has been provided don't update the feed
  149. } else {
  150. system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
  151. }
  152. return 0;
  153. }
  154. sub get_feed($) {
  155. my $feed = shift;
  156. if (!defined($feed_cache{$feed})) {
  157. my $file = "./feeds/$feed.index";
  158. clear_packages();
  159. -f $file or do {
  160. print "Ignoring feed '$feed' - index missing\n";
  161. return;
  162. };
  163. parse_package_metadata($file) or return;
  164. $feed_cache{$feed} = [ { %package }, { %srcpackage } ];
  165. }
  166. $feed_package = $feed_cache{$feed}->[0];
  167. $feed_src = $feed_cache{$feed}->[1];
  168. return $feed_cache{$feed}->[0];
  169. }
  170. sub get_installed() {
  171. system("$mk -s prepare-tmpinfo OPENWRT_BUILD=");
  172. clear_packages();
  173. parse_package_metadata("./tmp/.packageinfo");
  174. %installed = %package;
  175. }
  176. sub search_feed {
  177. my $feed = shift;
  178. my @substr = @_;
  179. my $display;
  180. return unless @substr > 0;
  181. get_feed($feed);
  182. foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
  183. my $pkg = $feed_package->{$name};
  184. my $substr;
  185. my $pkgmatch = 1;
  186. next if $pkg->{vdepends};
  187. foreach my $substr (@substr) {
  188. my $match;
  189. foreach my $key (qw(name title description src)) {
  190. $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
  191. }
  192. $match or undef $pkgmatch;
  193. };
  194. $pkgmatch and do {
  195. $display or do {
  196. print "Search results in feed '$feed':\n";
  197. $display = 1;
  198. };
  199. printf "\%-25s\t\%s\n", $pkg->{name}, $pkg->{title};
  200. };
  201. }
  202. return 0;
  203. }
  204. sub search {
  205. my %opts;
  206. getopt('r:', \%opts);
  207. foreach my $feed (@feeds) {
  208. search_feed($feed->[1], @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]);
  209. }
  210. }
  211. sub list_feed {
  212. my $feed = shift;
  213. get_feed($feed);
  214. foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
  215. my $pkg = $feed_package->{$name};
  216. next if $pkg->{vdepends};
  217. if($pkg->{name}) {
  218. printf "\%-32s\t\%s\n", $pkg->{name}, $pkg->{title};
  219. }
  220. }
  221. return 0;
  222. }
  223. sub list {
  224. my %opts;
  225. getopts('r:d:nsh', \%opts);
  226. if ($opts{h}) {
  227. usage();
  228. return 0;
  229. }
  230. if ($opts{n}) {
  231. foreach my $feed (@feeds) {
  232. printf "%s\n", $feed->[1];
  233. }
  234. return 0;
  235. }
  236. if ($opts{s}) {
  237. foreach my $feed (@feeds) {
  238. my $localpath = "./feeds/$feed->[1]";
  239. my $m = $update_method{$feed->[0]};
  240. my $revision;
  241. if( !$m->{'revision'} ) {
  242. $revision = "X";
  243. }
  244. elsif( $m->{'controldir'} && -d "$localpath/$m->{'controldir'}" ) {
  245. $revision = `cd '$localpath'; $m->{'revision'}`;
  246. }
  247. else {
  248. $revision = "local";
  249. }
  250. if ($opts{d}) {
  251. printf "%s%s%s%s%s%s%s\n", $feed->[1], $opts{d}, $feed->[0], $opts{d}, $revision, $opts{d}, join(", ", @{$feed->[2]});
  252. }
  253. else {
  254. printf "\%-8s \%-8s \%-8s \%s\n", $feed->[1], $feed->[0], $revision, join(", ", @{$feed->[2]});
  255. }
  256. }
  257. return 0;
  258. }
  259. foreach my $feed (@feeds) {
  260. list_feed($feed->[1], @ARGV) if (!defined($opts{r}) or $opts{r} eq $feed->[1]);
  261. }
  262. return 0;
  263. }
  264. sub install_generic() {
  265. my $feed = shift;
  266. my $pkg = shift;
  267. my $path = $pkg->{makefile};
  268. if($path) {
  269. $path =~ s/\/Makefile$//;
  270. -d "./package/feeds" or mkdir "./package/feeds";
  271. -d "./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
  272. system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
  273. } else {
  274. warn "Package is not valid\n";
  275. return 1;
  276. }
  277. return 0;
  278. }
  279. my %install_method = (
  280. 'src-svn' => \&install_generic,
  281. 'src-cpy' => \&install_generic,
  282. 'src-link' => \&install_generic,
  283. 'src-git' => \&install_generic,
  284. 'src-gitsvn' => \&install_generic,
  285. 'src-bzr' => \&install_generic,
  286. 'src-hg' => \&install_generic,
  287. 'src-darcs' => \&install_generic,
  288. );
  289. my %feed;
  290. sub lookup_package($$) {
  291. my $feed = shift;
  292. my $package = shift;
  293. foreach my $feed ($feed, @feeds) {
  294. next unless $feed->[1];
  295. next unless $feed{$feed->[1]};
  296. $feed{$feed->[1]}->{$package} and return $feed;
  297. }
  298. return;
  299. }
  300. sub is_core_package($) {
  301. my $package = shift;
  302. foreach my $file ("tmp/info/.packageinfo-$package", glob("tmp/info/.packageinfo-*_$package")) {
  303. next unless index($file, "tmp/info/.packageinfo-feeds_");
  304. return 1 if -s $file;
  305. }
  306. return 0;
  307. }
  308. sub install_package {
  309. my $feed = shift;
  310. my $name = shift;
  311. my $force = shift;
  312. my $ret = 0;
  313. $feed = lookup_package($feed, $name);
  314. $feed or do {
  315. $installed{$name} and return 0;
  316. # TODO: check if it's already installed within ./package directory
  317. $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";
  318. return 0;
  319. };
  320. # switch to the metadata for the selected feed
  321. get_feed($feed->[1]);
  322. my $pkg = $feed{$feed->[1]}->{$name} or return 1;
  323. $pkg->{name} or do {
  324. $installed{$name} and return 0;
  325. # TODO: check if this is an alias package, maybe it's known by another name
  326. warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
  327. return 0;
  328. };
  329. my $src = $pkg->{src};
  330. my $type = $feed->[0];
  331. $src or $src = $name;
  332. # If it's a core package and we don't want to override, just return
  333. !$force and is_core_package($src) and return 0;
  334. # previously installed packages set the runtime package
  335. # newly installed packages set the source package to 1
  336. $installed{$src} and $installed{$src} == 1 and return 0;
  337. # we'll trigger the override only with the 3 conditions below:
  338. # - override is allowed by command line (-f)
  339. # - a package with the same src exists in the core packages list
  340. # - the package previously installed is not from a feed
  341. my $override = 1 if ($force and is_core_package($src) and !$installed{$name}->{feed});
  342. # check previously installed packages
  343. $installed{$name} and !$override and return 0;
  344. $installed{$src} = 1;
  345. defined($override) and $override == 1
  346. and warn "Overriding package '$src'\n"
  347. or warn "Installing package '$src'\n";
  348. $install_method{$type} or do {
  349. warn "Unknown installation method: '$type'\n";
  350. return 1;
  351. };
  352. &{$install_method{$type}}($feed, $pkg) == 0 or do {
  353. warn "failed.\n";
  354. return 1;
  355. };
  356. # install all dependencies referenced from the source package
  357. foreach my $vpkg (@{$feed_src->{$src}}) {
  358. foreach my $dep (@{$vpkg->{depends}}, @{$vpkg->{builddepends}}, @{$vpkg->{"builddepends/host"}}) {
  359. next if $dep =~ /@/;
  360. $dep =~ s/^\+//;
  361. $dep =~ s/^.+://;
  362. $dep =~ s/\/.+$//;
  363. next unless $dep;
  364. install_package($feed, $dep, 0) == 0 or $ret = 1;
  365. }
  366. }
  367. return $ret;
  368. }
  369. sub refresh_config {
  370. my $default = shift;
  371. # workaround for timestamp check
  372. system("rm -f tmp/.packageinfo");
  373. # refresh the config
  374. if ($default) {
  375. system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
  376. } else {
  377. system("$mk defconfig Config.in >/dev/null 2>/dev/null");
  378. }
  379. }
  380. sub install {
  381. my $name;
  382. my %opts;
  383. my $feed;
  384. my $ret = 0;
  385. getopts('ap:d:fh', \%opts);
  386. if ($opts{h}) {
  387. usage();
  388. return 0;
  389. }
  390. get_installed();
  391. foreach my $f (@feeds) {
  392. # index all feeds
  393. $feed{$f->[1]} = get_feed($f->[1]);
  394. # look up the preferred feed
  395. $opts{p} and $f->[1] eq $opts{p} and $feed = $f;
  396. }
  397. if($opts{a}) {
  398. foreach my $f (@feeds) {
  399. if (!defined($opts{p}) or $opts{p} eq $f->[1]) {
  400. printf "Installing all packages from feed %s.\n", $f->[1];
  401. get_feed($f->[1]);
  402. foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
  403. my $p = $feed_package->{$name};
  404. next if $p->{vdepends};
  405. if( $p->{name} ) {
  406. install_package($feed, $p->{name}, exists($opts{f})) == 0 or $ret = 1;
  407. get_feed($f->[1]);
  408. }
  409. }
  410. }
  411. }
  412. } else {
  413. while ($name = shift @ARGV) {
  414. install_package($feed, $name, exists($opts{f})) == 0 or $ret = 1;
  415. }
  416. }
  417. # workaround for timestamp check
  418. # set the defaults
  419. if ($opts{d} and $opts{d} =~ /^[ymn]$/) {
  420. refresh_config($opts{d});
  421. }
  422. return $ret;
  423. }
  424. sub uninstall {
  425. my %opts;
  426. my $name;
  427. my $uninstall;
  428. getopts('ah', \%opts);
  429. if ($opts{h}) {
  430. usage();
  431. return 0;
  432. }
  433. if ($opts{a}) {
  434. system("rm -rvf ./package/feeds");
  435. $uninstall = 1;
  436. } else {
  437. if($#ARGV == -1) {
  438. warn "WARNING: no package to uninstall\n";
  439. return 0;
  440. }
  441. get_installed();
  442. while ($name = shift @ARGV) {
  443. my $pkg = $installed{$name};
  444. $pkg or do {
  445. warn "WARNING: $name not installed\n";
  446. next;
  447. };
  448. $pkg->{src} and $name = $pkg->{src};
  449. warn "Uninstalling package '$name'\n";
  450. system("rm -f ./package/feeds/*/$name");
  451. $uninstall = 1;
  452. }
  453. }
  454. $uninstall and refresh_config();
  455. return 0;
  456. }
  457. sub update_feed($$$$)
  458. {
  459. my $type=shift;
  460. my $name=shift;
  461. my $src=shift;
  462. my $perform_update=shift;
  463. my $force_relocate=update_location( $name, "@$src" );
  464. if( $force_relocate ) {
  465. warn "Source of feed $name has changed, replacing copy\n";
  466. }
  467. $update_method{$type} or do {
  468. warn "Unknown type '$type' in feed $name\n";
  469. return 1;
  470. };
  471. $perform_update and do {
  472. my $failed = 1;
  473. foreach my $feedsrc (@$src) {
  474. warn "Updating feed '$name' from '$feedsrc' ...\n";
  475. next unless update_feed_via($type, $name, $feedsrc, $force_relocate) == 0;
  476. $failed = 0;
  477. last;
  478. }
  479. $failed and do {
  480. warn "failed.\n";
  481. return 1;
  482. };
  483. };
  484. warn "Create index file './feeds/$name.index' \n";
  485. update_index($name) == 0 or do {
  486. warn "failed.\n";
  487. return 1;
  488. };
  489. return 0;
  490. }
  491. sub update {
  492. my %opts;
  493. my $feed_name;
  494. my $perform_update=1;
  495. $ENV{SCAN_COOKIE} = $$;
  496. $ENV{OPENWRT_VERBOSE} = 's';
  497. getopts('ahi', \%opts);
  498. if ($opts{h}) {
  499. usage();
  500. return 0;
  501. }
  502. if ($opts{i}) {
  503. # don't update from (remote) repository
  504. # only re-create index information
  505. $perform_update=0;
  506. }
  507. -d "feeds" or do {
  508. mkdir "feeds" or die "Unable to create the feeds directory";
  509. };
  510. if ( ($#ARGV == -1) or $opts{a}) {
  511. foreach my $feed (@feeds) {
  512. my ($type, $name, $src) = @$feed;
  513. next unless update_feed($type, $name, $src, $perform_update) == 1;
  514. last;
  515. }
  516. } else {
  517. while ($feed_name = shift @ARGV) {
  518. foreach my $feed (@feeds) {
  519. my ($type, $name, $src) = @$feed;
  520. if($feed_name ne $name) {
  521. next;
  522. }
  523. update_feed($type, $name, $src, $perform_update);
  524. }
  525. }
  526. }
  527. refresh_config();
  528. return 0;
  529. }
  530. sub feed_config() {
  531. foreach my $feed (@feeds) {
  532. my $installed = (-f "feeds/$feed->[1].index");
  533. printf "\tconfig FEED_%s\n", $feed->[1];
  534. printf "\t\tbool \"Enable feed %s\"\n", $feed->[1];
  535. printf "\t\tdepends on PER_FEED_REPO\n";
  536. printf "\t\tdefault y\n" if $installed;
  537. printf "\t\thelp\n";
  538. printf "\t\t Enable the \\\"%s\\\" feed at %s.\n", $feed->[1], $feed->[2][0];
  539. printf "\n";
  540. }
  541. return 0;
  542. }
  543. sub usage() {
  544. print <<EOF;
  545. Usage: $0 <command> [options]
  546. Commands:
  547. list [options]: List feeds, their content and revisions (if installed)
  548. Options:
  549. -n : List of feed names.
  550. -s : List of feed names and their URL.
  551. -r <feedname>: List packages of specified feed.
  552. -d <delimiter>: Use specified delimiter to distinguish rows (default: spaces)
  553. install [options] <package>: Install a package
  554. Options:
  555. -a : Install all packages from all feeds or from the specified feed using the -p option.
  556. -p <feedname>: Prefer this feed when installing packages.
  557. -d <y|m|n>: Set default for newly installed packages.
  558. -f : Install will be forced even if the package exists in core OpenWrt (override)
  559. search [options] <substring>: Search for a package
  560. Options:
  561. -r <feedname>: Only search in this feed
  562. uninstall -a|<package>: Uninstall a package
  563. Options:
  564. -a : Uninstalls all packages.
  565. update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
  566. Options:
  567. -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
  568. -i : Recreate the index only. No feed update from repository is performed.
  569. clean: Remove downloaded/generated files.
  570. EOF
  571. exit(1);
  572. }
  573. my %commands = (
  574. 'list' => \&list,
  575. 'update' => \&update,
  576. 'install' => \&install,
  577. 'search' => \&search,
  578. 'uninstall' => \&uninstall,
  579. 'feed_config' => \&feed_config,
  580. 'clean' => sub {
  581. system("rm -rf feeds");
  582. }
  583. );
  584. my $arg = shift @ARGV;
  585. $arg or usage();
  586. parse_config;
  587. foreach my $cmd (keys %commands) {
  588. $arg eq $cmd and do {
  589. exit(&{$commands{$cmd}}());
  590. };
  591. }
  592. usage();