5 use lib
"$FindBin::Bin";
11 chdir "$FindBin::Bin/..";
12 $ENV{TOPDIR
}=getcwd
();
14 my $mk=`which gmake`; # select the right 'make' program
15 chomp($mk); # trim trailing newline
16 $mk or $mk = "make"; # default to 'make'
18 # check version of make
19 my @mkver = split /\s+/, `$mk -v`, 4;
21 $mkver[0] =~ /^GNU/ or $valid_mk = 0;
22 $mkver[1] =~ /^Make/ or $valid_mk = 0;
23 $mkver[2] >= "3.81" or $valid_mk = 0;
24 $valid_mk or die "Unsupported version of make found: $mk\n";
31 my $feed_package = {};
38 open FEEDS
, "feeds.conf" or
39 open FEEDS
, "feeds.conf.default" or
40 die "Unable to open feeds configuration";
45 my @line = split /\s+/, $_, 3;
50 $line[0] =~ /^src-\w+$/ or $valid = 0;
51 $line[1] =~ /^\w+$/ or $valid = 0;
52 @src = split /\s+/, $line[2];
53 $valid or die "Syntax error in feeds.conf, line: $line\n";
55 $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n";
58 push @feeds, [$line[0], $line[1], \
@src];
63 sub update_location
($$)
69 -d
"./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
71 if( open LOC
, "< ./feeds/$name.tmp/location" )
73 chomp($old_url = readline LOC
);
77 if( !$old_url || $old_url ne $url )
79 if( open LOC
, "> ./feeds/$name.tmp/location" )
84 return $old_url ?
1 : 0;
94 -d
"./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
95 -d
"./feeds/$name.tmp/info" or mkdir "./feeds/$name.tmp/info" or return 1;
97 system("$mk -s prepare-mk TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
98 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\"");
99 system("ln -sf $name.tmp/.packageinfo ./feeds/$name.index");
104 my %update_method = (
106 'init' => "svn checkout '%s' '%s'",
107 'update' => "svn update",
108 'controldir' => ".svn"},
110 'init' => "cp -Rf '%s' '%s'",
113 'init' => "ln -s '%s' '%s'",
116 'init' => "git clone --depth 1 '%s' '%s'",
117 'update' => "git pull",
118 'controldir' => ".git"},
120 'init' => "bzr checkout --lightweight '%s' '%s'",
121 'update' => "bzr update",
122 'controldir' => ".bzr"},
124 'init' => "hg clone '%s' '%s'",
125 'update' => "hg pull --update",
126 'controldir' => ".hg"},
128 'init' => "darcs get '%s' '%s'",
129 'update' => "darcs pull -a",
130 'controldir' => "_darcs"},
133 # src-git: pull broken
134 # src-cpy: broken if `basename $src` != $name
136 sub update_feed_via
($$$$) {
140 my $relocate = shift;
142 my $m = $update_method{$type};
143 my $localpath = "./feeds/$name";
144 my $safepath = $localpath;
145 $safepath =~ s/'/'\\''/;
147 if( $relocate || !$m->{'update'} || !-d
"$localpath/$m->{'controldir'}" ) {
148 system("rm -rf '$safepath'");
149 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
151 system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
160 if (!defined($feed_cache{$feed})) {
161 my $file = "./feeds/$feed.index";
165 print "Ignoring feed '$feed' - index missing\n";
168 parse_package_metadata
($file) or return;
169 $feed_cache{$feed} = [ { %package }, { %srcpackage } ];
172 $feed_package = $feed_cache{$feed}->[0];
173 $feed_src = $feed_cache{$feed}->[1];
174 return $feed_cache{$feed}->[0];
177 sub get_installed
() {
178 system("$mk -s prepare-tmpinfo");
180 parse_package_metadata
("./tmp/.packageinfo");
181 %installed = %package;
189 return unless @substr > 0;
191 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
192 my $pkg = $feed_package->{$name};
196 next if $pkg->{vdepends
};
197 foreach my $substr (@substr) {
199 foreach my $key (qw(name title description src)) {
200 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
202 $match or undef $pkgmatch;
206 print "Search results in feed '$feed':\n";
209 printf "\%-25s\t\%s\n", $pkg->{name
}, $pkg->{title
};
218 getopt
('r:', \
%opts);
219 foreach my $feed (@feeds) {
220 search_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
228 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
229 my $pkg = $feed_package->{$name};
230 next if $pkg->{vdepends
};
232 printf "\%-32s\t\%s\n", $pkg->{name
}, $pkg->{title
};
242 getopts
('r:sh', \
%opts);
248 foreach my $feed (@feeds) {
249 printf "\%-32s\tURL: %s\n", $feed->[1], join(", ", @
{$feed->[2]});
253 foreach my $feed (@feeds) {
254 list_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
259 sub install_generic
() {
262 my $path = $pkg->{makefile
};
265 $path =~ s/\/Makefile$//;
267 -d
"./package/feeds" or mkdir "./package/feeds";
268 -d
"./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
269 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
271 warn "Package is not valid\n";
278 my %install_method = (
279 'src-svn' => \
&install_generic
,
280 'src-cpy' => \
&install_generic
,
281 'src-link' => \
&install_generic
,
282 'src-git' => \
&install_generic
,
283 'src-bzr' => \
&install_generic
,
284 'src-hg' => \
&install_generic
,
285 'src-darcs' => \
&install_generic
,
290 sub lookup_package
($$) {
294 foreach my $feed ($feed, @feeds) {
295 next unless $feed->[1];
296 next unless $feed{$feed->[1]};
297 $feed{$feed->[1]}->{$package} and return $feed;
302 sub install_package
{
307 $feed = lookup_package
($feed, $name);
309 $installed{$name} and return 0;
310 # TODO: check if it's already installed within ./package directory
311 $feed_src->{$name} or -d
"./package/$name" or warn "WARNING: No feed for package '$name' found, maybe it's already part of the standard packages?\n";
315 # switch to the metadata for the selected feed
316 get_feed
($feed->[1]);
318 my $pkg = $feed{$feed->[1]}->{$name} or return 1;
320 $installed{$name} and return 0;
321 # TODO: check if this is an alias package, maybe it's known by another name
322 warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
325 my $src = $pkg->{src
};
326 my $type = $feed->[0];
327 $src or $src = $name;
329 # previously installed packages set the runtime package
330 # newly installed packages set the source package
331 $installed{$src} and return 0;
333 # check previously installed packages
334 $installed{$name} and return 0;
335 $installed{$src} = 1;
336 warn "Installing package '$src'\n";
338 $install_method{$type} or do {
339 warn "Unknown installation method: '$type'\n";
343 &{$install_method{$type}}($feed, $pkg) == 0 or do {
348 # install all dependencies referenced from the source package
349 foreach my $vpkg (@
{$feed_src->{$src}}) {
350 foreach my $dep (@
{$vpkg->{depends
}}, @
{$vpkg->{builddepends
}}, @
{$vpkg->{"builddepends/host"}}) {
356 install_package
($feed, $dep) == 0 or $ret = 1;
366 # workaround for timestamp check
367 system("rm -f tmp/.packageinfo");
371 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
373 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
383 getopts
('ap:d:h', \
%opts);
392 foreach my $f (@feeds) {
394 $feed{$f->[1]} = get_feed
($f->[1]);
396 # look up the preferred feed
397 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
401 foreach my $f (@feeds) {
402 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
403 printf "Installing all packages from feed %s.\n", $f->[1];
405 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
406 my $p = $feed_package->{$name};
407 next if $p->{vdepends
};
409 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
416 while ($name = shift @ARGV) {
417 install_package
($feed, $name) == 0 or $ret = 1;
421 # workaround for timestamp check
424 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
425 refresh_config
($opts{d
});
436 getopts
('ah', \
%opts);
444 system("rm -rvf ./package/feeds");
448 warn "WARNING: no package to uninstall\n";
452 while ($name = shift @ARGV) {
453 my $pkg = $installed{$name};
455 warn "WARNING: $name not installed\n";
458 $pkg->{src
} and $name = $pkg->{src
};
459 warn "Uninstalling package '$name'\n";
460 system("rm -f ./package/feeds/*/$name");
464 $uninstall and refresh_config
();
468 sub update_feed
($$$$)
473 my $perform_update=shift;
474 my $force_relocate=update_location
( $name, "@$src" );
476 if( $force_relocate ) {
477 warn "Source of feed $name has changed, replacing copy\n";
479 $update_method{$type} or do {
480 warn "Unknown type '$type' in feed $name\n";
483 $perform_update and do {
485 foreach my $feedsrc (@
$src) {
486 warn "Updating feed '$name' from '$feedsrc' ...\n";
487 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
496 warn "Create index file './feeds/$name.index' \n";
497 update_index
($name) == 0 or do {
507 my $perform_update=1;
509 $ENV{SCAN_COOKIE
} = $$;
510 $ENV{KBUILD_VERBOSE
} = 99;
512 getopts
('ahi', \
%opts);
520 # don't update from (remote) repository
521 # only re-create index information
526 mkdir "feeds" or die "Unable to create the feeds directory";
529 if ( ($#ARGV == -1) or $opts{a
}) {
530 foreach my $feed (@feeds) {
531 my ($type, $name, $src) = @
$feed;
532 update_feed
($type, $name, $src, $perform_update);
535 while ($feed_name = shift @ARGV) {
536 foreach my $feed (@feeds) {
537 my ($type, $name, $src) = @
$feed;
538 if($feed_name ne $name) {
541 update_feed
($type, $name, $src, $perform_update);
553 Usage: $0 <command> [options]
556 list [options]: List feeds and their content
558 -s : List of feed names and their URL.
559 -r <feedname>: List packages of specified feed.
561 install [options] <package>: Install a package
563 -a : Install all packages from all feeds or from the specified feed using the -p option.
564 -p <feedname>: Prefer this feed when installing packages.
565 -d <y|m|n>: Set default for newly installed packages.
567 search [options] <substring>: Search for a package
569 -r <feedname>: Only search in this feed
571 uninstall -a|<package>: Uninstall a package
573 -a : Uninstalls all packages.
575 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
577 -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
578 -i : Recreate the index only. No feed update from repository is performed.
580 clean: Remove downloaded/generated files.
588 'update' => \
&update
,
589 'install' => \
&install
,
590 'search' => \
&search
,
591 'uninstall' => \
&uninstall
,
593 system("rm -rf feeds");
597 my $arg = shift @ARGV;
600 foreach my $cmd (keys %commands) {
601 $arg eq $cmd and do {
602 exit(&{$commands{$cmd}}());
This page took 0.093541 seconds and 5 git commands to generate.