summaryrefslogtreecommitdiff
path: root/beagle/debian-rfs/usr/sbin/dpkg-reconfigure
blob: e63684fe64f4e0fb31da67d29265004d721dcb4e (plain)
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
#!/usr/bin/perl -w
# This file was preprocessed, do not edit!



my $infodir="/var/lib/dpkg/info";

use strict;
use Debconf::Db;
use Debconf::Gettext;
use Debconf::Template;
use Debconf::Config;
use Debconf::AutoSelect qw(:all);
use Debconf::Log qw(:all);

Debconf::Config->priority('low');

my $unseen_only=0;
my $all=0;
my $force=0;
my $default_priority=0;
my $reload=1;
Debconf::Config->getopt(
gettext(qq{Usage: dpkg-reconfigure [options] packages
  -a,  --all			Reconfigure all packages.
  -u,  --unseen-only		Show only not yet seen questions.
       --default-priority	Use default priority instead of low.
       --force			Force reconfiguration of broken packages.
       --no-reload		Do not reload templates. (Use with caution.)}),
	"all|a"			=> \$all,
	"unseen-only|u"		=> \$unseen_only,
	"default-priority"	=> \$default_priority,
	"force"			=> \$force,
	"reload!"		=> \$reload,
);

if ($> != 0) {
	print STDERR sprintf(gettext("%s must be run as root"), $0)."\n";
	exit 1;
}

Debconf::Db->load;

if ($default_priority) {
	Debconf::Config->priority(Debconf::Question->get('debconf/priority')->value);
}

if (lc Debconf::Config->frontend eq 'noninteractive' &&
    ! Debconf::Config->frontend_forced) {
	Debconf::Config->frontend('dialog');
}

my $frontend=make_frontend();

unless ($unseen_only) {
	Debconf::Config->reshow(1);
}

my @packages;
if ($all) {
	@packages=allpackages();
	exit unless @packages;
}
else {
	@packages=@ARGV;
	if (! @packages) {
		print STDERR "$0: ".gettext("please specify a package to reconfigure")."\n";
		exit 1;
	}
}

$ENV{DEBCONF_RECONFIGURE}=1;

foreach my $pkg (@packages) {
	$frontend->default_title($pkg);
	$frontend->info(undef);

	$_=`dpkg --status $pkg`;
	my ($version)=m/Version: (.*)\n/;
	my ($status)=m/Status: (.*)\n/;
	if (! $force) {
		if (! defined $status || $status =~ m/not-installed$/) {
			print STDERR "$0: ".sprintf(gettext("%s is not installed"), $pkg)."\n";
			exit 1;
		}
		if ($status !~ m/ ok installed$/) {
			print STDERR "$0: ".sprintf(gettext("%s is broken or not fully installed"), $pkg)."\n";
			exit 1;
		}
	}
	
	if ($reload) {
		Debconf::Template->load("$infodir/$pkg.templates", $pkg)
			if -e "$infodir/$pkg.templates";
	}

	foreach my $info (['prerm',    'upgrade',     $version],
		          ['config',   'reconfigure', $version],
			  ['postinst', 'configure',   $version]) {
		my $script=shift @$info;
		next unless -x "$infodir/$pkg.$script";

		my $is_confmodule='';

		if ($script ne 'config') {
			open (IN, "<$infodir/$pkg.$script");
			while (<IN>) {
				if (/confmodule/i) {
					$is_confmodule=1;
					last;
				}
			}
			close IN;
		}
		
		if ($script eq 'config' || $is_confmodule) {
			my $confmodule=make_confmodule(
				"$infodir/$pkg.$script", @$info);
	
			$confmodule->owner($pkg);
		
			1 while ($confmodule->communicate);
	
			exit $confmodule->exitcode if $confmodule->exitcode > 0;
		}
		else {
			Debconf::Db->save;
			
			delete $ENV{DEBIAN_HAS_FRONTEND};
			my $ret=system("$infodir/$pkg.$script", @$info);
			if (int($ret / 256) != 0) {
				exit int($ret / 256);
			}
			$ENV{DEBIAN_HAS_FRONTEND}=1;
			
			Debconf::Db->load;
		}
	}
}

$frontend->shutdown;

Debconf::Db->save;

sub allpackages {
	my @ret;
	local $/="\n\n";
	
	open (STATUS, "</var/lib/dpkg/status")
		|| die sprintf(gettext("Cannot read status file: %s"), $!);
	while (<STATUS>) {
		push @ret, $1
			if m/Status:\s*.*\sinstalled\n/ && m/Package:\s*(.*)\n/;
	}
	close STATUS;

	return sort @ret;
}