summaryrefslogtreecommitdiff
path: root/Master/tlpkg/installer/install-menu-wizard.pl
blob: 3d7b060041d1320bf95e64a86ec726a8825618a6 (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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#!/usr/bin/env perl
# $Id$
#
# Copyright 2009 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
#

use strict;
$^W = 1;

my $svnrev = '$Revision: 11925 $';
$svnrev =~ m/: ([0-9]+) /;
$::menurevision = $1;


our %vars;
our $tlpdb;
our $texlive_release;

our $MENU_INSTALL = 0;
our $MENU_ABORT   = 1;
our $MENU_QUIT    = 2;
our $MENU_ALREADYDONE = 3;


my $return = $MENU_INSTALL;

require Tk;
require Tk::Dialog;
require Tk::DialogBox;
require Tk::PNG;
require Tk::ROText;
require Tk::ProgressBar;
require Tk::Font;

use utf8;
no utf8;

#
#
my $tit;

my $can;
my $prv;
my $nxt;

my $img;

if (defined($::opt_lang)) {
  $::lang = $::opt_lang;
  if ($::lang eq "zh") {
    # set language to simplified chinese
    $::lang = "zh-cn";
  }
} else {
  if ($^O =~ /^MSWin(32|64)$/i) {
    # trying to deduce automatically the country code
    my $foo =  TeXLive::TLWinGoo::reg_country();
    if ($foo) {
      $::lang = $foo;
    } else {
      debug("Didn't get any usuful code from reg_country: $foo...\n");
    }
  } else {
    # we load POSIX and locale stuff
    require POSIX;
    import POSIX qw/locale_h/;
    # now we try to deduce $::lang
    my $loc = setlocale(&POSIX::LC_MESSAGES);
    my ($lang,$area,$codeset);
    if ($loc =~ m/^([^_.]*)(_([^.]*))?(\.([^@]*))?(@.*)?$/) {
      $lang = defined($1)?$1:"";
      $area = defined($3)?$3:"";
      if ($lang eq "zh") {
        if ($area =~ m/^(TW|HK)$/i) {
          $lang = "zh-tw";
        } else {
          # fallback to zh-cn for anything else, that is
          # zh-cn, zh-sg, zh, and maybe something else
          $lang = "zh-cn";
        }
      }
    }
    $::lang = $lang if ($lang);
  }
}


my $dest;
my $mw;

######################################################################

sub setup_hooks_wizard {
  push @::info_hook,
    sub {
      return unless defined($mw);
      wizard_update_status(join(" ",@_));
      $mw->update;
    };
  push @::warn_hook,
    sub {
      return unless defined($mw);
      wizard_update_status(join(" ",@_));
      $mw->update;
    };
  push @::install_packages_hook, \&wizard_update_progressbar;
  push @::install_packages_hook, sub { $mw->update; };
}

sub wizard_update_status {
  my ($p) = @_;
  $::progressw->insert("end", "$p");
  $::progressw->see("end");
}
sub wizard_update_progressbar {
  my ($n,$total) = @_;
  if (defined($n) && defined($total)) {
    $::progress->value(int($n*100/$total));
  }
}

my %text = ( title      => 'TeX Live 2008 Installation',
             basicinfo  => 'Basic Information',
             custom     => 'Further Customization',
             dirsetup   => "Directory setup",
             options    => 'Options',
             sysint     => 'System Integration',
             change     => 'Change',
             toggle     => 'Toggle',
             install    => 'Install TeX Live',
             finbut     => 'Finish',
             quit       => 'Quit',
             ok         => 'Ok',
             cancel     => 'Cancel',
             status     => 'Status output',
             changevar  => 'Change variable value',
             enterpath  => 'Enter path for',
             hinthome   => '(use ~ for %%%)',
             selectscheme => 'Select a scheme',
             selectstdcol => 'Select the collections to be installed',
             selectall  => 'Select All',
             selectnone => 'Deselect All',
             selectlang => 'Select language support',
             selectdoc  => 'Select language-specific documentation',
             createsym  => 'create symlinks in standard directories',
             binto      => 'binaries to',
             manto      => 'manpages to',
             infoto     => 'info to',
             selectsys  => 'Select arch-os',
             outof      => 'out of',
             collof     => 'collections out of',
             diskreq    => 'disk space required',
             yes        => 'Yes',
             no         => 'No',
             notwritable => '(default not writable - please change!)',
             changetexdir => '(please change TEXDIR first!)',
             nolangcol  => '(no language collection selected!)',
             finished   => 'See TEXDIR/index.html for links to documentation.\nThe TeX Live web site (http://tug.org/texlive/) contains any updates and corrections. TeX Live is a joint project of the TeX user groups around the world; please consider supporting it by joining the group best for you. The list of groups is available on the web at http://tug.org/usergroups.html.',
             finishedpath => 'Add TEXDIR/texmf/doc/man to MANPATH.\nAdd TEXDIR/texmf/doc/info to INFOPATH.\nMost importantly, add TEXDIR/bin/PLATFORM\nto your PATH for current and future sessions.',
             welcome => 'Welcome to TeX Live!',
    );


my %labels = ( binsys   => 'Binary System(s)',
               scheme   => 'Selected Scheme',
               stdcoll  => 'Standard Collections',
               langcoll => 'Language Collections',
               texdir   => 'TEXDIR (the main TeX directory)',
               localdir => 'TEXMFLOCAL (directory for site-wide local files)',
               sysvardir   => 'TEXMFSYSVAR (directory for autogenerated data)',
               sysconfigdir   => 'TEXMFSYSCONFIG (directory for local config)',
               texmfhome => 'TEXMFHOME (directory for user-specific files)',
               optletter => 'Use letter size instead of A4 by default',
               optfmt   => 'Create all format files',
               optdoc   =>  'Install font/macro doc tree',
               optsrc   =>  'Install font/macro source tree',
               symlink  =>  'Create symlinks in system directories',
    );

if (($::lang ne "en") && ($::lang ne "C")) {
  if (! -r "$::installerdir/tlpkg/installer/lang/perltk-$::lang") {
    tlwarn ("\n  Sorry, no translations available for $::lang; falling back to English.
  (If you'd like to help translate the installer's messages, please see
  http://tug.org/texlive/doc.html#install-tl-xlate for information.)\n\n");
  } else {
    # merge the translated strings into the text string
    open(LANG, "<$::installerdir/tlpkg/installer/lang/perltk-$::lang");
    my %trans;
    while (<LANG>) {
      chomp;
      next if m/^\s*#/;
      next if m/^\s*$/;
      my ($a,$b) = split(/:/,$_,2);
      $b =~ s/^\s*([^\s])/$1/;
      $b =~ s/\s*$//;
      if (!utf8::decode($b)) {
        warn("decoding string to utf8 didn't work:$b\n");
      }
      $trans{"$a"} = "$b";
    }
    close(LANG);
    foreach my $k (keys %text) {
      $text{$k} = $trans{"text.$k"} if defined($trans{"text.$k"});
    }
    foreach my $k (keys %labels) {
      $labels{$k} = $trans{"label.$k"} if defined($trans{"label.$k"});
    }
  }
}


my $LEFT = 50;
my $TOP  = 50;
my $BOTTOM = 400;
my $INF = 300;

my $fmain;
my $counter;

################# WELCOME SCREEN ######################################

sub run_menu_wizard {
  $mw = Tk::MainWindow->new(-width => 640, -height => 480);
  setup_hooks_wizard();

  $dest = $vars{'TEXDIR'};

  $tit = $mw->Label(-text => "TeX Live 2008 Installation");

  $tit->place(-x => $LEFT, -y => $TOP);

  $counter = $mw->Label(-text => "1/4");
  $counter->place(-x => (640 - $LEFT), -y => $TOP, -anchor => "ne");

  $fmain = $mw->Frame(-height => ($BOTTOM - $TOP -50), -width => 540);
          #, -borderwidth => 1, -relief => "ridge");
  $fmain->place(-x => $LEFT, -y => ($TOP + 30));


  $can = $mw->Button(-width => 10, -relief => "ridge", -text => "Cancel",
               -command => sub { $return = $MENU_ABORT; $mw->destroy; });
  $nxt = $mw->Button(-width => 10, -relief => "ridge", -text => "Next >");
  $prv = $mw->Button(-width => 10, -relief => "ridge", -text => "< Back");

  $can->place(-x => $LEFT, -y => $BOTTOM);

  my $rb = 640 - $LEFT;
  $nxt->place(-x => $rb , -y => $BOTTOM, -anchor => "ne");

  reset_start();

  Tk::MainLoop();
  return($return);
}
$::run_menu = \&run_menu_wizard;

sub reset_start {
  for ($fmain->children) {
    $_->destroy;
  }
  $counter->configure(-text => "1/4");

  my $inf = $fmain->Label(-text => "Welcome to the installation of TeX Live 2008\nhttp://tug.org/texlive\n\nThis wizard will guide you through the installation.", -justify => "left");
  $inf->place(-x => 0, -y => 100);

  $nxt->configure(-text => "Next >", -command => \&ask_path );
}

################## PATH SCREEN ################################

sub ask_path {
  for ($fmain->children) {
    $_->destroy;
  }
  $counter->configure(-text => "2/4");
  my $lab = $fmain->Label(-text => "Destination Folder:");
  my $val = $fmain->Label(-textvar => \$dest);
  my $but = $fmain->Button(-text => "Change", -command => \&change_path, -relief => "ridge", -width => 10);

  my $pa = $fmain->Checkbutton(-text => "Use letter-size paper by default, instead of A4", -variable => \$vars{"option_letter"});
  my $cb = $fmain->Button(-text => "Advanced customization", 
         -relief => "ridge",
         -command => sub { $mw->destroy; 
                           #undef &run_menu;
                           @::warn_hook = ();
                           @::debug_hook = ();
                           @::info_hook = ();
                           @::install_packages_hook = ();
                           require("installer/install-menu-perltk.pl");
                           setup_hooks_perltk();
                           $return = run_menu_perltk();
                         });

  calc_depends();


  $fmain->Label(-text => "The destination folder will contain the installation.\nIt is strongly recommended to keep the year as the last component.", -justify => "left")->place(-x => 0, -y => 30);

  my $ytmp = 100;
  $lab->place(-x => 0, -y => $ytmp);
  $lab->update;
  $ytmp += $lab->height;
  $ytmp += 10;
  $val->place(-x => 0, -y => $ytmp, -anchor => "w");

  $but->place(-x => $fmain->width, -y => $ytmp, -anchor => "e");

  $pa->place(-x => 0, -y => $ytmp + 30);


  $cb->place(-x => $fmain->width, -y => $fmain->height, -anchor => "se");

  $fmain->Label(-text => "Total size needed: $vars{'total_size'} MB", 
                -justify => "left"
             )->place(-x => 0, -y => $fmain->height, -anchor => "sw");

  $prv->configure(-text => "< Prev", -command => \&reset_start );
  $nxt->configure(-text => "Next >", -command => \&ask_go );

  my $rb = 640 - $LEFT;
  $rb -= $nxt->width;
  $rb -= 30;

  $prv->place(-x => $rb, -y => $BOTTOM, -anchor => "ne");
}

sub change_path {
  my $val = $dest;
  my $sw = $mw->Toplevel(-title => "Changing TEXDIR");
  $sw->transient($mw);
  $sw->grab();
  $sw->Label(-text => $text{'enterpath'} . " TEXDIR: ")->pack(-padx => "2m", -pady => "2m");
  my $entry = $sw->Entry(-textvariable => $val, -width => 60);
  $entry->pack(-padx => "2m", -pady => "2m");
  my $f = $sw->Frame;
  my $okbutton = $f->Button(-text => $text{'ok'}, -relief => "ridge",
     -command => sub { $val = $entry->get; callback_change_texdir($val) ; $sw->destroy })->pack(-side => 'left', -padx => "2m", -pady => "2m");
  my $cancelbutton = $f->Button(-text => $text{'cancel'}, -relief => "ridge",
     -command => sub { $sw->destroy })->pack(-side => 'right', -padx => "2m", -pady => "2m");
  $f->pack(-expand => 'x');
  # bindings
  $sw->bind('<Return>' => [ $okbutton, 'Invoke']);
  $sw->bind('<Escape>' => [ $cancelbutton, 'Invoke']);
}

sub callback_change_texdir {
  my ($val) = @_;
  my $home = getenv('HOME');
  if (win32()) {
    $home = getenv('USERPROFILE');
    $home =~ s!\\!/!g;
  }
  $home ||= '~';
  $val =~ s!\\!/!g;
  $vars{'TEXDIR'} = $val;
  $vars{'TEXDIR'} =~ s/^~/$home/;
  $vars{'TEXMFLOCAL'} =~ s/^~/$home/;
  $vars{'TEXMFSYSVAR'} =~ s/^~/$home/;
  $vars{'TEXMFSYSCONFIG'} =~ s/^~/$home/;
  # only if we set TEXDIR we set the others in parallel
  if ($vars{'TEXDIR'}=~/^(.*)\/$texlive_release$/) {
    $vars{'TEXMFLOCAL'}="$1/texmf-local";
    $vars{'TEXMFSYSVAR'}="$1/$texlive_release/texmf-var";
    $vars{'TEXMFSYSCONFIG'}="$1/$texlive_release/texmf-config";
  } elsif ($vars{'TEXDIR'}=~/^(.*)$/) {
    $vars{'TEXMFLOCAL'}="$1/texmf-local";
    $vars{'TEXMFSYSVAR'}="$1/texmf-var";
    $vars{'TEXMFSYSCONFIG'}="$1/texmf-config";
  }
  $vars{'TEXDIRW'}=$vars{'TEXDIR'};
  $dest = $vars{'TEXDIR'};
}

################## INSTALL SCREEN #############################

sub ask_go {
  for ($fmain->children) {
    $_->destroy;
  }
  $counter->configure(-text => "3/4");
  my $inf = $fmain->Label(-justify => "left", -text => "We are ready to install TeX Live 2008.\nThe following settings will be used.\nIf you want to change something please go back,\notherwise press the \"Install\" button.\n\nDestination folder:   $dest");

  $inf->place(-x => 0, -y => 100);
  
  $nxt->configure(-text => "Install", 
                  -command => \&wizard_installation_window);
  $prv->configure(-text => "< Prev", -command => \&ask_path);
}

sub wizard_installation_window {
  for ($fmain->children) {
    $_->destroy;
  }
  $counter->configure(-text => "4/4");
# create a progress bar window
  # compute the height of the Text by the given font

  $::progressw = $fmain->Scrolled("ROText", -scrollbars => "e",
                                -wrap => "word");
  my $fo = $::progressw->cget("-font");

  my $lines = int( ($fmain->height - 20) / $fo->metrics("-linespace"));
  
  $::progressw->configure(-height => $lines); #, -width => $wd);

  my $pw = $fmain->height - ($lines * $fo->metrics("-linespace")) - 5;


  $::progressw->place(-x => 0, -y => 0, -width => $fmain->width);

  my $percent_done = 0;
  $fmain->update;
  print "fmain width = ", $fmain->width, "\n";
  $::progress = $fmain->ProgressBar(-variable => \$percent_done,
      -width => $pw, -length => ($fmain->width), 
      -from => 0, -to => 110, -blocks => 10,
      -colors => [ 0, '#0078b8' ]);
  $::progress->place(-x => 0, -y => $fmain->height, -anchor => "sw");

# set the vars
  calc_depends();
  do_installation();
  $::progress->value(110);
  $return = $MENU_ALREADYDONE;
  my $t = $text{'finished'};
  if (!win32()) {
    $t .= "\n\n$text{'finishedpath'}";
  }
  $t .= "\n\n$text{'welcome'}";
  $t =~ s/TEXDIR/$::vars{'TEXDIR'}/g;
  $t =~ s/PLATFORM/$::vars{'this_platform'}/g;
  $t =~ s/\\n/\n/g;
  $can->placeForget;
  $prv->placeForget;
  my $linechar = $::progressw->index("end");
  $::progressw->markSet("finaltext", $linechar);
  $::progressw->markGravity("finaltext", "left");
  $::progressw->insert("end", "\n$t");
  $::progressw->see("end");
  $::progressw->tagAdd("centered", $linechar, "end");
  $::progressw->tagConfigure("centered", -justify => "center");
  $nxt->configure(-text => $text{'finbut'},
                -command => sub { $mw->destroy; });
}

################### END OF MODULE RETURN 1 FOR REQUIRE ###########

1;

__END__

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #