File: write-siteconfig

package info (click to toggle)
request-tracker4 4.4.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,888 kB
  • sloc: javascript: 130,444; perl: 65,442; sh: 1,350; makefile: 480; python: 37; php: 30
file content (49 lines) | stat: -rw-r--r-- 1,439 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/perl -w
use strict;
use Text::Template;

# This script reads variable assignments of the form var=value
# on STDIN, fills in a template given as the first argument
# with these values, and outputs the result on STDOUT.

# It is used by the maintainer scripts of request-tracker4
# to turn debconf variables into a valid RT_SiteConfig.pm
# snippet.

# Note that Text::Template is already a dependency of 
# request-tracker4, so it's OK to use it from the postinst.

# Copyright 2007 Niko Tyni <ntyni@iki.fi>
#
# 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 2 of the
# License, or (at your option) any later version.  You may also can
# redistribute it and/or modify it under the terms of the Perl
# Artistic License.

my $template_file = shift;
die("usage: $0 <template>") if !$template_file;

my %values;

while (<>) {
    chomp;
    my ($var, $value) = split(/=/, $_, 2);
    if (!$var || not defined $value) {
        warn("Invalid input line: $_");
        next;
    }
    $values{$var} = $value;
}

my $template = Text::Template->new(
    TYPE    => 'FILE',
    SOURCE  => $template_file,
) or die ("Error reading template $template_file: $!");

my $result = $template->fill_in(HASH => \%values)
    or die("Error filling in the template: $Text::Template::ERROR");

print $result;