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
}}, @
{$vpkg->{"builddepends/host"}}) {
336 install_package
($feed, $dep) == 0 or $ret = 1;
346 # workaround for timestamp check
347 system("rm -f tmp/.packageinfo");
351 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
353 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
363 getopts
('ap:d:h', \
%opts);
372 foreach my $f (@feeds) {
374 $feed{$f->[1]} = get_feed
($f->[1]);
376 # look up the preferred feed
377 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
381 foreach my $f (@feeds) {
382 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
383 printf "Installing all packages from feed %s.\n", $f->[1];
385 foreach my $name (sort { lc($a) cmp lc($b) } keys %package) {
386 my $p = $package{$name};
388 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
394 while ($name = shift @ARGV) {
395 install_package
($feed, $name) == 0 or $ret = 1;
399 # workaround for timestamp check
402 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
403 refresh_config
($opts{d
});
414 getopts
('ah', \
%opts);
422 system("rm -rvf ./package/feeds");
426 warn "WARNING: no package to uninstall\n";
430 while ($name = shift @ARGV) {
431 my $pkg = $installed{$name};
433 warn "WARNING: $name not installed\n";
436 $pkg->{src
} and $name = $pkg->{src
};
437 warn "Uninstalling package '$name'\n";
438 system("rm -f ./package/feeds/*/$name");
442 $uninstall and refresh_config
();
446 sub update_feed
($$$$)
451 my $perform_update=shift;
452 my $force_relocate=update_location
( $name, "@$src" );
454 if( $force_relocate ) {
455 warn "Source of feed $name has changed, replacing copy\n";
457 $update_method{$type} or do {
458 warn "Unknown type '$type' in feed $name\n";
461 $perform_update and do {
463 foreach my $feedsrc (@
$src) {
464 warn "Updating feed '$name' from '$feedsrc' ...\n";
465 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
474 warn "Create index file './feeds/$name.index' \n";
475 update_index
($name) == 0 or do {
485 my $perform_update=1;
487 $ENV{SCAN_COOKIE
} = $$;
488 $ENV{KBUILD_VERBOSE
} = 99;
490 getopts
('ahi', \
%opts);
498 # don't update from (remote) repository
499 # only re-create index information
504 mkdir "feeds" or die "Unable to create the feeds directory";
507 if ( ($#ARGV == -1) or $opts{a
}) {
508 foreach my $feed (@feeds) {
509 my ($type, $name, $src) = @
$feed;
510 update_feed
($type, $name, $src, $perform_update);
513 while ($feed_name = shift @ARGV) {
514 foreach my $feed (@feeds) {
515 my ($type, $name, $src) = @
$feed;
516 if($feed_name ne $name) {
519 update_feed
($type, $name, $src, $perform_update);
531 Usage: $0 <command> [options]
534 list [options]: List feeds and their content
536 -s : List of feed names and their URL.
537 -r <feedname>: List packages of specified feed.
539 install [options] <package>: Install a package
541 -a : Install all packages from all feeds or from the specified feed using the -p option.
542 -p <feedname>: Prefer this feed when installing packages.
543 -d <y|m|n>: Set default for newly installed packages.
545 search [options] <substring>: Search for a package
547 -r <feedname>: Only search in this feed
549 uninstall -a|<package>: Uninstall a package
551 -a : Uninstalls all packages.
553 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
555 -a : Update all feeds listed within feeds.conf. Otherwise the spezified feeds will be updated.
556 -i : Recreate the index only. No feed update from repository is performed.
558 clean: Remove downloaded/generated files.
566 'update' => \
&update
,
567 'install' => \
&install
,
568 'search' => \
&search
,
569 'uninstall' => \
&uninstall
,
571 system("rm -rf feeds");
575 my $arg = shift @ARGV;
578 foreach my $cmd (keys %commands) {
579 $arg eq $cmd and do {
580 exit(&{$commands{$cmd}}());
This page took 0.104949 seconds and 5 git commands to generate.