update denpendencies version
[tools/build.git] / createarchdeps
1 #!/usr/bin/perl -w
2
3 # Archlinux support, based on the GSoC work of Nikolay Rysev <mad.f3ka@gmail.com>
4
5 ################################################################
6 #
7 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2 or 3 as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program (see the file COPYING); if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #
23 ################################################################
24
25 BEGIN {
26   unshift @INC, ($::ENV{"BUILD_DIR"} || "/usr/lib/build");
27 }
28
29 use strict;
30 use Build ':arch';
31 use Build::Archrepo;
32 use Digest::MD5 ();
33 use File::Path;
34 use Getopt::Long;
35
36 Getopt::Long::Configure("no_ignore_case");
37
38 my $cachedir = "/var/cache/build";
39
40 sub getreponame {
41   my ($url) = @_;
42   return $1 if "/$url/" =~ /.*\/([^\/]+)\/os\//;
43   return undef;
44 }
45
46 GetOptions("cachedir=s"  => \$cachedir) or exit(1);
47
48 for my $url (@ARGV) {
49   die("$url: not an remote Archlinux repo") unless $url =~ /^(:?ftps?|https?):\/\/([^\/]*)\/?/;
50   my $reponame = getreponame($url);
51   die("could not determine reponame from url $url\n") unless defined $reponame;
52   my $repoid = Digest::MD5::md5_hex($url);
53   my $dir = "$cachedir/$repoid";
54   $url .= '/' unless $url =~ /\/$/;
55   File::Path::mkpath($dir);
56   system("$INC[0]/download", $dir, "$url$reponame.db");
57   Build::Archrepo::parse("$dir/$reponame.db", sub { Build::writedeps(\*STDOUT, $_[0], $url) }, 'addselfprovides' => 1);
58 }