This file is indexed.

/usr/bin/dh_cme_upgrade is in libconfig-model-perl 2.047-1.

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
#!/usr/bin/perl 

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

#    Copyright (c) 2009.2012-2013 Dominique Dumont.
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser Public License as
#    published by the Free Software Foundation; either version 2.1 of
#    the License, or (at your option) any later version.
#
#    Config-Model 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
#    Lesser Public License for more details.
#
#    You should have received a copy of the GNU Lesser Public License
#    along with Config-Model; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#    02110-1301 USA

# dh_cme_upgrade file provided by libconfig-model-perl package

# See /usr/share/doc/debhelper/PROGRAMMING for debhelper details

use warnings;
use strict;
use File::Find;

use Debian::Debhelper::Dh_Lib;

my $prefix = '/usr';

init();

# See debhelper(7)
if ( $dh{NO_ACT} ) {
    exit;
}

if ( defined $ENV{DEB_BUILD_OPTIONS} and $ENV{DEB_BUILD_OPTIONS} =~ /noconfigmodel/ ) {
    warn "dh_cme_upgrade: DEB_BUILD_OPTIONS specifies 'noconfigmodel',  exiting ...\n";
    exit;
}

my @do_packages = @{ $dh{DOPACKAGES} };

unless (@do_packages) {
    @do_packages = map { m!debian/(.*)\.config-model!; $1; } glob("debian/*.config-model");
}

my @mandatory  = qw/cme-app-name cme-model-package/;
my @legal_list = ( @mandatory, qw/cme-model-version cme-options cme-purge cme-command/ );
my %legal      = map { ( $_ => 1 ) } @legal_list;

# debian/config file: foo.config-model
foreach my $package (@do_packages) {

    verbose_print("dh_cme_upgrade: package $package");

    my $metaconf = "debian/$package.config-model";

    next unless -e $metaconf;

    my %cm_config;

    # declare model name to load ($model below)
    # declare which package provides the model (optional)
    open my $meta_fh, $metaconf || die "Can't open $metaconf:$!";
    my @meta = <$meta_fh> ;
    close $meta_fh;
    while ($_ = shift @meta) {
        chomp;
        s/#.*//;
        next unless /\w/;
        my ( $k, $v ) = split /\s*?[:= ]\s*/,$_,2;
        if ( not $legal{$k} ) {
            die "Error: Unexpected option $k in $metaconf, expected @legal_list\n";
        }
        $cm_config{$k} = $v;
    }

    foreach my $k (@mandatory) {
        die "Error: Missing $k parameter in $metaconf\n" unless $cm_config{$k };
    }

    # add dependency
    addsubstvar( $package, 'misc:Depends', 'libconfig-model-perl', '>= 2.037' );

    # add dependency in misc:Depends control file
    my $dep = $cm_config{'cme-model-package'};
    $dep .= '(>= ' . $cm_config{'cme-model-version'}.')' if $cm_config{'cme-model-version'};

    addsubstvar( $package, 'misc:Depends', $dep );

    my $purge = $cm_config{'cme-purge'};
    my $command = $cm_config{'cme-command'} || 'migrate' ;
    my $munge_sub = sub {
        s/%APPNAME%/$cm_config{'cme-app-name'}/g;
        s/%PACKAGE%/$package/g;
        s/%COMMAND%/$command/g;
        no warnings 'uninitialized';
        s/%OPTION%/$cm_config{'cme-options'}/g;
        s/%PURGE%/$purge/g;
    };

    # calls autoscript to update pkg.postinst with cme command
    # see /usr/share/doc/debhelper/PROGRAMMING.gz
    autoscript( $package, postinst  => 'postinst-cme',      $munge_sub );
    autoscript( $package, config    => 'config-script-cme', $munge_sub );

    if ($purge) {
        my @purge_paths = split /\s+/, $purge ;
        my @ok = grep { m!^/etc/\w+! } @purge_paths ;
        die "Error: cme-purge is not safe ('$purge'). Expected all paths to be something like /etc/foo"
            if @ok < @purge_paths ;
        autoscript( $package, postrm  => 'postrm-cme', $munge_sub );

    }

    autotemplate( $package, 'template-cme',      $munge_sub );

}

# modified from autoscript
sub autotemplate {
    my $package  = shift;
    my $filename = shift;
    my $sub      = shift || "";

    # This is the file we will modify.
    my $outfile = "debian/" . pkgext($package) . 'templates';

    # Figure out what shell script snippet to use.
    my $infile;
    if ( defined( $ENV{DH_AUTOSCRIPTDIR} )
        && -e "$ENV{DH_AUTOSCRIPTDIR}/$filename" )
    {
        $infile = "$ENV{DH_AUTOSCRIPTDIR}/$filename";
    }
    else {
        if ( -e "$prefix/share/debhelper/autoscripts/$filename" ) {
            $infile = "$prefix/share/debhelper/autoscripts/$filename";
        }
        else {
            error("$prefix/share/debhelper/autoscripts/$filename does not exist");
        }
    }

    open(IN, $infile) or die "$infile: $!";
    open(OUT, ">$outfile") or die "$outfile: $!";
    while (<IN>) { $sub->(); print OUT }    
    close(OUT) or die "$outfile: $!";
    close(IN) or die "$infile: $!";
}


__END__

=encoding UTF-8

=head1 NAME

dh_cme_upgrade - add cme based configuration merge

=head1 SYNOPSIS

 dh_cme_upgrade [ debhelper options ] [ -p pkg ]

=head1 DESCRIPTION

B<dh_cme_upgrade is experimental>

dh_cme_upgrade is a debhelper that will modify the package script to
merge configuration on package upgrade. This merge is based on L<cme>
from L<Config::Model> and will merge user's customisations with
maintainer's configuration updates. This provides another way to
preserve users modifications during upgrades.

Configuration information used by L<cme> for upgrade are specified in
a configuration file (see below)

Configuration information is specified in a configuration model. It
must be provided by another package like
C<libconfig-model-lcdproc-perl>

=head1 REQUIREMENTS

For this program to work, package maintainer must make sure that:

=over

=item *

C<*.postinst>, C<*.postrm> and C<*.config> have a C<#DEBHELPER#>  line (if these files exist)

=item *

C<control> file has a dependency on C<${misc:Depends}>

=item *

Configuration files upgraded by C<cme> must not be conffiles. Any
default configuration file provided by upstream must not be installed
directly in C</etc>. They should be installed in C</usr/share/doc/> for
reference. C<cme> will create a default configuration file during package
installation.

=back

=head1 OPTIONS

This program accepts all debhelper options, including the C<-p>
option to specify which package(s) to act on.

=head1 Usage

C<dh_cme_upgrade> is designed be called in the rules file via
the dh command:

 %:
   dh --with cme_upgrade

No options can be passed to C<dh_cme_upgrade>. Its
configuration must be specified in C<debian/*.config_model> file. This
file contains several lines, each in the form of "key: value".

Here are the possible keys:

=over

=item cme-app-name

Specifies the application or model name (à la C<Config::Model>) that will be used to
perform the upgrade. (mandatory)

=item cme-model-package

Specifies the debian package that provide the model specified by
C<cme-app-name>. (mandatory)

=item cme-model-version

Specifies the minimal version of the package that provides the model.
(optional)

=item cme-command

Specify the command passed to L<cme>. Defaults to C<migrate>. Another useful value is C<fix> which
will migrate and fix the configuration file.

=item cme-options

Specify a list of options or command that will be passed verbatim to
L<cme> during upgrade. (optional)

=item cme-purge

Specify the configuration files or directory to be removed when purging the package. E.g
C</etc/LCDd.conf*> or C</etc/java/>. Several files or directory can be purged by using a shell glob.
If this option is empty, configuration files handled by cme will be left as-is after a purge.

=back

=head1 Examples

Here's a possible configuration for openssh server:

 $ cat debian/openssh-server.config-model
 cme-app-name: sshd
 cme-model-package: lib-config-model-openssh-perl
 cme-model-version: 1.206

For lcdproc:

 $ cat debian/lcdproc.config-model
 cme-app-name: lcdproc
 cme-package: libconfig-model-lcdproc-perl
 cme-model-version: 2.040
 # required to upgrade LCDd.conf from upstream configuration
 cme-options: -force
 cme-purge: /etc/LCDd.conf*

For Popcon:

 $ cat debian/popcon.config-model
 cme-app-name: popcon
 cme-model-package: libconfig-model-perl

=head1 debian files setup

C<dh_cme_upgrade> will work only if:

=over 4

=item *

C<control> file contains a C<S{misc:Depends}> variable in C<Depends> line

=item *

C<rules> contains a C<#DEBHELPER#> line to insert generated postinst snippet

=back

=head1 ENVIRONMENT

This program will exit(0) if C<DH_NO_ACT> is set or if C<DEB_BUILD_OPTIONS>
contains C<noconfigmodel>.

=head1 SEE ALSO

L<debhelper>

This program is an addendum to debhelper (part of libconfig-model-perl).

=head1 AUTHOR

Dominique Dumont <dod@debian.org>

=cut