[go: up one dir, main page]

File: config

package info (click to toggle)
timezoneconf 0.5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 144 kB
  • ctags: 26
  • sloc: python: 222; perl: 112; makefile: 39
file content (124 lines) | stat: -rw-r--r-- 3,068 bytes parent folder | download
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
#!/usr/bin/perl -w

use Debconf::Client::ConfModule qw(:all);

my $version = version(2.0);
title('Time Zone Configuration');
my $PRIORITY = 'low';
my $b = 'timezoneconf';
my $next = 'toplevel';

do {
  my @retval = &$next(@nextargs);
  #  if ($retval[0] eq 'BACK') {
  #    $retval[0] = $backups{$next};
  #  }
  ($next, @nextargs) = @retval;
} while ($next ne 'Exit');

sub toplevel {
  # First, need to find out the continents.  These are the
  # dirs in /usr/share/zoneinfo, minus a few.

  chdir("/usr/share/zoneinfo") ||
    die "Couldn't chdir to /usr/share/zoneinfo: $!";
  
  my @dirs = glob("*/");
  my @choices = ();
  foreach my $dir (@dirs) {
    chop $dir;
    unless ($dir =~ /^(posix|right|SystemV)$/) {
      push @choices, $dir;
    }
  }

  subst("$b/toplevel", 'choices', join(", ", sort(@choices)));
  exit(0) if (input($PRIORITY, "$b/toplevel") eq "question skipped");
  go();
  return 'zone';
}

sub zone {
  # Now, find the timezones in the specified area.
  my $zonedir = get("$b/toplevel");
  chdir("/usr/share/zoneinfo/$zonedir") ||
    die "Couldn't chdir to /usr/share/zoneinfo/$b: $!";
  my @files = glob("*");
  my @zones = ();
  foreach my $file (@files) {
    push @zones, $file if (! -d $file);
  }
  subst("$b/zone", 'choices', join(", ", @zones));
  input($PRIORITY, "$b/zone");
  go();
  return 'changetimep';
}

sub changetimep {
  # Set the vars.
  $ENV{TZ} = scalar(get("$b/toplevel")) . "/" .
    scalar(get("$b/zone"));
  subst("$b/changetime-p", 'zone', $ENV{TZ});
  my $localtime = `/bin/date`;
  chomp $localtime;
  subst("$b/changetime-p", 'localtime', $localtime);
  my $utctime = `/bin/date --utc`;
  chomp $utctime;
  subst("$b/changetime-p", 'UTCtime', $utctime);
  input($PRIORITY, "$b/changetime-p");
  go();
  return 'Exit' if (get("$b/changetime-p") eq 'false');
  return 'year';
}

sub year {
  input($PRIORITY, "$b/year");
  return 'month';
}

sub month {
  input($PRIORITY, "$b/month");
  return 'day';
}

sub day {
  input($PRIORITY, "$b/day");
  return 'time';
}

sub time {
  input($PRIORITY, "$b/time");
  go();
  
  print STDERR "D: Deciding whether to adjust clock...\n";

  # magic here: don't reset the time if we get run again.
  # Note that time() should never even get called in that situation
  # but add the check just to be on the safe side.

  return 'Exit' if (get("$b/changetime-p") eq 'false');
  return 'Exit' if (fget("$b/changetime-p", "isdefault") eq 'true');

  # Now set it to false so future invocations won't change it.

  set("$b/changetime-p", 'false');

  print STDERR "D: Decided yes.\n";

  ### Ugliness here.  We set the clock right now rather than in postinst.
  # Reason: delay between config and postinst could cause the config
  # script to store a time that's already passed.

  my $cmdline = '/bin/date \'--set=' .
    scalar(get("$b/month")) . ' ' .
    scalar(get("$b/day")) . ' ' .
    scalar(get("$b/year")) . ' ' .
    scalar(get("$b/time")) . "'" . ' > /dev/null';

  print STDERR "Running $cmdline\n";
  system($cmdline);

  set("$b/time", '');
  
  return 'Exit';
}