summaryrefslogtreecommitdiff
path: root/Master/common.sh
blob: 89cfb8c60b770b493e4ae312fae9d4de94d34161 (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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
#!/bin/sh
# $Id$
# 
# common.sh -- common routines for the TeX Live installation scripts.
# Do not call directly.
# 
# Copyright (c) Sebastian Rahtz and Karl Berry 2003, 2004, 2005, 2006.
#
#    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., 51 Franklin Street, Fifth Floor, Boston, MA
#    02110-1301, USA.
#     
#    Send bug reports or suggestions to tex-live@tug.org.

# We only do English, and we don't want different locales to mess up the
# output of, e.g., ls.
LC_ALL=C; export LC_ALL

setvars()
{
  # These names correspond to the texmf/lists/bin-tex.* files, with -
  # changed to _.
  p_alpha_linux_n='DEC Alpha with GNU/Linux'
  p_alphaev5_osf_n='DEC Alphaev5 OSF'
  p_i386_cygwin_n='Intel x86 with Cygwin'
  p_i386_darwin_n='Intel x86 with MacOSX/Darwin'
  p_i386_freebsd_n='Intel x86 with FreeBSD'
  p_i386_linux_n='Intel x86 with GNU/Linux'
  p_i386_solaris_n='Intel x86 with Sun Solaris'
  p_mips_irix_n='SGI IRIX'
  p_powerpc_aix_n='PowerPC AIX'
  p_powerpc_darwin_n='Mac OSX/Darwin 5.3 or 6.*'
  p_sparc_linux_n='Sparc with GNU/Linux'
  p_sparc_solaris_n='Sparc with Solaris'
  p_win32_n='Windows'
  p_x86_64_linux_n='Intel x86_64 with GNU/Linux'


  iden_1=a
  iden_2=b
  iden_3=c
  iden_4=d
  iden_5=e
  iden_6=f
  iden_7=g
  iden_8=h
  iden_9=i
  iden_10=j
  iden_11=k
  iden_12=l
  iden_13=m
  iden_14=n
  iden_15=o
  iden_16=p
  iden_17=s
  iden_18=t
  iden_19=u
  iden_20=v
  iden_21=w
  iden_22=x
  iden_23=y
  iden_24=z
  iden_25=A
  iden_26=B
  iden_27=C
  iden_28=D
  iden_29=E
  iden_30=F
  iden_31=G
  iden_32=H
  iden_33=I
  iden_34=J
  iden_35=K
  iden_36=L
  iden_37=M
  iden_38=N
  iden_39=O
  iden_40=P
  iden_41=T
  iden_42=U
  iden_43=V
  iden_44=W
  iden_45=X
  iden_46=Y
  iden_47=Z
  iden_48=1
  iden_49=2
  iden_50=3
  iden_51=4
  iden_52=5
  iden_53=6
  iden_54=7
  iden_55=8
  iden_56=0
  iden_57=@
}


series_select_level()
{
  p=$1
  l=$2
  case $l in
    0) eval p_${p}_s=false
       eval p_${p}_level=\'[ ]\'
       eval p_${p}_dus=0;;
    1) eval p_${p}_s=true
       eval p_${p}_level=\'[X]\'
       eval p_${p}_dus=\$p_${p}_du;;
    2) eval S=\$p_${p}_s
       if test "$S" = "true"; then
         eval p_${p}_s=false
         eval p_${p}_level=\'[ ]\'
         eval p_${p}_dus=0
       else
         eval p_${p}_s=true
         eval p_${p}_level=\'[X]\'
         eval p_${p}_dus=\$p_${p}_du
       fi
       ;;
  esac
  setlength p_${p}_dus 6
}

scheme_select()
{
  S=`echo $1 | sed -e 's/_/-/g' `
  series_lang_allnone
  series_allnone
  for i in `grep "^-collection-" $LISTS/$S.scheme | sed -e 's/^-//' -e 's/-/_/g'`
  do
     series_select_level $i 1
  done
  selected_packages=`grep "^[+\-]" $LISTS/$S.scheme | grep -v collection- | sed -e 's/^.//' -e 's/-/_/'`
  selected_collections=`grep "^-collection-" $LISTS/$S.scheme | sed -e 's/^-collection-//'`
}

system_selectall()
{
  size=0
  for s in $all_systems; do
    eval p_${p}_s=false
    eval size=\`expr $size + \$p_${s}_du\`
    eval p_${s}_s=true
  done
  all_systems_ns=$all_systems_anz
  setlength all_systems_ns 2
}

system_deselectall()
{
  for s in $all_systems; do
    series_select_level $s 0
  done
  all_systems_ns=0
  setlength all_systems_ns 2
}

series_lang_allnone()
{
  for s in $all_lang_collections; do
    series_select_level $s 0
  done
  series_select_level tex_basic 1
  total_stat
}

series_lang_allall()
{
  for s in $all_lang_collections; do
    series_select_level $s 1
  done
  total_stat
}

series_allnone()
{
  for s in $all_collections; do
    series_select_level $s 0
  done
  series_select_level tex_basic 1
  total_stat
}

series_allall()
{
  for s in $all_collections; do
    series_select_level $s 1
  done
  total_stat
}


systems_init () {
  $echon "Initializing system packages... "
  all_systems=
  anz=0
  for s in $systems; do
    anz=`expr $anz + 1`
    t=`echo $s | sed 's@-@_@g; s@\.@@g'`
    all_systems="$all_systems $t"
    eval p_${t}_fn=$s
    eval p_${t}_s=false
  done
  echo "done."
  
  all_systems_anz=$anz
  platform_guess
  if test -n "$this_system"; then
    eval p_${this_system}_s=true
    eval this_platform_n=\$p_${this_system}_n
    eval this_platform_fn=\$p_${this_system}_fn
    all_systems_ns=1
  fi
  setlength all_systems_anz 2
  setlength all_systems_ns 2
    total_stat
}

select_platforms()
{
  changed=false
  cls
  echo "Available sets of binaries: ";
  for p in $all_systems; do eval name=\"\$p_${p}_n\"; echo "  $p: $name" ;done
  echo "You can now choose to install some of these "
  echo "Possible answers: <Y>es, <N>o, <R>eturn to main menu, <Q>uit."
  echo ""
  for p in $all_systems; do
    eval name=\"\$p_${p}_n\"
    case `getopt YNRQ "Install binaries for system [$p] $name"` in
      Y) eval p_${p}_s=true; changed=true;;
      N) eval p_${p}_s=false; changed=true;;
      R) break;;
      Q) exit_on_confirm;;
    esac
  done
  $changed && { system_stat;   total_stat; }
}

system_stat()
{
  $echon "Counting selected system packages... "
  anz=0
  for i in $all_systems; do
    eval \$p_${i}_s && anz=`expr $anz + 1`
  done
  all_systems_ns=$anz
  setlength all_systems_ns 2
  echo "done."
}

nobinstat()
{
  $echon "Counting selected collections... "
  anz=0
  for i in $all_collections; do
    eval \$p_${i}_s && anz=`expr $anz + 1`
  done
  for i in $all_lang_collections; do
    eval \$p_${i}_s && anz=`expr $anz + 1`
  done
  all_collections_ns=$anz
  setlength all_collections_ns 2
  echo "done."

  $echon "Calculating disk space requirements for collections..."
  size=0
  for i in $all_collections; do
    eval \$p_${i}_s && eval size=\`expr $size + \$p_${i}_du\`
  done
  for i in $all_lang_collections; do
    eval \$p_${i}_s && eval size=\`expr $size + \$p_${i}_du\`
  done
  all_collections_dus=$size
  setlength all_collections_dus 6
  echo "done."
}

total_stat()
{
  nobinstat
  total_dus=`expr $all_collections_dus`
  setlength total_dus 6
}

this_platform_set()
{
  system_deselectall
  if test -n "$this_system"; then
    eval p_${this_system}_s=true
    size=0
    eval size=\`expr $size + \$p_${this_system}_du\`
    eval this_platform_n=\$p_${this_system}_n
    eval this_platform_fn=\$p_${this_system}_fn
    all_systems_ns=1
  fi

}

TEXMFCNF__fix_texmf()
{
  #test "$TEXDIR/texmf" = "$TEXMF" && return
  #test -w "$TEXMFCNF_DIR/texmf.cnf" || return
  cd $work_dir || exit 1
  #
  LOCAL=$TEXMFLOCAL
  if test "x$LOCAL_CHANGE" = "x1"; then
    : # explicitly set by user.
  elif test "x$LOCAL_CHANGE" = "x2"; then
    # implicitly set by changing TEXDIR
    LOCAL="\$SELFAUTOPARENT/texmf-local"
  else
    # no changes, meaning they took the default of /usr/local/texlive/2005,
    # meaning we want /usr/local/texlive/texmf-local ... one level up.
    LOCAL="\$SELFAUTOPARENT/../texmf-local"
  fi
  echo "Setting local tree (TEXMFLOCAL) to $LOCAL in $TEXMFCNF_DIR/texmf.cnf... " >&2
  sed "s@^TEXMFLOCAL.*@TEXMFLOCAL=$LOCAL@" $TEXMFCNF_DIR/texmf.cnf \
    >.sed_tmp.$$
  #
  VAR=$TEXMFSYSVAR
  test "x$VAR_CHANGE" = "x" && VAR="\$SELFAUTOPARENT/texmf-var"
  echo "Setting system var tree (TEXMFSYSVAR) to $VAR in $TEXMFCNF_DIR/texmf.cnf... " >&2
  sed "s@^TEXMFSYSVAR.*@TEXMFSYSVAR=$VAR@" \
    <.sed_tmp.$$ >$TEXMFCNF_DIR/texmf.cnf 
  rm .sed_tmp.$$
  # 
  # the TEXMFHOME tree
  if test "x$HOME_CHANGE" = "x1"; then
    # if the variable starts with the explicit home of the current user, 
    # replace that with the string '$HOME' as the explicit home of the 
    # current user is most certainly not what we want.
    HME=`echo "$TEXMFHOME" | sed "s@$HOME/*@@" ` ;
    TEXMFHOME="\$HOME/$HME" 
  fi
  echo "Setting the user texmf home (TEXMFHOME) to \$HOME/$TEXMFHOME in $TEXMFCNF_DIR/texmf.cnf... " >&2
  sed "s@^TEXMFHOME.*@TEXMFHOME=\$HOME/$TEXMFHOME@" $TEXMFCNF_DIR/texmf.cnf >.sed_tmp.$$
  cp .sed_tmp.$$ $TEXMFCNF_DIR/texmf.cnf
  rm .sed_tmp.$$
  echo Done fixing texmf.cnf. >&2
}


TEXMFCNF__fix_fmtutil()
{
  echo "Configuring fmtutil.cnf from $TEXMFCNF_DIR  into  $TEXMFSYSVAR/web2c... " >&2
  cd $work_dir
  mkdirhier $TEXMFSYSVAR/web2c
  sed "s@^\#!\#@@" $TEXMFCNF_DIR/fmtutil.cnf > $TEXMFSYSVAR/web2c/fmtutil.cnf
}



prepare_dirs()
{
  $echon "Preparing destination directories... " >&2
  unset TEXMFCNF
  unset TEXMFMAIN
  test -d "$CDDIR" \
    || fatal "$CDDIR does not seem to be the TeX Live distribution!"

  work_dir=${TMP-/tmp}/.tmp_tlinst.$$
  ERRLOG=$work_dir/.errlog.$$

  trap "cd /; rm -rf $work_dir $TEXDIR/texmf/.tmp_testfile.$$;trap '' 0; exit 0" 0 1 2 15

  alldirs="$TMPDIR $TEXDIR $TEXMFSYSVAR $TEXMF $work_dir $opt_symlinks_bin $opt_symlinks_info"
  test -z "$TEXMFSYSVAR" ||
    alldirs="$alldirs $TEXMFSYSVAR/fonts/pk $TEXMFSYSVAR/fonts/tfm"
  test -z "$opt_varfonts_dir" ||
    alldirs="$alldirs $opt_varfonts_dir/pk $opt_varfonts_dir/tfm"
  for dir in $alldirs; do
    while test ! -d $dir || test ! -w $dir; do
      mkdirhier $dir
      test -d $dir || { warn "could not make directory '$dir'"; continue; }
      test -w $dir || { warn "cannot write to directory '$dir'"; continue; }
    done
  done
  test -z "$TEXMFSYSVAR" || chmod -R a+w $TEXMFSYSVAR ||
     warn "command 'chmod -R a+w $TEXMFSYSVAR' failed"
  test -z "$opt_varfonts_dir" ||
    chmod 1777 $opt_varfonts_dir/pk $opt_varfonts_dir/tfm ||
    warn "command 'chmod 1777 $opt_varfonts_dir/pk $opt_varfonts_dir/tfm' failed"

  echo "done preparing." >&2
  if test $all_systems_ns = 1; then
    cls
    textvar_show screen_6
    echo
  fi
}

make_var_skeleton ()
{
  mkdirhier $TEXMFSYSVAR/tex/generic/config
  mkdirhier $TEXMFSYSVAR/dvipdfm/config
  mkdirhier $TEXMFSYSVAR/tex/plain/config
  mkdirhier $TEXMFSYSVAR/dvips/config
  mkdirhier $TEXMFSYSVAR/fonts/map/dvipdfm/updmap
  mkdirhier $TEXMFSYSVAR/fonts/map/dvips/updmap
  mkdirhier $TEXMFSYSVAR/fonts/map/pdftex/updmap
  mkdirhier $TEXMFSYSVAR/web2c
  mkdirhier $TEXMFSYSVAR/xdvi
  mkdirhier $TEXMFSYSVAR/tex/context/config
}

make_local_skeleton ()
{
 # skeleton local hierarchy
  mkdirhier $TEXMFLOCAL/tex/latex/local
  mkdirhier $TEXMFLOCAL/tex/plain/local
  mkdirhier $TEXMFLOCAL/dvips/local
  mkdirhier $TEXMFLOCAL/bibtex/bib/local
  mkdirhier $TEXMFLOCAL/bibtex/bst/local
  mkdirhier $TEXMFLOCAL/fonts/tfm/local
  mkdirhier $TEXMFLOCAL/fonts/vf/local
  mkdirhier $TEXMFLOCAL/fonts/source/local
  mkdirhier $TEXMFLOCAL/fonts/type1/local
  mkdirhier $TEXMFLOCAL/metapost/local
  mkdirhier $TEXMFLOCAL/web2c
}


maketex_setoptfonts()
{
    test -w "$TEXMFCNF_DIR/texmf.cnf" || return
    test "$opt_varfonts" = X || return
    $echon "Setting VARFONTS in texmf.cnf... " >&2
    ed "$TEXMFCNF_DIR/texmf.cnf" >$ERRLOG 2>&1 <<eof
/^VARTEXFONTS.*=/
c
VARTEXFONTS        = $opt_varfonts_dir
.
w
q
eof
    show_error
    echo "Done setting varfonts." >&2

    mtsite=$TEXMFCNF_DIR/mktex.cnf
    chmod u+w $mtsite
    test -w "$mtsite" || return
    show_error
    $echon "Adding varfonts feature in $mtsite... " >&2
    ed "$mtsite" >$ERRLOG 2>&1 <<'eof'
/MT_FEATURES=appendonlydir/
s/dir/dir:varfonts/
w
q
eof
    show_error
    echo "Done adding varfonts." >&2
}

greetings()
{
  cat <<ENDG

See ./index.html for links to documentation.
The 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.

Welcome to TeX Live!

ENDG
}

opt_do_symlinks()
{
  test "$opt_symlinks" = X || return

  $echon 'Creating symbolic links...'
  texdocdir=$TEXDIR/texmf/doc
  
  # Dynamically see which man sections we have.
  mans=`(cd $texdocdir/man && echo *)`
  test -z "$mans" && return  # unlikely but possible
  #
  for m in $mans; do
    mandir=$texdocdir/man/$m
    test -d $mandir || continue  # in case a README or something sneaks in.

    mkdirhier $opt_symlinks_man/$m
    test ! -w $opt_symlinks_man/$m && continue
    
    $echon " $m"
    cd $opt_symlinks_man/$m || continue
    rm -f `ls $mandir`
    ln -s $mandir/* .
  done

  # no subdirs for info.
  infodir=$texdocdir/info
  if test -w "$opt_symlinks_info"; then
    $echon " info"
    if cd $opt_symlinks_info; then
      rm -f `ls $infodir`
      ln -s $infodir/*info* .
    fi
  fi

  this_platform_bin=
  if test -x $TEXDIR/bin/tex; then
    this_platform_bin=$TEXDIR/bin
  elif test -x $TEXDIR/bin/$this_platform_fn/tex; then
    this_platform_bin=$TEXDIR/bin/$this_platform_fn
  fi
  if test -n "$this_platform_bin"; then
    $echon " binaries"
    $debug && echo " (target $this_platform_bin)"
    if cd $opt_symlinks_bin; then
      rm -f `ls $this_platform_bin`
      ln -s $this_platform_bin/* .
    fi
  fi

  echo ' ... done linking.'
}

################################################################
# menus:
################################################################
menu_main()
{
    while true; do
        cls
        opt_savespace_man=X
        echo; textvar_show screen_1; echo
        case `getopt BCSDLOIHPQR 'Enter command'` in
          C) menu_series_customize;;
          L) menu_lang_series_customize;;
          D) menu_directories;;
          H) helpme help_1;;
          I) install_now;;
          O) menu_options;;
          P) menu_this_platform;;
          Q) exit_on_confirm;;
          R) install_cd;;
          B) select_platforms;;
          S) menu_schemes;;
        esac
    done
}


# NEW PLATFORM: change getopt call and add a new case.
menu_this_platform()
{
    while true; do
        cls
        textvar_show screen_5; echo
      case `getopt NABCDEFGHIJKLMRQ 'Select the platform you are currently on'` in
          N) this_system=''; this_platform_set ;;
          A) this_system=i386_linux; this_platform_set ;;
          B) this_system=win32; this_platform_set ;;
          C) this_system=powerpc_darwin; this_platform_set ;;
          D) this_system=i386_darwin; this_platform_set ;;
          E) this_system=alpha_linux; this_platform_set ;;
          F) this_system=mips_irix; this_platform_set ;;
          G) this_system=powerpc_aix; this_platform_set ;;
          H) this_system=sparc_solaris; this_platform_set ;;
          I) this_system=i386_solaris; this_platform_set ;;
          J) this_system=i386_freebsd; this_platform_set ;;
          K) this_system=i386_cygwin; this_platform_set ;;
          L) this_system=x86_64_linux; this_platform_set ;;
          M) this_system=sparc_linux; this_platform_set ;;
          # N above
          R) total_stat; return ;;
          Q) exit_on_confirm ;;
        esac
    done
}


# This run for scheme selection <S>.
menu_schemes()
{
    while true; do
        cls
        for i in $all_schemes
	do 
	    eval key=\"\$schemes_${i}_ident\"
	    eval name=\"\$schemes_${i}_n\"
	    echo $key $name
	done | pr -t -2 - 
        echo
        echo Current scheme is [$selected_scheme].
        echo "[Collections: $selected_collections]" | sed 's/tex_//g' | fmt
        echo "[Packages: $selected_packages]"       | sed 's/tex_//g' | fmt
        echo
        echo '    Press <R> to return to main menu, <Q> to quit'
        K=`getopt ABCDEFGHIJKLMNOPQRSTUVWXYZ '      or press key to select a scheme'`
        case $K in 
          R) total_stat; return ;;
          Q) exit_on_confirm;;
          *) eval W=\"\$SCHEMES_${K}\"
	     selected_scheme=$W
	     scheme_select $W
	     total_stat; return;;
        esac
    done
}

menu_series_customize()
{
    while true; do
        cls
        for i in $all_collections 
	do 
	    eval status=\"\$p_${i}_level\"
	    eval key=\"\$p_${i}_ident\"
	    eval name=\"\$p_${i}_n\"
	    echo $key $status $name
	done | pr -t -3 -
        textvar_show screen_customize; echo
        K=`getoptallcase -+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@ 'Press key to toggle status of collection'`
        case $K in 
          +) series_allall;;
          -) series_allnone;;
          R)  total_stat; return ;;
          Q) exit_on_confirm;;
          r)  total_stat; return ;;
          q) exit_on_confirm;;
          *) eval W=\"\$P_${K}\"
             series_select_level $W 2; 
        esac
    done
}

menu_lang_series_customize()
{
    while true; do
        cls
        for i in $all_lang_collections 
	do 
	    eval status=\"\$p_${i}_level\"
	    eval key=\"\$p_${i}_ident\"
	    eval name=\"\$p_${i}_n\"
	    echo $key $status $name
	done | pr -t -2 -
        textvar_show screen_customize; echo
        K=`getoptallcase -+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@ 'Press key to toggle status of collection'`
        case $K in 
          +) series_lang_allall;;
          -) series_lang_allnone;;
          R)  total_stat; return ;;
          Q) exit_on_confirm;;
          r)  total_stat; return ;;
          q) exit_on_confirm;;
          *) eval W=\"\$LP_${K}\"
             series_select_level $W 2; 
        esac
    done
}


menu_directories()
{
    while true; do
        cls
        textvar_show screen_2; echo
        case `getopt 1234RQ 'Enter command'` in
          1) gets TEXDIR
	     LOCAL_CHANGE=2
             TEXDIR=`dirname "$TEXDIR/x" | sed 's@//*@/@g'`
             TEXMF=`echo $TEXDIR/texmf | sed 's@//*@/@g'`
	     TEXMFLOCAL=`echo $TEXDIR/texmf-local` 
	     TEXMFSYSVAR=`echo $TEXDIR/texmf-var`
	     ;;
          2) gets TEXMFLOCAL
             LOCAL_CHANGE=1
             TEXMFLOCAL=`dirname "$TEXMFLOCAL/x" | sed 's@//*@/@g'`
             ;;
          3) gets TEXMFSYSVAR
             VAR_CHANGE=1
             TEXMFSYSVAR=`dirname "$TEXMFSYSVAR/x" | sed 's@//*@/@g'`
             ;;
          4) gets TEXMFHOME
             HOME_CHANGE=1
             TEXMFHOME=`dirname "$TEXMFHOME/x" | sed 's@//*@/@g'` ;;
          R) return;;
          Q) exit_on_confirm;;
        esac
    done
}

menu_options()
{
    while true; do
        cls
        textvar_show screen_3; echo
        case `getopt ADFLRSQ 'Enter command'` in
          A) toggle opt_varfonts
             if test "$opt_varfonts" = X; then
               cls; textvar_show screen_3; echo
               opt_varfonts_dir=$opt_varfonts_dir_last
               test -z "$opt_varfonts_dir" && opt_varfonts_dir=/tmp/texfonts
               gets opt_varfonts_dir 'alternate directory'
             else
               opt_varfonts_dir_last=$opt_varfonts_dir
               opt_varfonts_dir=''
             fi
             ;;
          S) toggle opt_source
             if test "$opt_source" = X; then
               cls; textvar_show screen_3; echo
             fi
             ;;
          D) toggle opt_doc
             if test "$opt_doc" = X; then
               cls; textvar_show screen_3; echo
             fi
             ;;
          L) toggle opt_symlinks
             if test "$opt_symlinks" = X; then
               cls; textvar_show screen_3; echo
               opt_symlinks_bin=$opt_symlinks_bin_last
               test -z "$opt_symlinks_bin" && opt_symlinks_bin=/usr/bin
               gets opt_symlinks_bin 'binary directory'
               opt_symlinks_man=$opt_symlinks_man_last
               test -z "$opt_symlinks_man" && opt_symlinks_man=`dirname $opt_symlinks_bin`/man
               gets opt_symlinks_man 'man directory   '
               opt_symlinks_info=$opt_symlinks_info_last
               test -z "$opt_symlinks_info" && opt_symlinks_info=`dirname $opt_symlinks_bin`/info
               gets opt_symlinks_info 'info directory  '
             else
               opt_symlinks_bin_last=$opt_symlinks_bin
               opt_symlinks_man_last=$opt_symlinks_man
               opt_symlinks_info_last=$opt_symlinks_info
               opt_symlinks_bin=''; opt_symlinks_man=''; opt_symlinks_info=''
             fi
             ;;
          R) return;;
          Q) exit_on_confirm;;
        esac
    done
}

exit_on_confirm()
{
    cls
    yesno 'Really quit' && exit
}

################################################################
# global variables
################################################################
: ${PAGER=more}
envvars='
BIBINPUTS BSTINPUTS DVIPSHEADERS GFFONTS GLYPHFONTS MFBASES MFINPUTS
MFPOOL PKFONTS TEXCONFIG TEXFONTS TEXFORMATS TEXINPUTS TEXMFCNF TEXPICTS
TEXPKS TEXPOOL TFMFONTS VFFONTS DVIPSFONTS XDVIVFS XDVIFONTS DVILJFONTS
'
TARPROG=tar
TAROPT=""
varprefix='/var'
usrprefix='/usr'
opt_varfonts=' '
opt_vartexmf=' '
opt_source=' '
opt_doc=' '
opt_varfonts_dir=''
opt_vartexmf_dir=''
opt_varfonts_dir_last=''
opt_vartexmf_dir_last=''
opt_symlinks=' '
opt_symlinks_bin=''
opt_symlinks_man=''
opt_symlinks_info=''
opt_symlinks_bin_last=''
opt_symlinks_man_last=''
opt_symlinks_info_last=''

this_platform=

################################################################
# screens:
################################################################

screen_2='Current directories setup:
==============================================================================

  <1>  TEXDIR:       $TEXDIR
       support tree: $TEXMF

  <2>  TEXMFLOCAL:   $TEXMFLOCAL
  <3>  TEXMFSYSVAR:  $TEXMFSYSVAR
  <4>  TEXMFHOME:    $TEXMFHOME

Other options:
==============================================================================
  <R>   return to main menu
  <Q>   quit
'

screen_3='Current options setup:
==============================================================================

  <A>  alternate directory for automatically generated fonts: [$opt_varfonts]
         directory name: $opt_varfonts_dir
  <L>  create symlinks in standard directories:               [$opt_symlinks]
            binaries to: $opt_symlinks_bin
            manpages to: $opt_symlinks_man
                info to: $opt_symlinks_info
  <D>  do not install font/macro doc tree: [$opt_doc]
  <S>  do not install font/macro source tree: [$opt_source]

Other options:
==============================================================================
  <R>   return to main menu
  <Q>   quit
'

screen_5='Current platform: $this_platform_n
==============================================================================
  <N>  none of the entries below
  <A> $p_i386_linux_n
  <B> $p_win32_n
  <C> $p_powerpc_darwin_n
  <D> $p_i386_darwin_n
  <E> $p_alpha_linux_n
  <F> $p_mips_irix_n
  <G> $p_powerpc_aix_n
  <H> $p_sparc_solaris_n
  <I> $p_i386_solaris_n
  <J> $p_i386_freebsd_n
  <K> $p_i386_cygwin_n
  <L> $p_x86_64_linux_n
  <M> $p_sparc_linux_n

  <R>   return to main menu
  <Q>   quit
'


screen_6='TeX Live can be used on multiple systems
as a separate subdirectory is used for each
installed binary package in $TEXDIR/bin.'

screen_customize='
  <-> deselect all  <+> select all  <R> return to main menu  <Q> quit
'

system_screen='System setup section
==============================================================================
Current selection: $all_systems_ns out of $all_systems_anz

==============================================================================
  <R>   return to platform menu
  <Q>   quit
'

help_1='
This is the installation program of the TeX Live distribution.

The installation procedure is simple: just go through the
menus until you are happy with the way all options are set up,
and then do <I> (start installation).

To select a menu item (a letter or a number marked with brackets)
just enter the corresponding letter or number and press return
(the letters are case insensitive except when collections
are being selected). Do not enter the 
angle brackets <> themselves.

We will now consider each menu item in more detail:

======================================================================
  The collections menu (<C>)
======================================================================

The collections menu allows you to select and deselect standard
collections. Each collection --- TeX macro files, Metafont font
families, and so on --- consists of several packages.

======================================================================
  The language collections menu (<L>)
======================================================================

The language collections menu allows you to select and deselect
language support collections. Each collection consists of several
packages, which provide features like hyphenation files and fonts.

======================================================================
  The binary systems menu (<B>)
======================================================================

The systems menu allows you to select and deselect 
the binary packages for various different platforms.

======================================================================
  The directories menu (<D>)
======================================================================

The TeX Live distribution will be installed in a single directory tree
(TEXDIR). You may choose any directory you like
since there are no absolute paths compiled into the binaries. Instead,
the Kpathsea library selfdir feature ensures that all
paths are relative to the location of the binaries.

The platform independent files are stored in a directory tree in
TEXDIR/texmf. There is also an extra directory for performing
administrative tasks like change of configuration and languages. This
is where all format files are stored. It defaults to TEXDIR/texmf-var.

This system allows you to mount your
TEXDIR/texmf tree read-only.

======================================================================
  The options menu (<O>)
======================================================================

The options are not applicable to all installations.  Set them as
appropriate for yours.

======================================================================
  The schemes menu (<S>)
======================================================================

You can choose from a number of different installation
schemes for TeX Live. Selecting one of these selects
some collections in the Collections and Languages lists.
which you can subsequently modify.

"alternate fonts directory":
============================

You can choose an alternate directory for automatically generated fonts;
the default is TEXMFSYSVAR/fonts

One disadvantage may be that new fonts are not shared.  I.e., if you
set this to /tmp, and users on two different machines need the same
font, it will be built twice, once on each machine.

"symlinks in standard directories"
==================================

You can make the binaries, man pages, and info files available on your
system in either (or both) of two ways:
  1) install them in "standard places" that are searched for these files
  2) change your search paths to include the new directories

If you select the "symlinks" option, symbolic links will be installed in
the directories you choose. Note that if you share the TeX Live installation
accross several machines across NFS and if the chosen "standard places" are
not shared, you need to create the symbolic links on each client, too
(or use method 2 on your clients).

If you do not use the "symlinks" option, you probably need to set up
your search paths (PATH, MANPATH, INFOPATH).

"do not install doc or source trees"
====================================
These options are not recommended, but you can use them to save space. 
Normally all packages are installed with the source and/or documentation,
but these are not needed to actually run the software. If you
are installing a system for other people, it would be unfriendly to
select these options; if you know what you are doing and need a
minimal disk footprint, go ahead


======================================================================
  Other commands (<I>, <H>, <R> and <Q>
======================================================================

Well, this is easy to explain:
  <R> does not install the system, but sets you to run off the CD
  <I> starts the installation after you are happy with the setup
  <H> displays this help
  <Q> quits the installation program
'

init()
{
  #$debug && set -x
  echo "Welcome to TeX Live installation. (`date`)"; echo
  locate_binaries
  bad_sh
  find_echo
  find_tar
  series_init
  bindir=
  tex_prefix=${TEXLIVE_INSTALL_PREFIX-/usr/local/texlive}
  TEXDIR=${TEXLIVE_INSTALL_TEXDIR-$tex_prefix/2006}  # manually update each year!
  TEXMFSYSVAR=${TEXLIVE_INSTALL_TEXMFSYSVAR-$TEXDIR/texmf-var}
  TEXMF=$TEXDIR/texmf
  TEXMFLOCAL=${TEXLIVE_INSTALL_TEXMFLOCAL-$tex_prefix/texmf-local}
  TEXMFHOME=${TEXLIVE_INSTALL_TEXMFHOME-'$HOME/texmf'}
  VAR_CHANGE=""
  LOCAL_CHANGE=""
  HOME_CHANGE=""

screen_1=' ===================> TeX Live installation procedure <==================

===> Note: Letters/digits in <angle brackets> indicate menu items <===
===>       for commands or configurable options                   <===

    Proposed platform: $this_platform_n
    <P> override system detection and choose platform
    <B> binary systems:        $all_systems_ns out of $all_systems_anz
    <S> Installation scheme ($selected_scheme)
        [to customize within installation scheme:
         <C> standard collections   <L> language collections]
    $all_collections_ns out of $all_collections_anz, disk space required: $all_collections_dus kB
    <D> directories:
      TEXDIR      (main TeX directory):     $TEXDIR     
      TEXMFSYSVAR (systemwide config):      $TEXMFSYSVAR
      TEXMFLOCAL  (systemwide styles etc.): $TEXMFLOCAL
      TEXMFHOME   (personal styles etc.):   $TEXMFHOME
    <O> options:
       [$opt_varfonts] alternate directory for generated fonts ($opt_varfonts_dir)
       [$opt_symlinks] create symlinks in standard directories
       [$opt_doc] do not install macro/font doc tree
       [$opt_source] do not install macro/font source tree
    <R> do not install files, set up to run off CD or DVD
    <I> start installation
    <H> help,  <Q> quit
'

}

list_zipped_files()
{
  col=`echo $1 | sed 's/_/-/g'`
  $debug && echo "          -> collection $col" >&2
    morecols=`grep -- "^-" $LISTS/$col | sed 's/.//'`
    packages=`grep "^+"    $LISTS/$col | sed 's/.//'`
    :>$work_dir/tmp.text
    :>$work_dir/$col.jobs
    echo "$col.zip" >> $work_dir/tmp.text
    eval sort < $LISTS/$col | grep '^\!' | tr ' ' '=' >> $work_dir/$col.jobs
    if  test "x$packages" != "x"
    then
      for i in $packages 
      do
        expand_package $i $col
      done
    fi
  eval sort -u $work_dir/tmp.text >> $work_dir/$col.list.text


  rm $work_dir/tmp.text 

  if test "x$morecols" != "x"
  then
  for p in $morecols
  do
      list_zipped_files $p
  done
  fi

}

expand_package ()
{
  pack=$1
  col=$2
  $debug && echo "      expand package $pack"  >&2
  echo "$pack.zip" >> $work_dir/tmp.text
  eval sort < $LISTS/$pack | grep '^\!' | tr ' ' '=' >> $work_dir/$col.jobs
  more=`grep "^+" $LISTS/$pack | sed 's/.//'`
  if test "x$more" != "x"
  then
  for i in $more
   do
    expand_package $i $col
   done
  fi
}


# at the beginning of the end ... called at the beginning of install_new.
# the caller must set list_file_func and list_package_func.
# 
common_start_install()
{
  prepare_dirs
  make_local_skeleton
  make_var_skeleton

  skip_systemstuff=false
  TEXMFCNF_DIR=$TEXDIR/texmf/web2c
  test -f $TEXMFCNF_DIR/texmf.cnf && skip_systemstuff=true

  # 
  cat >$TEXMFSYSVAR/web2c/updmap.cfg <<OAF
# created during TeX Live installation, `date`.
################################################################
# OPTIONS
################################################################
#
# dvipsPreferOutline
#
# Should dvips (by default) prefer bitmap fonts or outline fonts
# if both are available? Independent of this setting, outlines
# can be forced by putting "p psfonts_t1.map" into a config file
# that dvips reads. Bitmaps (for the fonts in question) can
# be forced by putting "p psfonts_pk.map" into a config file.
# We provide such config files which can be enabled via
# dvips -Poutline ... resp. dvips -Ppk ...
#
# Valid settings for dvipsPreferOutline are true / false:
dvipsPreferOutline true

#
# LW35
#
# Which fonts for the "Basic 35 Laserwriter Fonts" do you want to use and
# how are the filenames chosen? Valid settings:
#   URW:     URW fonts with "vendor" filenames (e.g. n019064l.pfb)
#   URWkb:   URW fonts with "berry" filenames (e.g. uhvbo8ac.pfb)
#   ADOBE:   Adobe fonts with "vendor" filenames (e.g. hvnbo___.pfb)
#   ADOBEkb: Adobe fonts with  "berry" filenames (e.g. phvbo8an.pfb)
LW35 URWkb

#
# dvipsDownloadBase35
# 
# Should dvips (by default) download the standard 35 LaserWriter fonts
# with the document (then set dvipsDownloadBase35 true) or should these
# fonts be used from the ps interpreter / printer?
# Whatever the default is, the user can override it by specifying
# dvips -Pdownload35 ... resp. dvips -Pbuiltin35 ... to either download
# the LW35 fonts resp. use the built-in fonts.
#
# Valid settings are true / false:
dvipsDownloadBase35 false

#
# pdftexDownloadBase14
#
# Should pdftex download the base 14 pdf fonts? Since some configurations
# (ps / pdf tools / printers) use bad default fonts, it is safer to download
# the fonts. The pdf files will get bigger, though.
# Valid settings are true (download the fonts) or false (don't download
# the fonts). Adobe recomments to embed all fonts.
pdftexDownloadBase14 true

#
# dvipdfmDownloadBase14
#
# Should dvipdfm download the base 14 pdf fonts? Since some configurations
# (ps / pdf tools / printers) use bad default fonts, it is safer to download
# the fonts. The pdf files will get bigger, though.
# Valid settings are true (download the fonts) or false (don't download
# the fonts).
dvipdfmDownloadBase14 true

################################################################
# Map files.
################################################################
#
# There are two possible entries: Map and MixedMap. Both have one additional
# argument: the filename of the map file. MixedMap ("mixed" means that
# the font is available as bitmap and as outline) lines will not be used
# in the default map of dvips if dvipsPreferOutline is false. Inactive
# Map files should be marked by "#! " (without the quotes), not just #.
#
# (comments on a few map files from the teTeX updmap.cfg; for TeX Live,
# the actual Map lines are created during installation.)
# 
# AntykwaPoltawskiego; CTAN:fonts/psfonts/polish/antp/
# 
# AntykwaTorunska; CTAN:fonts/antt/
# 
# "quasi" fonts derived from URW and enhanced (from the Polish TeX users);
# CTAN:fonts/psfonts/polish/qfonts/
# 
# Bitstream Charter text font
#
# Computer Modern fonts extended with Russian letters;
# CTAN:fonts/cyrillic/cmcyr/
# 
# symbols for ConTeXt macro package
#
# latin modern; CTAN:fonts/lm.
#
# a symbol font; CTAN:fonts/psfonts/marvosym/
#
# two font map entries for the mathpple package
#
# for Omega
#
# the pazo fonts; CTAN:fonts/mathpazo
#
# pxfonts (palatino extension); CTAN:fonts/pxfonts
#
# txfonts (times extension); CTAN:fonts/txfonts
#
# XY-pic fonts; CTAN:macros/generic/diagrams/xypic
#
# 7-8-9 sizes for cmex taken from TeXtrace2001 different implementation
# for font entries found in ams-cmex-bsr-interpolated.map and
# cmother-bsr-interpolated.map.
#
# ps-type1 versions for ams; CTAN:fonts/amsfonts/ps-type1
#
# ps-type1 versions for cm; CTAN:fonts/cm/ps-type1/bluesky
#
# CSTeX; http://math.feld.cvut.cz/olsak/cstex/
#
# mf -> type1 converted fonts by Taco Hoekwater
#
# Polish version of Computer Modern; CTAN:language/polish/plpsfont
#
# Polish version of Computer Concrete; CTAN:fonts/psfonts/polish/cc-pl
#
# See comments in doc/fonts/belleek/README about using mt-belleek.map
# instead of mt-yy.map:
#
# Euro Symbol fonts by Henrik Theiling; CTAN:fonts/eurosym
#
# vntex support, see http://vntex.org/
#
# Doublestroke, based on Knuth's Computer Modern Roman; CTAN:fonts/doublestroke
#
# FPL, free substitutes for the commercial Palatino SC/OsF fonts
# are available from CTAN:fonts/fpl; used by psnfss 9.2.
OAF
  (
    echo "Preparing list of files to be installed..." >&2
    $debug && echo "debug:for selected systems:" >&2
    for p in $all_systems; do
      $debug && echo "debug: checking system $p_${p}_s..."
      eval \$p_${p}_s || continue
      eval name=\"\$p_${p}_n\"
      echo "  $name" >&2
    done
    echo >&2

    $debug && echo "debug:for selected collections:" >&2
    for p in $all_collections; do
      $debug && echo "debug: checking coll $p_${p}_s..."
      eval \$p_${p}_s || continue
      eval name=\"\$p_${p}_n\"
      echo "  $name ">&2
      $list_file_func $p
    done
    echo >&2
    
    $debug && echo "debug:for selected language collections:" >&2
    for p in $all_lang_collections; do
      $debug && echo "debug: checking lang coll $p_${p}_s..."
      eval \$p_${p}_s || continue
      eval name=\"\$p_${p}_n\"
      echo "  $name ">&2
      $list_file_func $p
    done

    # e.g., GUST scheme depends on some individual packages, not just
    # collections.  Write info for those to a special .list file.
    # (Ignored for compressed installation.)
    $debug && echo "debug:for selected packages:" >&2
    :>$work_dir/PKGONLY.list
    for p in $selected_packages; do
      $list_package_func $p PKGONLY
    done
  )
}


# at the end of the end ... this routine does not return.
# 
common_end_install()
{
  test -n "$platform_subdir_strip_d" && rm -f $TEXDIR/bin/$platform_subdir_strip_d 2>/dev/null

  if test "x$TEXMF" != "x$TEXDIR/texmf"; then
    $echon "Fixing permissions in $TEXMF... " >&2
    chmod -R a+r,u+w,go-w $TEXMF 2>/dev/null
    rm -f $TEXDIR/texmf
    echo "done." >&2
  fi
  $echon "Fixing permissions in $TEXDIR... " >&2
  chmod -R a+r,u+w,go-w $TEXDIR 2>/dev/null
  test -z "$TEXMFSYSVAR" ||
    chmod -R a+w $TEXMFSYSVAR ||
     warn "command 'chmod 1777 $TEXMFSYSVAR' failed"
  echo "done." >&2

  if test "$opt_varfonts" = X; then
     $echon "$opt_varfonts_dir will be used for font creation... " >&2
  else
    $echon "Setting up directories for automatic font creation... " >&2
    find "$TEXMF/fonts/pk" "$TEXMF/fonts/tfm" "$TEXMF/fonts/source/jknappen" -type d \
      -print 2>/dev/null | $XARGS chmod 1777 2>/dev/null
  fi
  find "$TEXMF/fonts/source/jknappen" -type d -print 2>/dev/null | $XARGS chmod 1777 2>/dev/null
  echo "done." >&2

  $skip_systemstuff || maketex_setoptfonts
  $skip_systemstuff || TEXMFCNF__fix_fmtutil
  $skip_systemstuff || TEXMFCNF__fix_texmf
  pd=$this_platform_fn
  bindir=
  have_system=false
  echo Testing for $TEXDIR/bin/$pd/texconfig....  >&2
  if test -x $TEXDIR/bin/$pd/texconfig; then
    have_system=true
    bindir=$TEXDIR/bin/$pd
  elif test -x $TEXDIR/bin/texconfig; then
    have_system=true
    bindir=$TEXDIR/bin
  fi
  $skip_systemstuff && have_system=false
  $skip_systemstuff || opt_do_symlinks
  $skip_systemstuff && echo "System updated successfully."  >&2
  if $have_system; then
    runsetup
    echo
    echo "Add $bindir" >&2
    echo "  to your PATH for current and future sessions." >&2
    echo 
    echo "Add $TEXDIR/texmf/doc/man to MANPATH." >&2
    echo "Add $TEXDIR/texmf/doc/info to INFOPATH." >&2
    
    if test "$pd" = i386-solaris; then
      # we should do this if i386-solaris is installed, not just if it's
      # the current platform, but that seems pretty painful.
      echo
      echo "For i386-solaris, you must also install extra libraries:"
      echo "  gzip -d <support/i386-solaris-libs.pkg.gz >/tmp/tlibs.pkg"
      echo "  pkgadd -d /tmp/tlibs.pkg"
      echo "(or the equivalent.)"
      echo
    fi
  fi

  $skip_systemstuff || greetings

  if $skip_systemstuff; then
   echo Since $TEXMFCNF_DIR/texmf.cnf already existed,
   echo we have not touched modified anything in that directory.
   echo Please review your setup.
  fi
  exit
}


# called from runsetup.
# 
post_install_jobs ()
{
 $debug && echo "debug:do post_install_jobs " >&2
 for j in `sort -u $work_dir/*.jobs`
  do
    command=`echo $j | sed 's/.\(.*\)=.*/\1/'`
    parameter=`echo $j | sed 's/.*=\(.*\)/\1/'`
    echo "   EXECUTE $j: $command on $parameter" >&2
    case $command in
        addMap)
	    echo "Map $parameter" >> $TEXMFSYSVAR/web2c/updmap.cfg;;
        addMixedMap)
	    echo "MixedMap $parameter" >> $TEXMFSYSVAR/web2c/updmap.cfg;;
        addDvipsMap)
	    echo "p +$parameter" >> $TEXMFSYSVAR/dvips/config/config.ps;;
        addDvipdfmMap)
	    test -f $TEXMFSYSVAR/dvipdfm/config/config && echo "f $parameter" >> $TEXMFSYSVAR/dvipdfm/config/config;
	    ;;
    esac
done
}


# subroutine called from common_end_setup.
# 
runsetup()
{
  PATH=$bindir:/bin:/usr/bin
  export PATH
  if test -f $TEXMFSYSVAR/tex/generic/config/language.dat
  then
   echo Using language.dat from TeX Live distribution.  >&2
  else
   echo Making language.dat in $TEXMFSYSVAR/tex/generic/config  >&2
   echo " from your language selections..."  >&2
   # if lang.dat's installed (basic scheme), don't mention missing files.
   langsel=$TEXDIR/texmf/tex/generic/config/language.*.dat
   test -n "`ls $langsel 2>/dev/null`" || langsel=
   mkdirhier $TEXMFSYSVAR/tex/generic/config
   cat $TEXDIR/texmf/tex/generic/config/language.us $langsel \
      >$TEXMFSYSVAR/tex/generic/config/language.dat 
  fi

  # Update ls-R before running texconfig, or modes.mf et al. may not be found.
  echo Updating filename database with mktexlsr... >&2
  $bindir/mktexlsr

  echo "Doing post-install jobs from the packages..."
  post_install_jobs

  echo "Making map files for dvips, pdftex, dvipdfm with updmap..." >&2
  $bindir/updmap-sys --nohash --quiet \
    --cnffile=$TEXMFSYSVAR/web2c/updmap.cfg \
    --dvipsoutputdir=$TEXMFSYSVAR/fonts/map/dvips/updmap \
    --dvipdfmoutputdir=$TEXMFSYSVAR/fonts/map/dvipdfm/updmap \
    --pdftexoutputdir=$TEXMFSYSVAR/fonts/map/pdftex/updmap

  echo "Re-updating filename database with mktexlsr..." >&2
  $bindir/mktexlsr

  cat <<ENDC

=========================
Installation is finished.  (`date`)

For future global configuration, edit files in $TEXMFSYSVAR
(or run texconfig or texconfig-sys).

ENDC
}