This file is indexed.

/usr/bin/debconf-apt-progress is in debconf 1.5.58ubuntu1.

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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#!/usr/bin/perl -w
# This file was preprocessed, do not edit!


use strict;
use POSIX;
use Fcntl;
use Getopt::Long;
use Debconf::Client::ConfModule ();

my ($config, $start, $from, $to, $stop);
my $progress=1;
my $dlwaypoint=15;
my ($logfile, $logstderr);
my $had_frontend;

sub checkopen (@) {
	my $file = $_[0];
	my $fd = POSIX::open($file, &POSIX::O_RDONLY);
	defined $fd or die "$0: can't open $_[0]: $!\n";
	return $fd;
}

sub checkclose ($) {
	my $fd = $_[0];
	unless (POSIX::close($fd)) {
		return if $! == &POSIX::EBADF;
		die "$0: can't close fd $fd: $!\n";
	}
}

sub checkdup2 ($$) {
	my ($oldfd, $newfd) = @_;
	checkclose($newfd);
	POSIX::dup2($oldfd, $newfd)
		or die "$0: can't dup fd $oldfd to $newfd: $!\n";
}

sub nocloexec (*) {
	my $fh = shift;
	my $flags = fcntl($fh, F_GETFD, 0);
	fcntl($fh, F_SETFD, $flags & ~FD_CLOEXEC);
}

sub nonblock (*) {
	my $fh = shift;
	my $flags = fcntl($fh, F_GETFL, 0);
	fcntl($fh, F_SETFL, $flags | O_NONBLOCK);
}

sub reservefds (@) {
	my $null = checkopen('/dev/null');
	my $close = 1;
	for my $fd (@_) {
		if ($null == $fd) {
			$close = 0;
		} else {
			checkclose($fd);
			checkdup2($null, $fd);
		}
	}
	if ($close) {
		checkclose($null);
	}
}

sub envnonempty ($) {
	my $name = shift;
	return (exists $ENV{$name} and $ENV{$name} ne '');
}

sub start_debconf (@) {
	if (! $ENV{DEBIAN_HAS_FRONTEND}) {
		if (envnonempty('DEBCONF_DB_REPLACE')) {
			$ENV{DEBCONF_APT_PROGRESS_DB_REPLACE} =
				$ENV{DEBCONF_DB_REPLACE};
		}
		if (envnonempty('DEBCONF_DB_OVERRIDE')) {
			$ENV{DEBCONF_APT_PROGRESS_DB_OVERRIDE} =
				$ENV{DEBCONF_DB_OVERRIDE};
		}

		$ENV{DEBCONF_DB_REPLACE} = 'configdb';
		$ENV{DEBCONF_DB_OVERRIDE} = 'Pipe{infd:none outfd:none}';

		$ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND} = 1;

		@ARGV = @_;
	}

	import Debconf::Client::ConfModule;
}

sub passthrough (@) {
	my $priority = Debconf::Client::ConfModule::get('debconf/priority');

	defined(my $pid = fork) or die "$0: can't fork: $!\n";
	if (!$pid) {
		close STATUS_READ;
		close COMMAND_WRITE;
		close DEBCONF_COMMAND_READ;
		close DEBCONF_REPLY_WRITE;
		$^F = 6; # avoid close-on-exec
		if (fileno(COMMAND_READ) != 0) {
			checkdup2(fileno(COMMAND_READ), 0);
			close COMMAND_READ;
		}
		if (fileno(APT_LOG) != 1) {
			checkclose(1);
			checkdup2(fileno(APT_LOG), 1);
		}
		if (fileno(APT_LOG) != 2) {
			checkclose(2);
			checkdup2(fileno(APT_LOG), 2);
		}
		close APT_LOG;
		delete $ENV{DEBIAN_HAS_FRONTEND};
		delete $ENV{DEBCONF_REDIR};
		delete $ENV{DEBCONF_SYSTEMRC};
		delete $ENV{DEBCONF_PIPE}; # just in case ...
		$ENV{DEBIAN_FRONTEND} = 'passthrough';
		$ENV{DEBIAN_PRIORITY} = $priority;
		$ENV{DEBCONF_READFD} = 5;
		$ENV{DEBCONF_WRITEFD} = 6;
		$ENV{APT_LISTCHANGES_FRONTEND} = 'none';
		if ($had_frontend) {
			$ENV{DEBCONF_DB_REPLACE} = 'configdb';
			$ENV{DEBCONF_DB_OVERRIDE} = 'Pipe{infd:none outfd:none}';
		}
		exec @_;
	}

	close STATUS_WRITE;
	close COMMAND_READ;
	close DEBCONF_COMMAND_WRITE;
	close DEBCONF_REPLY_READ;
	return $pid;
}

sub handle_status ($$$) {
	my ($from, $to, $line) = @_;
	my ($status, $pkg, $percent, $description) = split ':', $line, 4;

	my ($min, $len);
	if ($status eq 'dlstatus') {
		$min = 0;
		$len = $dlwaypoint;
	}
	elsif ($status eq 'pmstatus') {
		$min = $dlwaypoint;
		$len = 100 - $dlwaypoint;
	}
	elsif ($status eq 'media-change') {
		Debconf::Client::ConfModule::subst(
			'debconf-apt-progress/media-change', 'MESSAGE',
			$description);
		my @ret = Debconf::Client::ConfModule::input(
			'critical', 'debconf-apt-progress/media-change');
		$ret[0] == 0 or die "Can't display media change request!\n";
		Debconf::Client::ConfModule::go();
		print COMMAND_WRITE "\n" || die "can't talk to command fd: $!";
		return;
	}
	else {
		return;
	}

	$percent = ($percent * $len / 100 + $min);
	$percent = ($percent * ($to - $from) / 100 + $from);
	$percent =~ s/\..*//;
	if ($progress) {
		my @ret=Debconf::Client::ConfModule::progress('SET', $percent);
		if ($ret[0] eq '30') {
			cancel();
		}
	}
	Debconf::Client::ConfModule::subst(
		'debconf-apt-progress/info', 'DESCRIPTION', $description);
	my @ret=Debconf::Client::ConfModule::progress(
		'INFO', 'debconf-apt-progress/info');
	if ($ret[0] eq '30') {
		cancel();
	}
}

sub handle_debconf_command ($) {
	my $line = shift;

	print "$line\n" || die "can't write to stdout: $!";
	my $ret = <STDIN>;
	chomp $ret;
	print DEBCONF_REPLY_WRITE "$ret\n" ||
		die "can't write to DEBCONF_REPLY_WRITE: $!";
}

my $pid;
sub run_progress ($$@) {
	my $from = shift;
	my $to = shift;
	my $command = shift;
	local (*STATUS_READ, *STATUS_WRITE);
	local (*COMMAND_READ, *COMMAND_WRITE);
	local (*DEBCONF_COMMAND_READ, *DEBCONF_COMMAND_WRITE);
	local (*DEBCONF_REPLY_READ, *DEBCONF_REPLY_WRITE);
	local *APT_LOG;
	use IO::Handle;

	if ($progress) {
		my @ret=Debconf::Client::ConfModule::progress(
			'INFO', 'debconf-apt-progress/preparing');
		if ($ret[0] eq '30') {
			cancel();
			return 30;
		}
	}

	reservefds(4, 5, 6);

	pipe STATUS_READ, STATUS_WRITE
		or die "$0: can't create status pipe: $!";
	nonblock(\*STATUS_READ);
	checkdup2(fileno(STATUS_WRITE), 4);
	open STATUS_WRITE, '>&=4'
		or die "$0: can't reopen STATUS_WRITE as fd 4: $!";
	nocloexec(\*STATUS_WRITE);

	pipe COMMAND_READ, COMMAND_WRITE
		or die "$0: can't create command pipe: $!";
	nocloexec(\*COMMAND_READ);
	COMMAND_WRITE->autoflush(1);

	pipe DEBCONF_COMMAND_READ, DEBCONF_COMMAND_WRITE
		or die "$0: can't create debconf command pipe: $!";
	nonblock(\*DEBCONF_COMMAND_READ);
	checkdup2(fileno(DEBCONF_COMMAND_WRITE), 6);
	open DEBCONF_COMMAND_WRITE, '>&=6'
		or die "$0: can't reopen DEBCONF_COMMAND_WRITE as fd 6: $!";
	nocloexec(\*DEBCONF_COMMAND_WRITE);

	pipe DEBCONF_REPLY_READ, DEBCONF_REPLY_WRITE
		or die "$0: can't create debconf reply pipe: $!";
	checkdup2(fileno(DEBCONF_REPLY_READ), 5);
	open DEBCONF_REPLY_READ, '<&=5'
		or die "$0: can't reopen DEBCONF_REPLY_READ as fd 5: $!";
	nocloexec(\*DEBCONF_REPLY_READ);
	DEBCONF_REPLY_WRITE->autoflush(1);

	if (defined $logfile) {
		open APT_LOG, '>>', $logfile
			or die "$0: can't open $logfile: $!";
	} elsif ($logstderr) {
		open APT_LOG, '>&STDERR'
			or die "$0: can't duplicate stderr: $!";
	} else {
		open APT_LOG, '>', '/dev/null'
			or die "$0: can't open /dev/null: $!";
	}
	nocloexec(\*APT_LOG);

	$pid = passthrough $command,
		'-o', 'APT::Status-Fd=4',
		'-o', 'APT::Keep-Fds::=5',
		'-o', 'APT::Keep-Fds::=6',
		@_;

	my $status_eof = 0;
	my $debconf_command_eof = 0;
	my $status_buf = '';
	my $debconf_command_buf = '';

	while (not $status_eof) {
		my $rin = '';
		my $rout;
		vec($rin, fileno(STATUS_READ), 1) = 1;
		vec($rin, fileno(DEBCONF_COMMAND_READ), 1) = 1
			unless $debconf_command_eof;
		my $sel = select($rout = $rin, undef, undef, undef);
		if ($sel < 0) {
			next if $! == &POSIX::EINTR;
			die "$0: select failed: $!";
		}

		if (vec($rout, fileno(STATUS_READ), 1) == 1) {
			while (1) {
				my $r = sysread(STATUS_READ, $status_buf, 4096,
						length $status_buf);
				if (not defined $r) {
					next if $! == &POSIX::EINTR;
					last if $! == &POSIX::EAGAIN or
						$! == &POSIX::EWOULDBLOCK;
					die "$0: read STATUS_READ failed: $!";
				}
				elsif ($r == 0) {
					if ($status_buf ne '' and
					    $status_buf !~ /\n$/) {
						$status_buf .= "\n";
					}
					$status_eof = 1;
					last;
				}
				last if $status_buf =~ /\n/;
			}

			while ($status_buf =~ /\n/) {
				my $status_line;
				($status_line, $status_buf) =
					split /\n/, $status_buf, 2;
				handle_status $from, $to, $status_line;
			}
		}

		if (vec($rout, fileno(DEBCONF_COMMAND_READ), 1) == 1) {
			while (1) {
				my $r = sysread(DEBCONF_COMMAND_READ,
						$debconf_command_buf, 4096,
						length $debconf_command_buf);
				if (not defined $r) {
					next if $! == &POSIX::EINTR;
					last if $! == &POSIX::EAGAIN or
						$! == &POSIX::EWOULDBLOCK;
					die "$0: read DEBCONF_COMMAND_READ " .
					    "failed: $!";
				}
				elsif ($r == 0) {
					if ($debconf_command_buf ne '' and
					    $debconf_command_buf !~ /\n$/) {
						$debconf_command_buf .= "\n";
					}
					$debconf_command_eof = 1;
					last;
				}
				last if $debconf_command_buf =~ /\n/;
			}

			while ($debconf_command_buf =~ /\n/) {
				my $debconf_command_line;
				($debconf_command_line, $debconf_command_buf) =
					split /\n/, $debconf_command_buf, 2;
				handle_debconf_command $debconf_command_line;
			}
		}
	}

	waitpid $pid, 0;
	undef $pid;
	my $status = $?;

	if ($progress) {
		my @ret=Debconf::Client::ConfModule::progress('SET', $to);
		if ($ret[0] eq '30') {
			cancel();
		}
	}

	if ($status & 127) {
		return 127;
	}

	return ($status >> 8);
}

my $cancelled=0;
my $cancel_sent_signal=0;
sub cancel () {
	$cancelled++;
	if (defined $pid) {
		$cancel_sent_signal++;
		if ($cancel_sent_signal == 1) {
			kill INT => $pid;
		}
		else {
			kill KILL => $pid;
		}
	}
}

sub start_bar ($$) {
	my ($from, $to) = @_;
	if ($progress) {
		Debconf::Client::ConfModule::progress(
			'START', $from, $to, 'debconf-apt-progress/title');
		my @ret=Debconf::Client::ConfModule::progress(
			'INFO', 'debconf-apt-progress/preparing');
		if ($ret[0] eq '30') {
			cancel();
		}
	}
}

sub stop_bar () {
	Debconf::Client::ConfModule::progress('STOP') if $progress;
	Debconf::Client::ConfModule::stop() unless $had_frontend;
}

if (envnonempty('DEBCONF_APT_PROGRESS_DB_REPLACE')) {
	$ENV{DEBCONF_DB_REPLACE} = $ENV{DEBCONF_APT_PROGRESS_DB_REPLACE};
} else {
	delete $ENV{DEBCONF_DB_REPLACE};
}
if (envnonempty('DEBCONF_APT_PROGRESS_DB_OVERRIDE')) {
	$ENV{DEBCONF_DB_OVERRIDE} = $ENV{DEBCONF_APT_PROGRESS_DB_OVERRIDE};
} else {
	delete $ENV{DEBCONF_DB_OVERRIDE};
}
$had_frontend = 1 unless $ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND};
delete $ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND}; # avoid inheritance

my @saved_argv = @ARGV;

my $result = GetOptions('config'       => \$config,
			'start'        => \$start,
			'from=i'       => \$from,
			'to=i'         => \$to,
			'stop'         => \$stop,
			'logfile=s'    => \$logfile,
			'logstderr'    => \$logstderr,
			'progress!'    => \$progress,
			'dlwaypoint=i' => \$dlwaypoint,
);

if (! $progress && ($start || $from || $to || $stop)) {
	die "--no-progress cannot be used with --start, --from, --to, or --stop\n";
}

unless ($start) {
	if (defined $from and not defined $to) {
		die "$0: --from requires --to\n";
	} elsif (defined $to and not defined $from) {
		die "$0: --to requires --from\n";
	}
}

my $mutex = 0;
++$mutex if $config;
++$mutex if $start;
++$mutex if $stop;
if ($mutex > 1) {
	die "$0: must use only one of --config, --start, or --stop\n";
}

if (($config or $stop) and (defined $from or defined $to)) {
	die "$0: cannot use --from or --to with --config or --stop\n";
}

start_debconf(@saved_argv) unless $config;

my $status = 0;

if ($config) {
	print <<'EOF';
DEBCONF_APT_PROGRESS_DB_REPLACE="$DEBCONF_DB_REPLACE"
DEBCONF_APT_PROGRESS_DB_OVERRIDE="$DEBCONF_DB_OVERRIDE"
export DEBCONF_APT_PROGRESS_DB_REPLACE DEBCONF_APT_PROGRESS_DB_OVERRIDE
DEBCONF_DB_REPLACE=configdb
DEBCONF_DB_OVERRIDE='Pipe{infd:none outfd:none}'
export DEBCONF_DB_REPLACE DEBCONF_DB_OVERRIDE
EOF
} elsif ($start) {
	$from = 0 unless defined $from;
	$to = 100 unless defined $to;
	start_bar($from, $to);
} elsif (defined $from) {
	$status = run_progress($from, $to, @ARGV);
} elsif ($stop) {
	stop_bar();
} else {
	start_bar(0, 100);
	if (! $cancelled) {
		$status = run_progress(0, 100, @ARGV);
		stop_bar();
	}
}

if ($cancelled) {
	Debconf::Client::ConfModule::get("debconf/priority");

	exit 30;
}
elsif ($status == 30) {
	exit 3;
}
else {
	exit $status;
}