This file is indexed.

/usr/share/perl5/Rex/PkgConf/Debian.pm is in rex 1.4.1-1.

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

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
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

package Rex::PkgConf::Debian;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

use Rex::Helper::Run;

use Rex::PkgConf::Base;
use base qw(Rex::PkgConf::Base);

sub new {
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = $proto->SUPER::new(@_);

  bless( $self, $proto );

  return $self;
}

sub get_options {
  my ( $self, $pkg, $option ) = @_;
  die "Package name required to configure" unless $pkg;
  my $conf_cmd = "debconf-show $pkg";

  Rex::Logger::debug("Running command $conf_cmd");
  my @lines = i_run $conf_cmd;

  my %config;
  for my $line (@lines) {

    # Expecting: * postfix/relayhost: smtp.example.com
    Rex::Logger::debug("Parsing line $line");
    if ( $line =~ m!^(\*?)\s+(.+):\s*(.*)! ) {
      my ( $already_set, $question, $value ) = ( $1, $2, $3, $4 );
      Rex::Logger::debug(
        "Found configuration question $question with value $value");
      next if $option && $option ne $question;
      $already_set = $already_set ? 1 : 0;
      $config{$question} = {
        question    => $question,
        value       => $value,
        already_set => $already_set,
      };
    }
  }

  %config;
}

sub set_options {
  my ( $self, $pkg, $values, %options ) = @_;
  die "set_option usage: set_option package, values, options"
    unless $pkg && $values;

  # Get existing options first, to see if they need setting
  my %existing = $self->get_options($pkg);

  my @updated;
  for my $line (@$values) {

    my ( $question, $value, $type ) =
      ( $line->{question}, $line->{value}, $line->{type} );

    die "Question and type required for each package configuration option"
      unless $question && $type;

    if ( $existing{$question} && $existing{$question}->{value} eq $value ) {
      Rex::Logger::debug("Option $question already set to $value, ignoring");
      next;
    }

    if ( $options{no_update}
      && $existing{$question}
      && $existing{$question}->{already_set} )
    {
      Rex::Logger::debug("Option $question already set, not updating");
      next;
    }

    push @updated, $question;
    Rex::Logger::debug("Will set option $question: $value (type $type)");
    push @updated, "$pkg $question $type $value";
  }

  if (@updated) {
    my $settings = join '\n', @updated;
    my $conf_cmd = qq(echo -e "$settings"|debconf-set-selections);
    i_run $conf_cmd;
    return {
      changed => 1,
      names   => \@updated,
    };
  }
  else {
    return { changed => 0, };
  }
}

1;