This file is indexed.

/usr/bin/debsnap is in devscripts 2.11.6ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/usr/bin/perl

# Copyright © 2010, David Paleino <d.paleino@gmail.com>,
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;

use Getopt::Long qw(:config gnu_getopt);
use File::Basename;
use Cwd qw/cwd abs_path/;
use File::Path qw/make_path/;
use Dpkg::Version;

my $progname = basename($0);

eval {
    require LWP::Simple;
    require LWP::UserAgent;
    no warnings;
    $LWP::Simple::ua = LWP::UserAgent->new(agent => 'LWP::UserAgent/Devscripts/2.11.6ubuntu1');
};
if ($@) {
    if ($@ =~ m/Can\'t locate LWP/) {
	die "$progname: Unable to run: the libwww-perl package is not installed";
    } else {
	die "$progname: Unable to run: Couldn't load LWP::Simple: $@";
    }
}

eval {
    require JSON;
};
if ($@) {
    if ($@ =~ m/Can\'t locate JSON/) {
	die "$progname: Unable to run: the libjson-perl package is not installed";
    } else {
	die "$progname: Unable to run: Couldn't load JSON: $@";
    }
}

my $modified_conf_msg = '';
my %config_vars = ();

my %opt;
my $package = '';
my $pkgversion = '';
my $warnings = 0;

sub fatal($);
sub verbose($);

sub version
{
    print <<"EOF";
This is $progname, from the Debian devscripts package, version 2.11.6ubuntu1
This code is copyright 2010 by David Paleino <dapal\@debian.org>.
This program comes with ABSOLUTELY NO WARRANTY.
You are free to redistribute this code under the terms of the GNU
General Public License v3 or, at your option, any later version.
EOF
    exit 0;
}

sub usage
{
    my $rc = shift;
    print <<"EOF";
$progname [options] <package name> [package version]

Automatically downloads packages from snapshot.debian.org

The following options are supported:
    -h, --help                          Shows this help message
    --version                           Shows information about version
    -v, --verbose                       Be verbose
    -d <destination directory>,
    --destdir=<destination directory>   Directory for retrieved packages
                                        Default is ./source-<package name>
    -f, --force                         Force overwriting an existing
                                        destdir
    --binary                            Download binary packages instead of
                                        source packages
    -a <architecture>,
    --architecture <architecture>       Specify architecture of binary packages,
                                        implies --binary. May be given multiple
                                        times

Default settings modified by devscripts configuration files or command-line
options:
$modified_conf_msg
EOF
    exit $rc;
}

sub fetch_json_page
{
    my ($json_url) = @_;

    # download the json page:
    verbose "Getting json $json_url\n";
    my $content = LWP::Simple::get($json_url);
    return unless defined $content;
    my $json = JSON->new();

    # these are some nice json options to relax restrictions a bit:
    my $json_text = $json->allow_nonref->utf8->relaxed->decode($content);

    return $json_text;
}

sub read_conf
{
    my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
    %config_vars = (
	'DEBSNAP_VERBOSE' => 'no',
	'DEBSNAP_DESTDIR' => '',
	'DEBSNAP_BASE_URL' => 'http://snapshot.debian.org',
    );

    my %config_default = %config_vars;

    my $shell_cmd;
    # Set defaults
    $shell_cmd .= qq[unset `set | grep "^DEBSNAP_" | cut -d= -f1`;\n];
    foreach my $var (keys %config_vars) {
	$shell_cmd .= qq[$var="$config_vars{$var}";\n];
    }
    $shell_cmd .= 'for file in ' . join(" ",@config_files) . "; do\n";
    $shell_cmd .= '[ -f $file ] && . $file; done;' . "\n";
    # Read back values
    foreach my $var (keys %config_vars) { $shell_cmd .= "echo \$$var;\n" }
    my $shell_out = `/bin/bash -c '$shell_cmd'`;
    @config_vars{keys %config_vars} = split /\n/, $shell_out, -1;

    # Check validity
    $config_vars{'DEBSNAP_VERBOSE'} =~ /^(yes|no)$/
	or $config_vars{'DEBSNAP_VERBOSE'} = 'no';

    foreach my $var (sort keys %config_vars) {
	if ($config_vars{$var} ne $config_default{$var}) {
	    $modified_conf_msg .= "  $var=$config_vars{$var}\n";
	}
    }

    $modified_conf_msg ||= "  (none)\n";
    chomp $modified_conf_msg;

    $opt{verbose} = $config_vars{DEBSNAP_VERBOSE} eq 'yes';
    $opt{destdir} = $config_vars{DEBSNAP_DESTDIR};
    $opt{baseurl} = $config_vars{DEBSNAP_BASE_URL};
}

sub have_file($$)
{
    my ($path, $hash) = @_;

    if (-e $path) {
	open(HASH, '-|', 'sha1sum', $path) || fatal "Can't run sha1sum: $!";
	while (<HASH>) {
	    if (m/^([a-fA-F\d]{40}) /) {
		close(HASH) || fatal "sha1sum problems: $! $?";
		return $1 eq $hash;
	    }
	}
    }
    return 0;
}

sub fatal($)
{
    my ($pack, $file, $line);
    ($pack, $file, $line) = caller();
    (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d;
    $msg =~ s/\n\n$/\n/;
    $! = 1;
    die $msg;
}

sub verbose($)
{
    (my $msg = "@_\n") =~ tr/\0//d;
    $msg =~ s/\n\n$/\n/;
    print "$msg" if $opt{verbose};
}

###
# Main program
###
read_conf(@ARGV);
Getopt::Long::Configure('gnu_compat');
Getopt::Long::Configure('no_ignore_case');
GetOptions(\%opt, 'verbose|v', 'destdir|d=s', 'force|f', 'help|h', 'version', 'binary', 'architecture|a=s@') || exit 1;

usage(0) if $opt{help};
usage(1) unless @ARGV;
$package = shift;
if (@ARGV) {
    my $version = shift;
    $pkgversion = Dpkg::Version->new($version, check => 1);
    fatal "Invalid version '$version'" unless $pkgversion;
}

$package eq '' && usage(1);

$opt{binary} ||= $opt{architecture};

my $baseurl;
if ($opt{binary}) {
    $opt{destdir} ||= "binary-$package";
    $baseurl = "$opt{baseurl}/mr/binary/$package/";
} else {
    $opt{destdir} ||= "source-$package";
    $baseurl = "$opt{baseurl}/mr/package/$package/";
}

if (-d $opt{destdir}) {
    unless ($opt{force} || cwd() eq abs_path($opt{destdir})) {
	fatal "Destination dir $opt{destdir} already exists.\nPlease (re)move it first, or use --force to overwrite.";
    }
}
make_path($opt{destdir});

my $json_text = fetch_json_page($baseurl);
unless ($json_text && @{$json_text->{result}}) {
    fatal "Unable to retrieve information for $package from $baseurl.";
}

if ($opt{binary}) {
    foreach my $version (@{$json_text->{result}}) {
	if ($pkgversion) {
	    next if ($version->{binary_version} <=> $pkgversion);
	}

	my $src_json = fetch_json_page("$opt{baseurl}/mr/package/$version->{source}/$version->{version}/binfiles/$version->{name}/$version->{binary_version}?fileinfo=1");

	unless ($src_json) {
	    warn "$progname: No binary packages found for $package version $version->{binary_version}\n";
	    $warnings++;
	}

	foreach my $result (@{$src_json->{result}}) {
	    if ($opt{architecture} && @{$opt{architecture}}) {
		next unless (grep { $_ eq $result->{architecture} } @{$opt{architecture}});
	    }
	    my $hash = $result->{hash};
	    my $fileinfo = @{$src_json->{fileinfo}{$hash}}[0];
	    my $file_url = "$opt{baseurl}/file/$hash";
	    my $file_name = basename($fileinfo->{name});
	    if (!have_file("$opt{destdir}/$file_name", $hash)) {
		verbose "Getting file $file_name: $file_url";
		LWP::Simple::getstore($file_url, "$opt{destdir}/$file_name");
	    }
	}
    }
}
else {
    foreach my $version (@{$json_text->{result}}) {
	if ($pkgversion) {
	    next if ($version->{version} <=> $pkgversion);
	}

	my $src_json = fetch_json_page("$baseurl/$version->{version}/srcfiles?fileinfo=1");
	unless ($src_json) {
	    warn "$progname: No source files found for $package version $version->{version}\n";
	    $warnings++;
	}

	foreach my $hash (keys %{$src_json->{fileinfo}}) {
	    my $fileinfo = $src_json->{fileinfo}{$hash};
	    my $file_name;
	    # fileinfo may match multiple files (e.g., orig tarball for iceweasel 3.0.12)
	    foreach my $info (@$fileinfo) {
		if ($info->{name} =~ m/^${package}/) {
		    $file_name = $info->{name};
		    last;
		}
	    }
	    unless ($file_name) {
		warn "$progname: No files with hash $hash matched '${package}'\n";
		$warnings++;
		next;
	    }
	    my $file_url = "$opt{baseurl}/file/$hash";
	    $file_name = basename($file_name);
	    if (!have_file("$opt{destdir}/$file_name", $hash)) {
		verbose "Getting file $file_name: $file_url";
		LWP::Simple::getstore($file_url, "$opt{destdir}/$file_name");
	    }
	}
    }
}

if ($warnings) {
    exit 2;
}
exit 0;