Welcome to mirror list, hosted at ThFree Co, Russian Federation.

patch-index.pl « bin - github.com/openwrt/buildscripts.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 317698dd70dc4589490e031b1f7236fca6b5ea4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

my $index;
my @add;
my @remove;

GetOptions(
	"index=s"  => \$index,
	"add=s"    => \@add,
	"remove=s" => \@remove
);


unless (defined($index) && -f $index && (@add || @remove))
{
	die "Usage: $0 --index <pkg index> --add <pkg> --remove <pkg>\n";
}

sub pkg_basename
{
	my $file = shift || return;

	return undef unless -f $file;

	my ($name) = $file =~ m!^(?:.+/)?([^_/]+)[^/]+\.ipk$!;

	return $name;
}

sub pkg_metadata
{
	my $file = shift || return;

	return undef unless -f $file;

	my $size = -s $file;
	my $md5sum;
	my $sha256sum;

	if (open MD5, "md5sum $file |")
	{
		if (defined(my $line = readline MD5))
		{
			($md5sum) = $line =~ /^([0-9a-fA-F]{32})/;
		}

		close MD5;
	}

	if (open SHA256, "openssl dgst -sha256 $file |")
	{
		if (defined(my $line = readline SHA256))
		{
			($sha256sum) = $line =~ /([0-9a-fA-f]{64})$/;
		}

		close SHA256;
	}

	return undef unless $md5sum && $sha256sum;

	my $meta = '';
	my ($name) = $file =~ m!([^/]+)$!;

	if (open TAR, "tar -xzOf $file ./control.tar.gz | tar -xzOf - ./control |")
	{
		while (defined(my $line = readline TAR))
		{
			if ($line =~ /^Description:/)
			{
				$meta .= sprintf "Filename: %s\n", $name;
				$meta .= sprintf "Size: %d\n", $size;
				$meta .= sprintf "MD5Sum: %s\n", $md5sum;
				$meta .= sprintf "SHA256sum: %s\n", $sha256sum;
			}

			$meta .= $line;
		}

		$meta .= "\n";

		close TAR;
	}

	# Fix up source
	$meta =~ s!^Source: .+/(feeds/.+)$!Source: $1!m;

	return $meta;
}


my %addpkg;
my %rempkg;

foreach my $pkg (@add)
{
	my $name = pkg_basename($pkg);
	my $meta = pkg_metadata($pkg);

	if (!defined $name || !defined $meta)
	{
		warn "$pkg is not a valid .ipk file\n";
		next;
	}

	$addpkg{$name} = $meta;
	$rempkg{$name} = 1;
}

my ($cur_pkg, $cur_meta);
my $cat = ($index =~ /\.gz$/) ? "zcat" : "cat";

@rempkg{@remove} = (1) x @remove;

if (open IDX, "$cat $index |")
{
	while (1)
	{
		my $line = readline IDX;

		if (defined($line) && $line =~ /^Package: (.+)$/)
		{
			$cur_pkg = $1;
			$cur_meta = $line;
		}
		elsif (defined($line) && $line !~ /^$/ && defined($cur_meta))
		{
			$cur_meta .= $line;
		}
		else
		{
			foreach my $add (sort keys %addpkg)
			{
				if (!defined($cur_pkg) || $add le $cur_pkg)
				{
					print $addpkg{$add};
					delete $addpkg{$add};

					#$cur_pkg = $add;					
				}
			}
			
			if (defined($cur_pkg) && !$rempkg{$cur_pkg})
			{
				print $cur_meta, "\n";
			}

			undef $cur_pkg;
			undef $cur_meta;
		}

		last unless defined $line;
	}

	close IDX;
}