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"}
129 # src-git: pull broken
130 # src-cpy: broken if `basename $src` != $name
132 sub update_feed_via
($$$$) {
136 my $relocate = shift;
138 my $m = $update_method{$type};
139 my $localpath = "./feeds/$name";
140 my $safepath = $localpath;
141 $safepath =~ s/'/'\\''/;
143 if( $relocate || !$m->{'update'} || !-d
"$localpath/$m->{'controldir'}" ) {
144 system("rm -rf '$safepath'");
145 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
147 system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
156 if (!defined($feed_cache{$feed})) {
157 my $file = "./feeds/$feed.index";
161 print "Ignoring feed '$feed' - index missing\n";
164 parse_package_metadata
($file) or return;
165 $feed_cache{$feed} = [ { %package }, { %srcpackage } ];
168 $feed_package = $feed_cache{$feed}->[0];
169 $feed_src = $feed_cache{$feed}->[1];
170 return $feed_cache{$feed}->[0];
173 sub get_installed
() {
174 system("$mk -s prepare-tmpinfo");
176 parse_package_metadata
("./tmp/.packageinfo");
177 %installed = %package;
185 return unless @substr > 0;
187 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
188 my $pkg = $feed_package->{$name};
192 next if $pkg->{vdepends
};
193 foreach my $substr (@substr) {
195 foreach my $key (qw(name title description src)) {
196 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
198 $match or undef $pkgmatch;
202 print "Search results in feed '$feed':\n";
205 printf "\%-25s\t\%s\n", $pkg->{name
}, $pkg->{title
};
214 getopt
('r:', \
%opts);
215 foreach my $feed (@feeds) {
216 search_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
224 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
225 my $pkg = $feed_package->{$name};
226 next if $pkg->{vdepends
};
228 printf "\%-32s\t\%s\n", $pkg->{name
}, $pkg->{title
};
238 getopts
('r:sh', \
%opts);
244 foreach my $feed (@feeds) {
245 printf "\%-32s\tURL: %s\n", $feed->[1], join(", ", @
{$feed->[2]});
249 foreach my $feed (@feeds) {
250 list_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
255 sub install_generic
() {
258 my $path = $pkg->{makefile
};
261 $path =~ s/\/Makefile$//;
263 -d
"./package/feeds" or mkdir "./package/feeds";
264 -d
"./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
265 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
267 warn "Package is not valid\n";
274 my %install_method = (
275 'src-svn' => \
&install_generic
,
276 'src-cpy' => \
&install_generic
,
277 'src-link' => \
&install_generic
,
278 'src-git' => \
&install_generic
,
279 'src-bzr' => \
&install_generic
,
280 'src-hg' => \
&install_generic
,
285 sub lookup_package
($$) {
289 foreach my $feed ($feed, @feeds) {
290 next unless $feed->[1];
291 next unless $feed{$feed->[1]};
292 $feed{$feed->[1]}->{$package} and return $feed;
297 sub install_package
{
302 $feed = lookup_package
($feed, $name);
304 $installed{$name} and return 0;
305 # TODO: check if it's already installed within ./package directory
306 $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";
310 # switch to the metadata for the selected feed
311 get_feed
($feed->[1]);
313 my $pkg = $feed{$feed->[1]}->{$name} or return 1;
315 $installed{$name} and return 0;
316 # TODO: check if this is an alias package, maybe it's known by another name
317 warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
320 my $src = $pkg->{src
};
321 my $type = $feed->[0];
322 $src or $src = $name;
324 # previously installed packages set the runtime package
325 # newly installed packages set the source package
326 $installed{$src} and return 0;
328 # check previously installed packages
329 $installed{$name} and return 0;
330 $installed{$src} = 1;
331 warn "Installing package '$src'\n";
333 $install_method{$type} or do {
334 warn "Unknown installation method: '$type'\n";
338 &{$install_method{$type}}($feed, $pkg) == 0 or do {
343 # install all dependencies referenced from the source package
344 foreach my $vpkg (@
{$feed_src->{$src}}) {
345 foreach my $dep (@
{$vpkg->{depends
}}, @
{$vpkg->{builddepends
}}, @
{$vpkg->{"builddepends/host"}}) {
351 install_package
($feed, $dep) == 0 or $ret = 1;
361 # workaround for timestamp check
362 system("rm -f tmp/.packageinfo");
366 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
368 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
378 getopts
('ap:d:h', \
%opts);
387 foreach my $f (@feeds) {
389 $feed{$f->[1]} = get_feed
($f->[1]);
391 # look up the preferred feed
392 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
396 foreach my $f (@feeds) {
397 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
398 printf "Installing all packages from feed %s.\n", $f->[1];
400 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
401 my $p = $feed_package->{$name};
402 next if $p->{vdepends
};
404 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
410 while ($name = shift @ARGV) {
411 install_package
($feed, $name) == 0 or $ret = 1;
415 # workaround for timestamp check
418 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
419 refresh_config
($opts{d
});
430 getopts
('ah', \
%opts);
438 system("rm -rvf ./package/feeds");
442 warn "WARNING: no package to uninstall\n";
446 while ($name = shift @ARGV) {
447 my $pkg = $installed{$name};
449 warn "WARNING: $name not installed\n";
452 $pkg->{src
} and $name = $pkg->{src
};
453 warn "Uninstalling package '$name'\n";
454 system("rm -f ./package/feeds/*/$name");
458 $uninstall and refresh_config
();
462 sub update_feed
($$$$)
467 my $perform_update=shift;
468 my $force_relocate=update_location
( $name, "@$src" );
470 if( $force_relocate ) {
471 warn "Source of feed $name has changed, replacing copy\n";
473 $update_method{$type} or do {
474 warn "Unknown type '$type' in feed $name\n";
477 $perform_update and do {
479 foreach my $feedsrc (@
$src) {
480 warn "Updating feed '$name' from '$feedsrc' ...\n";
481 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
490 warn "Create index file './feeds/$name.index' \n";
491 update_index
($name) == 0 or do {
501 my $perform_update=1;
503 $ENV{SCAN_COOKIE
} = $$;
504 $ENV{KBUILD_VERBOSE
} = 99;
506 getopts
('ahi', \
%opts);
514 # don't update from (remote) repository
515 # only re-create index information
520 mkdir "feeds" or die "Unable to create the feeds directory";
523 if ( ($#ARGV == -1) or $opts{a
}) {
524 foreach my $feed (@feeds) {
525 my ($type, $name, $src) = @
$feed;
526 update_feed
($type, $name, $src, $perform_update);
529 while ($feed_name = shift @ARGV) {
530 foreach my $feed (@feeds) {
531 my ($type, $name, $src) = @
$feed;
532 if($feed_name ne $name) {
535 update_feed
($type, $name, $src, $perform_update);
547 Usage: $0 <command> [options]
550 list [options]: List feeds and their content
552 -s : List of feed names and their URL.
553 -r <feedname>: List packages of specified feed.
555 install [options] <package>: Install a package
557 -a : Install all packages from all feeds or from the specified feed using the -p option.
558 -p <feedname>: Prefer this feed when installing packages.
559 -d <y|m|n>: Set default for newly installed packages.
561 search [options] <substring>: Search for a package
563 -r <feedname>: Only search in this feed
565 uninstall -a|<package>: Uninstall a package
567 -a : Uninstalls all packages.
569 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
571 -a : Update all feeds listed within feeds.conf. Otherwise the spezified feeds will be updated.
572 -i : Recreate the index only. No feed update from repository is performed.
574 clean: Remove downloaded/generated files.
582 'update' => \
&update
,
583 'install' => \
&install
,
584 'search' => \
&search
,
585 'uninstall' => \
&uninstall
,
587 system("rm -rf feeds");
591 my $arg = shift @ARGV;
594 foreach my $cmd (keys %commands) {
595 $arg eq $cmd and do {
596 exit(&{$commands{$cmd}}());
This page took 0.095777 seconds and 5 git commands to generate.