Debian Codegraph @

debian/postinst

raw
1 #! /usr/bin/perl -w
2
3 package Debconf::Client::ConfModuleX;
4
5 #
6 # Add the error checking behaviour that I think
7 # Debconf::Client::ConfModule should have anyway
8 #
9
10 use Debconf::Client::ConfModule;
11
12 use base qw(Exporter);
13
14 BEGIN {
15 *EXPORT_OK = \@Debconf::Client::ConfModule::EXPORT_OK;
16 *EXPORT_TAGS = \%Debconf::Client::ConfModule::EXPORT_TAGS;
17 }
18
19 sub AUTOLOAD {
20 my $cmd = our $AUTOLOAD;
21 $cmd =~ s|.*:||;
22
23 my ($ret, $text) = &{"Debconf::Client::ConfModule::$cmd"}(@_);
24 if ($ret == 0 or $ret >= 30 && $ret < 100) {
25 # expected return values
26 return wantarray ? ($ret, $text) : $text;
27 }
28
29 $cmd = uc $cmd;
30 my $msg = $text ? "$text ($ret)" : "code $ret";
31
32 require Carp;
33 if ($ret < 10 || $ret >= 110) {
34 Carp::confess("Debconf $cmd returned reserved error code? $msg");
35 } elsif ($ret < 20) {
36 # Dump @_ ?
37 Carp::croak("Debconf $cmd: invalid parameters: $msg");
38 } elsif ($ret < 30) {
39 Carp::confess("Debconf $cmd: syntax error: $msg");
40 } else { # $ret < 110
41 Carp::confess("Debconf $cmd: debconf internal error: $msg");
42 }
43 }
44
45 1;
46
47 package main;
48
49 use IO::File;
50 use Data::Dumper;
51
52 #use Debconf::Client::ConfModuleX qw(get);
53 BEGIN { Debconf::Client::ConfModuleX->import(qw(get)) }
54
55 use strict;
56
57 # call systemd-tmpfiles first
58 my $temp = "set -e\nset -- @ARGV\n" . << 'MYEOF';
59 #DEBHELPER#
60 sleep 1
61 MYEOF
62 system($temp) == 0
63 or die "Problem with debhelper scripts: $!\n";
64
65
66 my $configfile = '/var/lib/libapache-sessionx-perl/Config.pm';
67
68
69 # read config vales out of debconf and build A::SX::Config structures
70
71 # from Apache::SessionX Makefile.PL:
72 my %Store =
73 (
74 'File' =>
75 {
76 param =>
77 {
78 'Store' => 'File',
79 'Lock' => 'Semaphore',
80 'Serialize' => 'Storable',
81 'Directory' => '?',
82 },
83 },
84
85 'FileFile' =>
86 {
87 param =>
88 {
89 'Store' => 'File',
90 'Lock' => 'File',
91 'Serialize' => 'Storable',
92 'Directory' => '?',
93 'LockDirectory' => '?',
94 },
95 },
96
97 'DB_File' =>
98 {
99 param =>
100 {
101 'Lock' => 'File',
102 'Serialize' => 'Storable',
103 'FileName' => '?',
104 'LockDirectory' => '?',
105 },
106 },
107
108 'Mysql' =>
109 {
110 param =>
111 {
112 'Store' => 'MySQL',
113 'Lock' => 'Semaphore',
114 'Serialize' => 'Storable',
115 'DataSource' => '?',
116 'UserName' => '?',
117 'Password' => '?',
118 },
119 'require' =>
120 [
121 'DBD::mysql',
122 ],
123 },
124
125 'MysqlMysql' =>
126 {
127 param =>
128 {
129 'Store' => 'MySQL',
130 'Lock' => 'MySQL',
131 'Serialize' => 'Storable',
132 'DataSource' => '?',
133 'UserName' => '?',
134 'Password' => '?',
135 'LockDataSource' => '?',
136 'LockUserName' => '?',
137 'LockPassword' => '?',
138 },
139 'require' =>
140 [
141 'DBD::mysql',
142 ],
143 },
144
145 'Oracle' =>
146 {
147 param =>
148 {
149 'Lock' => 'Null',
150 'Serialize' => 'Base64',
151 'Commit' => 1,
152 'DataSource' => '?',
153 'UserName' => '?',
154 'Password' => '?',
155 },
156 'require' =>
157 [
158 'DBD::Oracle',
159 ],
160 },
161 'Sybase' =>
162 {
163 param =>
164 {
165 'Lock' => 'Null',
166 'Serialize' => 'Sybase',
167 'Commit' => 1,
168 'DataSource' => '?',
169 'UserName' => '?',
170 'Password' => '?',
171 },
172 'require' =>
173 [
174 'DBD::Sybase',
175 ],
176 },
177 'Postgres' =>
178 {
179 param =>
180 {
181 'Lock' => 'Null',
182 'Serialize' => 'Base64',
183 'Commit' => 1,
184 'DataSource' => '?',
185 'UserName' => '?',
186 'Password' => '?',
187 },
188 'require' =>
189 [
190 'DBD::Pg',
191 ],
192 },
193 ) ;
194
195 my @confs = ();
196 my %param = ();
197
198 sub get_store_val {
199 my $lc = lc $_[1];
200 get "libapache-sessionx-perl/store_$_[0]_$lc";
201 }
202
203 foreach (split ',', get 'libapache-sessionx-perl/priv_keys') {
204 my %this = ();
205 my $type = get_store_val $_, 'type';
206 my $name = get_store_val $_, 'name';
207
208 # copy across values from %Store, filling '?' with debconf values
209 while (my ($param, $value) = each %{$Store{$type}{param}}) {
210 $this{$param} = $value eq '?' ? get_store_val($_, $param) : $value;
211 }
212
213 $this{Store} ||= $type;
214 $this{Serialize} ||= 'Storeable';
215 $this{Lock} ||= 'Semaphore';
216 $this{Generate} ||= 'MD5';
217
218 push @confs, $name;
219 $param{$name} = \%this;
220 }
221
222 my $default = get 'libapache-sessionx-perl/default_store';
223
224 my $newconfig = "$configfile.new";
225
226 my $newfh = new IO::File $newconfig, 'w' or
227 die "Couldn't write to $newconfig: $!\n";
228
229 END {
230 # cleanup if something went wrong
231 if ($newfh) {
232 undef $newfh;
233 unlink $newconfig;
234 }
235 }
236
237 # generate config file
238
239 print $newfh <<'EOF';
240 #
241 # Apache::SessionX configuration
242 #
243 # Autogenerated by libapache-sessionx-perl Debconf script, do not edit!
244 # Run dpkg-reconfigure libapache-sessionx-perl if you wish to make changes.
245 #
246
247 package Apache::SessionX::Config ;
248
249 EOF
250
251 $newfh->print(Data::Dumper->Dump([$default, \@confs, \%param],
252 [qw(default *confs *param)]));
253
254 print $newfh <<'EOF';
255
256 1;
257 EOF
258
259 # commit changes
260 close $newfh
261 or die "Error flushing $newconfig: $!\n";
262 rename $newconfig, $configfile
263 or die "Error renaming $newconfig to $configfile: $!\n";