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' => "bzr checkout --lightweight '%s' '%s'",
122 'update' => "bzr update",
123 'controldir' => ".bzr"},
125 'init' => "hg clone '%s' '%s'",
126 'update' => "hg pull --update",
127 'controldir' => ".hg"},
129 'init' => "darcs get '%s' '%s'",
130 'update' => "darcs pull -a",
131 'controldir' => "_darcs"},
134 # src-git: pull broken
135 # src-cpy: broken if `basename $src` != $name
137 sub update_feed_via
($$$$) {
141 my $relocate = shift;
143 my $m = $update_method{$type};
144 my $localpath = "./feeds/$name";
145 my $safepath = $localpath;
146 $safepath =~ s/'/'\\''/;
147 my ($base, $branch) = split(/;/, $src, 2);
149 if( $relocate || !$m->{'update'} || !-d
"$localpath/$m->{'controldir'}" ) {
150 system("rm -rf '$safepath'");
151 if ($m->{'init_branch'} and $branch) {
152 system(sprintf($m->{'init_branch'}, $branch, $base, $safepath)) == 0 or return 1;
154 system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
157 system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
166 if (!defined($feed_cache{$feed})) {
167 my $file = "./feeds/$feed.index";
171 print "Ignoring feed '$feed' - index missing\n";
174 parse_package_metadata
($file) or return;
175 $feed_cache{$feed} = [ { %package }, { %srcpackage } ];
178 $feed_package = $feed_cache{$feed}->[0];
179 $feed_src = $feed_cache{$feed}->[1];
180 return $feed_cache{$feed}->[0];
183 sub get_installed
() {
184 system("$mk -s prepare-tmpinfo");
186 parse_package_metadata
("./tmp/.packageinfo");
187 %installed = %package;
195 return unless @substr > 0;
197 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
198 my $pkg = $feed_package->{$name};
202 next if $pkg->{vdepends
};
203 foreach my $substr (@substr) {
205 foreach my $key (qw(name title description src)) {
206 $pkg->{$key} and $substr and $pkg->{$key} =~ m/$substr/i and $match = 1;
208 $match or undef $pkgmatch;
212 print "Search results in feed '$feed':\n";
215 printf "\%-25s\t\%s\n", $pkg->{name
}, $pkg->{title
};
224 getopt
('r:', \
%opts);
225 foreach my $feed (@feeds) {
226 search_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
234 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
235 my $pkg = $feed_package->{$name};
236 next if $pkg->{vdepends
};
238 printf "\%-32s\t\%s\n", $pkg->{name
}, $pkg->{title
};
248 getopts
('r:sh', \
%opts);
254 foreach my $feed (@feeds) {
255 printf "\%-32s\tURL: %s\n", $feed->[1], join(", ", @
{$feed->[2]});
259 foreach my $feed (@feeds) {
260 list_feed
($feed->[1], @ARGV) if (!defined($opts{r
}) or $opts{r
} eq $feed->[1]);
265 sub install_generic
() {
268 my $path = $pkg->{makefile
};
271 $path =~ s/\/Makefile$//;
273 -d
"./package/feeds" or mkdir "./package/feeds";
274 -d
"./package/feeds/$feed->[1]" or mkdir "./package/feeds/$feed->[1]";
275 system("ln -sf ../../../$path ./package/feeds/$feed->[1]/");
277 warn "Package is not valid\n";
284 my %install_method = (
285 'src-svn' => \
&install_generic
,
286 'src-cpy' => \
&install_generic
,
287 'src-link' => \
&install_generic
,
288 'src-git' => \
&install_generic
,
289 'src-bzr' => \
&install_generic
,
290 'src-hg' => \
&install_generic
,
291 'src-darcs' => \
&install_generic
,
296 sub lookup_package
($$) {
300 foreach my $feed ($feed, @feeds) {
301 next unless $feed->[1];
302 next unless $feed{$feed->[1]};
303 $feed{$feed->[1]}->{$package} and return $feed;
308 sub install_package
{
313 $feed = lookup_package
($feed, $name);
315 $installed{$name} and return 0;
316 # TODO: check if it's already installed within ./package directory
317 $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";
321 # switch to the metadata for the selected feed
322 get_feed
($feed->[1]);
324 my $pkg = $feed{$feed->[1]}->{$name} or return 1;
326 $installed{$name} and return 0;
327 # TODO: check if this is an alias package, maybe it's known by another name
328 warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
331 my $src = $pkg->{src
};
332 my $type = $feed->[0];
333 $src or $src = $name;
335 # previously installed packages set the runtime package
336 # newly installed packages set the source package
337 $installed{$src} and return 0;
339 # check previously installed packages
340 $installed{$name} and return 0;
341 $installed{$src} = 1;
342 warn "Installing package '$src'\n";
344 $install_method{$type} or do {
345 warn "Unknown installation method: '$type'\n";
349 &{$install_method{$type}}($feed, $pkg) == 0 or do {
354 # install all dependencies referenced from the source package
355 foreach my $vpkg (@
{$feed_src->{$src}}) {
356 foreach my $dep (@
{$vpkg->{depends
}}, @
{$vpkg->{builddepends
}}, @
{$vpkg->{"builddepends/host"}}) {
362 install_package
($feed, $dep) == 0 or $ret = 1;
372 # workaround for timestamp check
373 system("rm -f tmp/.packageinfo");
377 system("$mk oldconfig CONFDEFAULT=\"$default\" Config.in >/dev/null 2>/dev/null");
379 system("$mk defconfig Config.in >/dev/null 2>/dev/null");
389 getopts
('ap:d:h', \
%opts);
398 foreach my $f (@feeds) {
400 $feed{$f->[1]} = get_feed
($f->[1]);
402 # look up the preferred feed
403 $opts{p
} and $f->[1] eq $opts{p
} and $feed = $f;
407 foreach my $f (@feeds) {
408 if (!defined($opts{p
}) or $opts{p
} eq $f->[1]) {
409 printf "Installing all packages from feed %s.\n", $f->[1];
411 foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
412 my $p = $feed_package->{$name};
413 next if $p->{vdepends
};
415 install_package
($feed, $p->{name
}) == 0 or $ret = 1;
422 while ($name = shift @ARGV) {
423 install_package
($feed, $name) == 0 or $ret = 1;
427 # workaround for timestamp check
430 if ($opts{d
} and $opts{d
} =~ /^[ymn]$/) {
431 refresh_config
($opts{d
});
442 getopts
('ah', \
%opts);
450 system("rm -rvf ./package/feeds");
454 warn "WARNING: no package to uninstall\n";
458 while ($name = shift @ARGV) {
459 my $pkg = $installed{$name};
461 warn "WARNING: $name not installed\n";
464 $pkg->{src
} and $name = $pkg->{src
};
465 warn "Uninstalling package '$name'\n";
466 system("rm -f ./package/feeds/*/$name");
470 $uninstall and refresh_config
();
474 sub update_feed
($$$$)
479 my $perform_update=shift;
480 my $force_relocate=update_location
( $name, "@$src" );
482 if( $force_relocate ) {
483 warn "Source of feed $name has changed, replacing copy\n";
485 $update_method{$type} or do {
486 warn "Unknown type '$type' in feed $name\n";
489 $perform_update and do {
491 foreach my $feedsrc (@
$src) {
492 warn "Updating feed '$name' from '$feedsrc' ...\n";
493 next unless update_feed_via
($type, $name, $feedsrc, $force_relocate) == 0;
502 warn "Create index file './feeds/$name.index' \n";
503 update_index
($name) == 0 or do {
513 my $perform_update=1;
515 $ENV{SCAN_COOKIE
} = $$;
516 $ENV{KBUILD_VERBOSE
} = 99;
518 getopts
('ahi', \
%opts);
526 # don't update from (remote) repository
527 # only re-create index information
532 mkdir "feeds" or die "Unable to create the feeds directory";
535 if ( ($#ARGV == -1) or $opts{a
}) {
536 foreach my $feed (@feeds) {
537 my ($type, $name, $src) = @
$feed;
538 update_feed
($type, $name, $src, $perform_update);
541 while ($feed_name = shift @ARGV) {
542 foreach my $feed (@feeds) {
543 my ($type, $name, $src) = @
$feed;
544 if($feed_name ne $name) {
547 update_feed
($type, $name, $src, $perform_update);
559 Usage: $0 <command> [options]
562 list [options]: List feeds and their content
564 -s : List of feed names and their URL.
565 -r <feedname>: List packages of specified feed.
567 install [options] <package>: Install a package
569 -a : Install all packages from all feeds or from the specified feed using the -p option.
570 -p <feedname>: Prefer this feed when installing packages.
571 -d <y|m|n>: Set default for newly installed packages.
573 search [options] <substring>: Search for a package
575 -r <feedname>: Only search in this feed
577 uninstall -a|<package>: Uninstall a package
579 -a : Uninstalls all packages.
581 update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
583 -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
584 -i : Recreate the index only. No feed update from repository is performed.
586 clean: Remove downloaded/generated files.
594 'update' => \
&update
,
595 'install' => \
&install
,
596 'search' => \
&search
,
597 'uninstall' => \
&uninstall
,
599 system("rm -rf feeds");
603 my $arg = shift @ARGV;
606 foreach my $cmd (keys %commands) {
607 $arg eq $cmd and do {
608 exit(&{$commands{$cmd}}());
This page took 0.085081 seconds and 5 git commands to generate.