This file is indexed.

config is in tvtime 1.0.2-10ubuntu10.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

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
#! /usr/bin/perl
# config - Debconf configuration for tvtime
# Copyright (C) 2003  Billy Biggs
#
# 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.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use strict;
use warnings;
use English;
use Fcntl ':mode';
use File::Copy;

# Source debconf library
use Debconf::Client::ConfModule ':all';
# Declare the version, and the ability to back up.
version(2.0);
capb('backup');

		    ### CONFIG FILE ARGUMENTS ###

# Get the name of the XML config file
my $pkgsysconfdir = '/etc/tvtime';
my $tvtime_xml = "$pkgsysconfdir/tvtime.xml";
my $tvtime_configure = '/usr/bin/tvtime-configure';

		       ### DATA STRUCTURES ###

# Each $options{} consists of a key with the name of the <option>.
# and the value is a reference to another hash.
my %options;

# We want to be able to add to %options.
sub add_to_options ($) {
    my $option_name = shift;
}

### OPTIONS ###

# These are the options to look for.
# High priority Debconf questions.
add_to_options("norm");
add_to_options("frequencies");
# Low priority Debconf questions.
add_to_options("device");
add_to_options("vbidevice");
add_to_options("priority");

### PARSE FILES ###

sub parse_conf_line ($) {
    $_[0] =~ m/([^:]*):(.*)/;
    if ($1 eq 'V4LDevice') {
	$options{'device'} = $2;
    }
    else {
	$options{lc($1)} = $2;
    }
}

# Ask tvtime-configure to give us the values of certain things.
sub parse_conf () {
    if (-e $tvtime_xml and -x $tvtime_configure) {
	# Here we set $options{$name}
	open(CONFIG,
	     "$tvtime_configure --configfile=\"$tvtime_xml\" " .
	     "--norm --frequencies --device --vbidevice --priority " .
	     "2>/dev/null |");
	
	# Watch out!  tvtime-configure --vbidevice is broken in 0.9.10-7 and
	# previous.  We must check for a functional version!
	if (not $_ = <CONFIG>) {
	    open(CONFIG,
		 "$tvtime_configure --configfile=\"$tvtime_xml\" " .
		 "--norm --frequencies --device --priority 2>/dev/null |");
	    $options{'vbidevice'} = '/dev/vbi0';
	} else {
	    parse_conf_line($_);
	}

	# Parse the input from the program
	while (<CONFIG>) {
	    parse_conf_line($_);
	}
    }
}

# Detect setuid on the binary
my $tvtime_setuid;
sub detect_setuid () {
    my $tvtime_bin = '/usr/bin/tvtime';
    my $tvtime_mode;
    if (-x $tvtime_bin) {
	$tvtime_mode = (stat($tvtime_bin))[2];
	$tvtime_setuid = $tvtime_mode & S_ISUID;
    }
}

### DEBCONF STUFF ###

# Set defaults for "Type: Select"
sub set_select ($$$@) {
    my $name = shift;
    my $template = 'tvtime/' . shift;
    my $priority = shift;
    my @select_values = @_;

    if (defined $options{$name}
	and lc(get($template)) ne lc($options{$name})) {
	for my $k (@select_values) {
	    if (lc($options{$name}) eq $k) {
		set($template, $options{$name});
		last;
	    }
	}
    }
    input($priority, $template);
}

# Set defaults for "Type: String"
sub set_string ($$$) {
    my $name = shift;
    my $template = 'tvtime/' . shift;
    my $priority = shift;

    if (defined $options{$name}
	and (get($template)
	     ne $options{$name})) {
	set($template, $options{$name});
    }
    input($priority, $template);
}

# Set defaults for "Type: Boolean"
sub set_boolean ($$$) {
    my $name = shift;
    my $template = 'tvtime/' . shift;
    my $priority = shift;

    if (defined $options{$name}) {
	my $boolean;
	if ($options{$name} eq '0') {
	    $boolean = 'false';
	}
	elsif ($options{$name} eq '1') {
	    $boolean = 'true';
	}

	if (get($template) ne $boolean) {
	    set($template, $boolean);
	}
    }
    input($priority, $template);
}

# Setup the state machine for Q&A
sub ask_questions ($) {
    my $debconf_state = shift;
    while (($debconf_state != 0) and ($debconf_state != 7)) {
	if ($debconf_state == 1) {
	    # Select the Norm
	    set_select('norm', 'norm', 'high',
		       ('NTSC','NTSC-JP','PAL','PAL-60','PAL-M','PAL-N',
			'PAL-Nc','SECAM'));
	}
	elsif ($debconf_state == 2) {
	    my $norm = get('tvtime/norm');
	    if ($norm eq "NTSC" || $norm eq "PAL-M" || $norm eq "PAL-Nc") {
		# Select the frequency table for NTSC.
		set_select('frequencies', 'frequencies-ntsc', 'high',
			   ('Cable' => 'us-cable',
			    'Broadcast' => 'us-broadcast',
			    'Cable including channels 100+' => 'us-cable100'));
	    }
	    elsif ($norm eq "NTSC-JP") {
		# Select the frequency table for Japan.
		set_select('frequencies', 'frequencies-jp', 'high',
			   ('Cable','Broadcast'));
	    }
	    elsif ($norm eq "PAL" || $norm eq "PAL-60" || $norm eq "PAL-N"
		   || $norm eq "SECAM") {
		# Select the frequency table for PAL and SECAM
		set_select('frequencies', 'frequencies-pal', 'high',
			   ('Australia' => 'australia',
			    'Australia Optus' => 'australia-optus',
			    'China Broadcast' => 'china-broadcast',
			    'Europe' => 'europe',
			    'France' => 'france',
			    'New Zealand' => 'newzealand',
			    'Russia' => 'russia',
			    'Custom' => 'custom'));
	    }
	}
	elsif ($debconf_state == 3) {
	    # Specify the television capture device.
	    set_string('device', 'v4ldevice', 'low');
	}
	elsif ($debconf_state == 4) {
	    # Specify the VBI device
	    set_string('vbidevice', 'vbidevice', 'low');
	}
	elsif ($debconf_state == 5) {
	    # Specify whether to setuid root /usr/bin/tvtime.
	    if (defined $tvtime_setuid) {
		my $setuid;
		if ($tvtime_setuid) {
		    $setuid = 'true';
		}
		else {
		    $setuid = 'false';
		}

		if (get('tvtime/setuid') ne $setuid) {
		    set('tvtime/setuid', $setuid);
		}
	    }
	    input('medium', 'tvtime/setuid');
	}
	elsif ($debconf_state == 6) {
	    # Specify the process priority if tvtime is setuid.
	    if (defined $options{'priority'}
		and (get('tvtime/processpriority')
		     ne $options{'priority'})) {
		set('tvtime/processpriority',
		    $options{'priority'});
	    }
	    if (get('tvtime/setuid') eq 'true') {
		input('low', 'tvtime/processpriority');
	    }
	}

	# Code to handle the query, and then going backwards and forwards in
	# the state machine.
	my @return;
	if (@return = go()) {
	    if ($return[0] == 30) {
		# Back button was pushed.
		$debconf_state--;
	    }
	    else {
		$debconf_state++;
	    }
	}
	else {
	    $debconf_state--;
	}
    }
}

# We will only parse /etc/tvtime/tvtime.xml if tvtime-configure
# exists.  In the event that tvtime.xml exists, but tvtime-configure
# doesn't, we assume that the sysadmin put tvtime.xml there on
# purpose, and it is correct.
my $first_question = 1;
detect_setuid();
if (-x $tvtime_configure) {
    parse_conf();
}
elsif (-e $tvtime_xml) {
    # touch /etc/tvtime/debconf.tvtime.xml
    open(OUT, ">$pkgsysconfdir/debconf.tvtime.xml");
    close(OUT);
    $first_question = 5;		# Only ask setuid questions
}
ask_questions($first_question);