<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
# This file was preprocessed, do not edit!


package Debconf::FrontEnd::Passthrough;
use strict;
use Carp;
use IO::Socket;
use IO::Handle;
use IO::Select;
use Debconf::FrontEnd;
use Debconf::Element;
use Debconf::Element::Select;
use Debconf::Element::Multiselect;
use Debconf::Log qw(:all);
use Debconf::Encoding;
use base qw(Debconf::FrontEnd);


sub init {
	my $this=shift;

	if (not defined $this-&gt;{readfh} or not defined $this-&gt;{writefh}) {
		if (not defined $this-&gt;init_fh_from_env()) {
			die "Neither DEBCONF_PIPE nor DEBCONF_READFD and DEBCONF_WRITEFD were set\n";
		}
	}

	binmode $this-&gt;{readfh}, ":utf8";
	binmode $this-&gt;{writefh}, ":utf8";

	$this-&gt;{readfh}-&gt;autoflush(1);
	$this-&gt;{writefh}-&gt;autoflush(1);

	$this-&gt;elements([]);
	$this-&gt;interactive(1);
	$this-&gt;need_tty(0);
}


sub init_fh_from_env {
	my $this = shift;
	my ($socket_path, $readfd, $writefd);

	if (defined $ENV{DEBCONF_PIPE}) {
		my $socket_path = $ENV{DEBCONF_PIPE};
		$this-&gt;{readfh} = $this-&gt;{writefh} = IO::Socket::UNIX-&gt;new(
			Type =&gt; SOCK_STREAM,
			Peer =&gt; $socket_path
		) || croak "Cannot connect to $socket_path: $!";
		return "socket";
	} elsif (defined $ENV{DEBCONF_READFD} and defined $ENV{DEBCONF_WRITEFD}) {
		$readfd = $ENV{DEBCONF_READFD};
		$writefd = $ENV{DEBCONF_WRITEFD};
		$this-&gt;{readfh} = IO::Handle-&gt;new_from_fd(int($readfd), "r")
			or croak "Failed to open fd $readfd: $!";
		$this-&gt;{writefh} = IO::Handle-&gt;new_from_fd(int($writefd), "w")
			or croak "Failed to open fd $writefd: $!";
		return "fifo";
	}
	return undef;
}


sub talk_with_timeout {
	my $this=shift;
	my $timeout=shift;
	my $command=join(' ', map { Debconf::Encoding::to_Unicode($_) } @_);
	my $reply;
	
	my $readfh = $this-&gt;{readfh} || croak "Broken pipe";
	my $writefh = $this-&gt;{writefh} || croak "Broken pipe";
	
	debug developer =&gt; "----&gt; (passthrough) $command";
	print $writefh $command."\n";
	$writefh-&gt;flush;

	if (defined $timeout) {
		my $select = IO::Select-&gt;new($readfh);
		return undef if !$select-&gt;can_read($timeout);
	}
	return undef if ($readfh-&gt;eof());

	$reply = &lt;$readfh&gt;;
	chomp($reply);
	debug developer =&gt; "&lt;---- (passthrough) $reply";
	my ($tag, $val) = split(' ', $reply, 2);
	$val = '' unless defined $val;
	$val = Debconf::Encoding::convert("UTF-8", $val);

	return ($tag, $val) if wantarray;
	return $tag;
}


sub talk {
	my $this=shift;
	return $this-&gt;talk_with_timeout(undef, @_);
}


sub makeelement
{
	my $this=shift;
	my $question=shift;

	my $type=$question-&gt;type;
	if ($type eq "select" || $type eq "multiselect") {
		$type=ucfirst($type);
		return "Debconf::Element::$type"-&gt;new(question =&gt; $question);
	} else {
		return Debconf::Element-&gt;new(question =&gt; $question);
	}
}


sub capb_backup
{
	my $this=shift;
	my $val = shift;

	$this-&gt;{capb_backup} = $val;
	$this-&gt;talk('CAPB', 'backup') if $val;
}


sub capb
{
	my $this=shift;
	my $ret;
	return $this-&gt;{capb} if exists $this-&gt;{capb};

	($ret, $this-&gt;{capb}) = $this-&gt;talk('CAPB');
	return $this-&gt;{capb} if $ret eq '0';
}


sub title
{
	my $this = shift;
	return $this-&gt;{title} unless @_;
	my $title = shift;

	$this-&gt;{title} = $title;
	$this-&gt;talk('TITLE', $title);
}


sub settitle
{
	my $this = shift;
	my $question = shift;

	$this-&gt;{title} = $question-&gt;description;

	my $tag = $question-&gt;template-&gt;template;
	my $type = $question-&gt;template-&gt;type;
	my $desc = $question-&gt;description;
	my $extdesc = $question-&gt;extended_description;

	$this-&gt;talk('DATA', $tag, 'type', $type);

	if ($desc) {
		$desc =~ s/\n/\\n/g;
		$this-&gt;talk('DATA', $tag, 'description', $desc);
	}

	if ($extdesc) {
		$extdesc =~ s/\n/\\n/g;
		$this-&gt;talk('DATA', $tag, 'extended_description', $extdesc);
	}

	$this-&gt;talk('SETTITLE', $tag);
}


sub go {
	my $this = shift;

	my @elements=grep $_-&gt;visible, @{$this-&gt;elements};
	foreach my $element (@elements) {
		my $question = $element-&gt;question;
		my $tag = $question-&gt;template-&gt;template;
		my $type = $question-&gt;template-&gt;type;
		my $desc = $question-&gt;description;
		my $extdesc = $question-&gt;extended_description;
		my $default;
		if ($type eq 'select') {
			$default = $element-&gt;translate_default;
		} elsif ($type eq 'multiselect') {
			$default = join ', ', $element-&gt;translate_default;
		} else {
			$default = $question-&gt;value;
		}

                $this-&gt;talk('DATA', $tag, 'type', $type);

		if ($desc) {
			$desc =~ s/\n/\\n/g;
			$this-&gt;talk('DATA', $tag, 'description', $desc);
		}

		if ($extdesc) {
			$extdesc =~ s/\n/\\n/g;
			$this-&gt;talk('DATA', $tag, 'extended_description',
			            $extdesc);
		}

		if ($type eq "select" || $type eq "multiselect") {
			my $choices = $question-&gt;choices;
			$choices =~ s/\n/\\n/g if ($choices);
			$this-&gt;talk('DATA', $tag, 'choices', $choices);
		}

		$this-&gt;talk('SET', $tag, $default) if $default ne '';

		my @vars=$Debconf::Db::config-&gt;variables($question-&gt;{name});
		for my $var (@vars) {
			my $val=$Debconf::Db::config-&gt;getvariable($question-&gt;{name}, $var);
			$val='' unless defined $val;
			$this-&gt;talk('SUBST', $tag, $var, $val);
		}

		$this-&gt;talk('INPUT', $question-&gt;priority, $tag);
	}

	if (@elements &amp;&amp; (scalar($this-&gt;talk('GO')) eq "30") &amp;&amp; $this-&gt;{capb_backup}) {
		return;
	}
	
	foreach my $element (@{$this-&gt;elements}) {
		if ($element-&gt;visible) {
			my $tag = $element-&gt;question-&gt;template-&gt;template;
			my $type = $element-&gt;question-&gt;template-&gt;type;

			my ($ret, $val)=$this-&gt;talk('GET', $tag);
			if ($ret eq "0") {
				if ($type eq 'select') {
					$element-&gt;value($element-&gt;translate_to_C($val));
				} elsif ($type eq 'multiselect') {
					$element-&gt;value(join(', ', map { $element-&gt;translate_to_C($_) } split(', ', $val)));
				} else {
					$element-&gt;value($val);
				}
				debug developer =&gt; "Got \"$val\" for $tag";
			}
		} else {
			$element-&gt;show;
		}
	}

	return 1;
}


sub progress_data {
	my $this=shift;
	my $question=shift;

	my $tag=$question-&gt;template-&gt;template;
	my $type=$question-&gt;template-&gt;type;
	my $desc=$question-&gt;description;
	my $extdesc=$question-&gt;extended_description;

	$this-&gt;talk('DATA', $tag, 'type', $type);

	if ($desc) {
		$desc =~ s/\n/\\n/g;
		$this-&gt;talk('DATA', $tag, 'description', $desc);
	}

	if ($extdesc) {
		$extdesc =~ s/\n/\\n/g;
		$this-&gt;talk('DATA', $tag, 'extended_description', $extdesc);
	}
}

sub progress_start {
	my $this=shift;

	$this-&gt;progress_data($_[2]);
	return $this-&gt;talk('PROGRESS', 'START', $_[0], $_[1], $_[2]-&gt;template-&gt;template);
}

sub progress_set {
	my $this=shift;

	return (scalar($this-&gt;talk('PROGRESS', 'SET', $_[0])) ne "30");
}

sub progress_step {
	my $this=shift;

	return (scalar($this-&gt;talk('PROGRESS', 'STEP', $_[0])) ne "30");
}

sub progress_info {
	my $this=shift;

	$this-&gt;progress_data($_[0]);
	return (scalar($this-&gt;talk('PROGRESS', 'INFO', $_[0]-&gt;template-&gt;template)) ne "30");
}

sub progress_stop {
	my $this=shift;

	return $this-&gt;talk('PROGRESS', 'STOP');
}

sub shutdown {
	my $this=shift;
	$this-&gt;SUPER::shutdown();
	if (defined $this-&gt;{readfh} &amp;&amp;
	   (not defined $this-&gt;{writefh} or $this-&gt;{readfh} != $this-&gt;{writefh}))
	{
		close $this-&gt;{readfh};
		delete $this-&gt;{readfh};
	}
	if (defined $this-&gt;{writefh}) {
		close $this-&gt;{writefh};
		delete $this-&gt;{writefh};
	}
}


1

</pre></body></html>