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";
34 open FEEDS
, "feeds.conf" or
35 open FEEDS
, "feeds.conf.default" or
36 die "Unable to open feeds configuration";
41 my @line = split /\s+/, $_, 3;
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.list, line: $line\n";
51 $name{$line[1]} and die "Duplicate feed name '$line[1]', line: $line\n";
54 push @feeds, [$line[0], $line[1], \
@src];
59 sub update_location
($$)
65 -d
"./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
67 if( open LOC
, "< ./feeds/$name.tmp/location" )
69 chomp($old_url = readline LOC
);
73 if( !$old_url || $old_url ne $url )
75 if( open LOC
, "> ./feeds/$name.tmp/location" )
80 return $old_url ?
1 : 0;
90 -d
"./feeds/$name.tmp" or mkdir "./feeds/$name.tmp" or return 1;
91 -d
"./feeds/$name.tmp/info" or mkdir "./feeds/$name.tmp/info" or return 1;
93 system("$mk -s prepare-mk TMP_DIR=\"$ENV{TOPDIR}/feeds/$name.tmp\"");
94 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\"");
95 system("ln -sf $name.tmp/.packageinfo ./feeds/$name.index");
100 my %update_method = (
102 'init' => "svn checkout '%s' '%s'",
103 'update' => "svn update",
104 'controldir' => ".svn"},
106 'init' => "cp -Rf '%s' '%s'",
109 'init' => "ln -s '%s' '%s'",
112 'init' => "git clone --depth 1 '%s' '%s'",
113 'update' => "git pull",
114 'controldir' => ".git"},
116 'init' => "bzr checkout --lightweight '%s' '%s'",
117 'update' => "bzr update",
118 'controldir' => ".bzr"},
120 'init' => "hg clone '%s' '%s'",
121 'update' => "hg pull --update",
122 'controldir' => ".hg"}
125 # src-git: pull broken
126 # src-cpy: broken if `basename $src` != $name
128 sub update_feed_via
($$$$) {
132 my $relocate = shift;
134 my $m = $update_method{$type};
135 my $localpath = "./feeds/$name";
136 my $safepath = $localpath;
137 $safepath =~ s/'/'\\''/;
139 if( $relocate || !$m->{'update'} || !-d
"$localpath/$m->{'controldir'}" ) {
140 system("rm -rf '$safepath'");
141 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
143 system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
151 my $file = "./feeds/$feed.index";
156 print "Ignoring feed '$feed' - index missing\n";
159 parse_package_metadata
($file) or return;
163 sub get_installed
() {
164 system("$mk -s prepare-tmpinfo");
166 parse_package_metadata
("./tmp/.packageinfo");
167 %installed = %package;
175 return unless @substr > 0;
177 foreach my $name (sort { lc($a) cmp lc($b) } keys %package) {
178 my $pkg = $package{$name};
182 foreach my $substr (@substr) {
184 foreach my $key (qw(name title description src)) {
185 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
187 $match or undef $pkgmatch;
191 print "Search results in feed '$feed':\n";
194 printf "\%-25s\t\%s\n", $pkg->{name
}, $pkg->{title
};
203 getopt
('r:', \
%opts);
204 foreach my $feed (@feeds) {
205 search_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
213 foreach my $name (sort { lc($a) cmp lc($b) } keys %package) {
214 my $pkg = $package{$name};
216 printf "\%-32s\t\%s\n", $pkg->{name
}, $pkg->{title
};
226 getopts
('r:sh', \
%opts);
232 foreach my $feed (@feeds) {
233 printf "\%-32s\tURL: %s\n", $feed->[1], join(", ", @
{$feed->[2]});
237 foreach my $feed (@feeds) {
238 list_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
243 sub install_generic
() {
246 my $path = $pkg->{makefile
};
249 $path =~ s/\/Makefile$//;
251 -d
"./package/feeds" or mkdir "./package/feeds";
252 -d
"./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
253 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
255 warn "Package is not valid\n";
262 my %install_method = (
263 'src-svn' => \
&install_generic
,
264 'src-cpy' => \
&install_generic
,
265 'src-link' => \
&install_generic
,
266 'src-git' => \
&install_generic
,
267 'src-bzr' => \
&install_generic
,
268 'src-hg' => \
&install_generic
,
273 sub lookup_package
($$) {
277 foreach my $feed ($feed, @feeds) {
278 next unless $feed->[1];
279 next unless $feed{$feed->[1]};
280 $feed{$feed->[1]}->{$package} and return $feed;
285 sub install_package
{
290 $feed = lookup_package
($feed, $name);
292 $installed{$name} and return 0;
293 # TODO: check if it's already installed within ./package directory
294 $srcpackage{$name} or -d
"./package/$name" or warn "WARNING: No feed for package '$name' found, maybe it's already part of the standard packages?\n";
298 my $pkg = $feed{$feed->[1]}->{$name} or return 1;
300 $installed{$name} and return 0;
301 # TODO: check if this is an alias package, maybe it's known by another name
302 warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
305 my $src = $pkg->{src
};
306 my $type = $feed->[0];
307 $src or $src = $name;
309 # previously installed packages set the runtime package
310 # newly installed packages set the source package
311 $installed{$src} and return 0;
313 # check previously installed packages
314 $installed{$name} and return 0;
315 $installed{$src} = 1;
316 warn "Installing package '$src'\n";
318 $install_method{$type} or do {
319 warn "Unknown installation method: '$type'\n";
323 &{$install_method{$type}}($feed, $pkg) == 0 or do {
328 # install all dependencies
329 foreach my $vpkg (@
{$srcpackage{$src}}, $pkg) {
330 foreach my $dep (@
{$vpkg->{depends
}}, @
{$vpkg->{builddepends
}}) {
335 install_package
($feed, $dep) == 0 or $ret = 1;
345 # workaround for timestamp check
346 system("rm -f tmp/.packageinfo");
350 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
352 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
362 getopts
('ap:d:h', \
%opts);
371 foreach my $f (@feeds) {
373 $feed{$f->[1]} = get_feed
($f->[1]);
375 # look up the preferred feed
376 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
380 foreach my $f (@feeds) {
381 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
382 printf "Installing all packages from feed %s.\n", $f->[1];
384 foreach my $name (sort { lc($a) cmp lc($b) } keys %package) {
385 my $p = $package{$name};
387 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
393 while ($name = shift @ARGV) {
394 install_package
($feed, $name) == 0 or $ret = 1;
398 # workaround for timestamp check
401 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
402 refresh_config
($opts{d
});
413 getopts
('ah', \
%opts);
421 system("rm -rvf ./package/feeds");
425 warn "WARNING: no package to uninstall\n";
429 while ($name = shift @ARGV) {
430 my $pkg = $installed{$name};
432 warn "WARNING: $name not installed\n";
435 $pkg->{src
} and $name = $pkg->{src
};
436 warn "Uninstalling package '$name'\n";
437 system("rm -f ./package/feeds/*/$name");
441 $uninstall and refresh_config
();
445 sub update_feed
($$$$)
450 my $perform_update=shift;
451 my $force_relocate=update_location
( $name, "@$src" );
453 if( $force_relocate ) {
454 warn "Source of feed $name has changed, replacing copy\n";
456 $update_method{$type} or do {
457 warn "Unknown type '$type' in feed $name\n";
460 $perform_update and do {
462 foreach my $feedsrc (@
$src) {
463 warn "Updating feed '$name' from '$feedsrc' ...\n";
464 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
473 warn "Create index file './feeds/$name.index' \n";
474 update_index
($name) == 0 or do {
484 my $perform_update=1;
486 $ENV{SCAN_COOKIE
} = $$;
487 $ENV{KBUILD_VERBOSE
} = 99;
489 getopts
('ahi', \
%opts);
497 # don't update from (remote) repository
498 # only re-create index information
503 mkdir "feeds" or die "Unable to create the feeds directory";
506 if ( ($#ARGV == -1) or $opts{a
}) {
507 foreach my $feed (@feeds) {
508 my ($type, $name, $src) = @
$feed;
509 update_feed
($type, $name, $src, $perform_update);
512 while ($feed_name = shift @ARGV) {
513 foreach my $feed (@feeds) {
514 my ($type, $name, $src) = @
$feed;
515 if($feed_name ne $name) {
518 update_feed
($type, $name, $src, $perform_update);
530 Usage: $0 <command> [options]
533 list [options]: List feeds and their content
535 -s : List of feed names and their URL.
536 -r <feedname>: List packages of specified feed.
538 install [options] <package>: Install a package
540 -a : Install all packages from all feeds or from the specified feed using the -p option.
541 -p <feedname>: Prefer this feed when installing packages.
542 -d <y|m|n>: Set default for newly installed packages.
544 search [options] <substring>: Search for a package
546 -r <feedname>: Only search in this feed
548 uninstall -a|<package>: Uninstall a package
550 -a : Uninstalls all packages.
552 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
554 -a : Update all feeds listed within feeds.conf. Otherwise the spezified feeds will be updated.
555 -i : Recreate the index only. No feed update from repository is performed.
557 clean: Remove downloaded/generated files.
565 'update' => \
&update
,
566 'install' => \
&install
,
567 'search' => \
&search
,
568 'uninstall' => \
&uninstall
,
570 system("rm -rf feeds");
574 my $arg = shift @ARGV;
577 foreach my $cmd (keys %commands) {
578 $arg eq $cmd and do {
579 exit(&{$commands{$cmd}}());
This page took 0.104097 seconds and 5 git commands to generate.