Debian Codegraph @

backends/apt/pkconffile

raw
1 #!/usr/bin/perl
2
3 use Debconf::Client::ConfModule ':all';
4 use Cwd 'abs_path';
5 use File::Temp qw/ tempfile tempdir /;
6 use strict;
7
8 my $template_fname;
9 (undef, $template_fname) = tempfile('/tmp/pkconffileXXXXXX', SUFFIX => '.template');
10
11 # (1) quit unless we have the correct number of command-line args
12 if ($#ARGV + 1 != 3) {
13 print STDERR "Usage: ./pkconffile package original_conf new_conf\n";
14 exit;
15 }
16
17 ## Process template so we can add the diff at the end
18 ## the abs_path will give us the full path where this script is so we can find the template
19 open (TEMP_NODIFF, abs_path($0).'.nodiff') || die ("could not open the template");
20 open (TEMPLATE, ">$template_fname");
21
22 ## Adds the original template
23 while (<TEMP_NODIFF>) {
24 print TEMPLATE $_;
25 }
26 close (TEMP_NODIFF);
27
28 ## get the original and new files
29 my $package = $ARGV[0];
30 my $forig = $ARGV[1];
31 my $fnew = $ARGV[2];
32
33 ## Add the diff to the end of the TEMPLATE
34 my @diff = `diff -u $forig $fnew`;
35 foreach (@diff) {
36 if ($_ =~ /^\$/) {
37 print TEMPLATE " .\n";
38 } else {
39 chomp;
40 ## Add two spaces here so that the extended description
41 ## receives the proper line breaks.
42 print TEMPLATE " $_\n";
43 }
44 }
45 close (TEMPLATE);
46
47 ## Force the template to be loaded again
48 x_loadtemplatefile($template_fname);
49
50 ## set the package name in the title
51 subst("pkconffile/title", "package", $package);
52 settitle("pkconffile/title");
53
54 my $state = 1;
55 while (1) {
56 if ($state == 1) {
57 ## ask the user what to do with the conf file
58 fset("pkconffile/what_to_do", "seen", "false");
59 subst("pkconffile/what_to_do", "forig", $forig);
60 input("high", "pkconffile/what_to_do");
61 } else {
62 ## the user whants to see the diff
63 fset("pkconffile/diff", "seen", "false");
64 subst("pkconffile/diff", "forig", $forig);
65 subst("pkconffile/diff", "fnew", $fnew);
66 input("high", "pkconffile/diff");
67 }
68
69 ## get the user answer
70 if (go() == 0 && $state == 1) {
71 my @ret = get("pkconffile/what_to_do");
72 if ($ret[1] =~ "Keep the currently installed version") {
73 $state = 10;
74 last;
75 } elsif ($ret[1] =~ "Install the package maintainer's version") {
76 $state = 20;
77 last;
78 }
79 $state = 2;
80 } else {
81 $state = 1;
82 }
83 }
84
85 unlink($template_fname);
86 exit $state;