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 'init_branch' => "git clone --depth 1 --branch '%s' '%s' '%s'",
118 'update' => "git pull",
119 'controldir' => ".git"},
121 'init' => "git svn clone -r HEAD '%s' '%s'",
122 'update' => "git svn rebase",
123 'controldir' => ".git"},
125 'init' => "bzr checkout --lightweight '%s' '%s'",
126 'update' => "bzr update",
127 'controldir' => ".bzr"},
129 'init' => "hg clone '%s' '%s'",
130 'update' => "hg pull --update",
131 'controldir' => ".hg"},
133 'init' => "darcs get '%s' '%s'",
134 'update' => "darcs pull -a",
135 'controldir' => "_darcs"},
138 # src-git: pull broken
139 # src-cpy: broken if `basename $src` != $name
141 sub update_feed_via
($$$$) {
145 my $relocate = shift;
147 my $m = $update_method{$type};
148 my $localpath = "./feeds/$name";
149 my $safepath = $localpath;
150 $safepath =~ s/'/'\\''/;
151 my ($base, $branch) = split(/;/, $src, 2);
153 if( $relocate || !$m->{'update'} || !-d
"$localpath/$m->{'controldir'}" ) {
154 system("rm -rf '$safepath'");
155 if ($m->{'init_branch'} and $branch) {
156 system(sprintf($m->{'init_branch'}, $branch, $base, $safepath)) == 0 or return 1;
158 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
161 system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
170 if (!defined($feed_cache{$feed})) {
171 my $file = "./feeds/$feed.index";
175 print "Ignoring feed '$feed' - index missing\n";
178 parse_package_metadata
($file) or return;
179 $feed_cache{$feed} = [ { %package }, { %srcpackage } ];
182 $feed_package = $feed_cache{$feed}->[0];
183 $feed_src = $feed_cache{$feed}->[1];
184 return $feed_cache{$feed}->[0];
187 sub get_installed
() {
188 system("$mk -s prepare-tmpinfo");
190 parse_package_metadata
("./tmp/.packageinfo");
191 %installed = %package;
199 return unless @substr > 0;
201 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
202 my $pkg = $feed_package->{$name};
206 next if $pkg->{vdepends
};
207 foreach my $substr (@substr) {
209 foreach my $key (qw(name title description src)) {
210 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
212 $match or undef $pkgmatch;
216 print "Search results in feed '$feed':\n";
219 printf "\%-25s\t\%s\n", $pkg->{name
}, $pkg->{title
};
228 getopt
('r:', \
%opts);
229 foreach my $feed (@feeds) {
230 search_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
238 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
239 my $pkg = $feed_package->{$name};
240 next if $pkg->{vdepends
};
242 printf "\%-32s\t\%s\n", $pkg->{name
}, $pkg->{title
};
252 getopts
('r:sh', \
%opts);
258 foreach my $feed (@feeds) {
259 printf "\%-32s\tURL: %s\n", $feed->[1], join(", ", @
{$feed->[2]});
263 foreach my $feed (@feeds) {
264 list_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
269 sub install_generic
() {
272 my $path = $pkg->{makefile
};
275 $path =~ s/\/Makefile$//;
277 -d
"./package/feeds" or mkdir "./package/feeds";
278 -d
"./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
279 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
281 warn "Package is not valid\n";
288 my %install_method = (
289 'src-svn' => \
&install_generic
,
290 'src-cpy' => \
&install_generic
,
291 'src-link' => \
&install_generic
,
292 'src-git' => \
&install_generic
,
293 'src-gitsvn' => \
&install_generic
,
294 'src-bzr' => \
&install_generic
,
295 'src-hg' => \
&install_generic
,
296 'src-darcs' => \
&install_generic
,
301 sub lookup_package
($$) {
305 foreach my $feed ($feed, @feeds) {
306 next unless $feed->[1];
307 next unless $feed{$feed->[1]};
308 $feed{$feed->[1]}->{$package} and return $feed;
313 sub install_package
{
318 $feed = lookup_package
($feed, $name);
320 $installed{$name} and return 0;
321 # TODO: check if it's already installed within ./package directory
322 $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";
326 # switch to the metadata for the selected feed
327 get_feed
($feed->[1]);
329 my $pkg = $feed{$feed->[1]}->{$name} or return 1;
331 $installed{$name} and return 0;
332 # TODO: check if this is an alias package, maybe it's known by another name
333 warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
336 my $src = $pkg->{src
};
337 my $type = $feed->[0];
338 $src or $src = $name;
340 # previously installed packages set the runtime package
341 # newly installed packages set the source package
342 $installed{$src} and return 0;
344 # check previously installed packages
345 $installed{$name} and return 0;
346 $installed{$src} = 1;
347 warn "Installing package '$src'\n";
349 $install_method{$type} or do {
350 warn "Unknown installation method: '$type'\n";
354 &{$install_method{$type}}($feed, $pkg) == 0 or do {
359 # install all dependencies referenced from the source package
360 foreach my $vpkg (@
{$feed_src->{$src}}) {
361 foreach my $dep (@
{$vpkg->{depends
}}, @
{$vpkg->{builddepends
}}, @
{$vpkg->{"builddepends/host"}}) {
367 install_package
($feed, $dep) == 0 or $ret = 1;
377 # workaround for timestamp check
378 system("rm -f tmp/.packageinfo");
382 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
384 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
394 getopts
('ap:d:h', \
%opts);
403 foreach my $f (@feeds) {
405 $feed{$f->[1]} = get_feed
($f->[1]);
407 # look up the preferred feed
408 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
412 foreach my $f (@feeds) {
413 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
414 printf "Installing all packages from feed %s.\n", $f->[1];
416 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
417 my $p = $feed_package->{$name};
418 next if $p->{vdepends
};
420 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
427 while ($name = shift @ARGV) {
428 install_package
($feed, $name) == 0 or $ret = 1;
432 # workaround for timestamp check
435 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
436 refresh_config
($opts{d
});
447 getopts
('ah', \
%opts);
455 system("rm -rvf ./package/feeds");
459 warn "WARNING: no package to uninstall\n";
463 while ($name = shift @ARGV) {
464 my $pkg = $installed{$name};
466 warn "WARNING: $name not installed\n";
469 $pkg->{src
} and $name = $pkg->{src
};
470 warn "Uninstalling package '$name'\n";
471 system("rm -f ./package/feeds/*/$name");
475 $uninstall and refresh_config
();
479 sub update_feed
($$$$)
484 my $perform_update=shift;
485 my $force_relocate=update_location
( $name, "@$src" );
487 if( $force_relocate ) {
488 warn "Source of feed $name has changed, replacing copy\n";
490 $update_method{$type} or do {
491 warn "Unknown type '$type' in feed $name\n";
494 $perform_update and do {
496 foreach my $feedsrc (@
$src) {
497 warn "Updating feed '$name' from '$feedsrc' ...\n";
498 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
507 warn "Create index file './feeds/$name.index' \n";
508 update_index
($name) == 0 or do {
518 my $perform_update=1;
520 $ENV{SCAN_COOKIE
} = $$;
521 $ENV{KBUILD_VERBOSE
} = 99;
523 getopts
('ahi', \
%opts);
531 # don't update from (remote) repository
532 # only re-create index information
537 mkdir "feeds" or die "Unable to create the feeds directory";
540 if ( ($#ARGV == -1) or $opts{a
}) {
541 foreach my $feed (@feeds) {
542 my ($type, $name, $src) = @
$feed;
543 update_feed
($type, $name, $src, $perform_update);
546 while ($feed_name = shift @ARGV) {
547 foreach my $feed (@feeds) {
548 my ($type, $name, $src) = @
$feed;
549 if($feed_name ne $name) {
552 update_feed
($type, $name, $src, $perform_update);
564 Usage: $0 <command> [options]
567 list [options]: List feeds and their content
569 -s : List of feed names and their URL.
570 -r <feedname>: List packages of specified feed.
572 install [options] <package>: Install a package
574 -a : Install all packages from all feeds or from the specified feed using the -p option.
575 -p <feedname>: Prefer this feed when installing packages.
576 -d <y|m|n>: Set default for newly installed packages.
578 search [options] <substring>: Search for a package
580 -r <feedname>: Only search in this feed
582 uninstall -a|<package>: Uninstall a package
584 -a : Uninstalls all packages.
586 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
588 -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
589 -i : Recreate the index only. No feed update from repository is performed.
591 clean: Remove downloaded/generated files.
599 'update' => \
&update
,
600 'install' => \
&install
,
601 'search' => \
&search
,
602 'uninstall' => \
&uninstall
,
604 system("rm -rf feeds");
608 my $arg = shift @ARGV;
611 foreach my $cmd (keys %commands) {
612 $arg eq $cmd and do {
613 exit(&{$commands{$cmd}}());
This page took 0.145597 seconds and 5 git commands to generate.