feeds 19 KB

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