]> git.donarmstrong.com Git - lilypond.git/blob - debian/postinst
release: 0.1.36
[lilypond.git] / debian / postinst
1 #!/usr/bin/perl -w
2 #
3 # postinst script for the Debian GNU/Linux lilypond package
4 #
5 #   by Anthony Fok <foka@debian.org>
6 #   Initial release:  Sun, 26 Oct 1997 03:23:00 -0700
7 #     Last modified:  Sun, 23 Nov 1997 03:04:16 -0700
8
9 use strict;
10 use File::Copy;
11
12 my ($package, $pkg_name, $font_supplier, $font_typeface, $std_TEXMF, $TEXMF,
13     $TEXINPUTS, $MFINPUTS, $TFMFONTS, @fonts);
14
15 sub correct_opus_fonts ($$);
16 sub check_texmfcnf ();
17 sub run_texhash ();
18 sub add_fonts ($$$$@);
19 sub check_specialmap ();
20
21 $| = 1;
22
23
24 #######################
25 # Variables  
26 #######################
27
28 $package = "lilypond";          # This is used for filenames!  Don't change it!
29 $pkg_name = "GNU LilyPond";
30
31 $font_supplier = "public";
32 $font_typeface = "lilypond";
33 @fonts = qw( feta );
34
35 $std_TEXMF = "/usr/lib/texmf";  # Debian's standard $TEXMF
36 $TEXINPUTS = "$std_TEXMF/tex/$package//";
37 $MFINPUTS = "$std_TEXMF/fonts/source/$font_supplier/$font_typeface//";
38 $TFMFONTS = "$std_TEXMF/fonts/tfm/$font_supplier/$font_typeface//";
39
40
41 #######################
42 # Subroutine
43 #######################
44
45 #----- Fix Opus font entries in special.map (called by check_specialmap()) ---
46 #  I goofed up the Opus font entries in special.map, hence this fix.
47 #  Note: This is a temporary fix.  Consider removing this in 1998.  ^_^
48
49 sub correct_opus_fonts ($$) {
50     my $specialmap = $_[1];
51     my $supplier = "opustex";
52     my $typeface = "opus";
53     my @opusfonts = qw( opus opusline opusnum opussps osl );
54     my $font = "";
55     my $entries = "";
56
57     if ($_[0] =~ /(^\w+\s+public\s+$typeface\n)+/m) {
58         print " Correcting old font entries ...";
59         foreach $font (@opusfonts) {
60             if (length($font) < 8) { $font .= "\t"; }
61             $entries .= "$font\t$supplier\t\t$typeface\n";
62         }
63
64         ($_[0] =~ s/(^\w+\s+public\s+$typeface\n)+/$entries/m)
65             or die " Can't correct font entries in $specialmap: $!";
66
67         system(": \${MAKETEXDIR=$TEXMF/maketex}; " .
68                "test -r \$MAKETEXDIR/maketex.site && . \$MAKETEXDIR/maketex.site; " .
69                ": \${MT_DESTROOT=$TEXMF/fonts}; " .
70                "rm -rf \$MT_DESTROOT/pk/*/public/$typeface");
71
72         print "\n";
73         return 1;
74     } else {
75         return 0;
76     }
77 }
78
79 #-------------------- Check/Modify texmf.cnf for custom teTeX installation ---
80 #  Edit texmf.cnf to add search path /usr/lib/texmf
81 #  for non-Debian teTeX installation
82
83 sub check_texmfcnf () {
84     my $texmfcnf;
85
86     print "\n You have a custom teTeX installation in $TEXMF.\n";
87
88     chop($texmfcnf = `kpsewhich cnf texmf.cnf`);
89
90     if ($? == 0 and $texmfcnf ne "") {
91         my($filebuf, $line);
92         my $new = "$texmfcnf.new";
93         my $bak = "$texmfcnf.bak";
94
95         open(OLD, "< $texmfcnf") or die " Can't open $texmfcnf for reading: $!";
96
97         undef $/;
98         if ($filebuf = <OLD>) {
99             if ($filebuf =~ /^(TEXMFL.*)$/m) {
100                 $line = $1;
101                 if ($line =~ /TEXMFL\s*=.*$std_TEXMF/) {
102                     print " Found $std_TEXMF in \$TEXMFL.  Leaving $texmfcnf untouched.\n";
103                 } else {
104                     print " Adding $std_TEXMF to \$TEXMFL, updating $texmfcnf ...";
105
106                     $filebuf =~ s/^(TEXMFL\s*=\s*\S*)/$1,$std_TEXMF/m;
107                     open(NEW, "> $new")  or die "\n Can't open $new for writing: $!";
108                     (print NEW $filebuf) or die "\n Can't write to $new: $!";
109                     close(NEW);
110                     copy($texmfcnf, $bak) or die "\n Can't backup $texmfcnf: $!";
111                     rename($new, $texmfcnf)
112                         or ( copy($new, $texmfcnf), unlink($new) )
113                         or die "\n Can't update $texmfcnf: $!";
114                     print " done.\n";
115                 }
116             }
117         } else {
118             warn " **\n";
119             warn " ** Can't read from $texmfcnf: $!\n";
120             warn " ** Please verify the content of $texmfcnf!\n";
121             warn " **\n";
122         }
123         $/ = "\n";
124         close(OLD);
125     } else {
126         warn " **\n";
127         warn " ** Can't find texmf.cnf!\n";
128         warn " ** Please add $std_TEXMF to \$TEXMFL in your texmf.cnf.\n";
129         warn " **\n";
130     }
131 }
132
133 #------------------------------------------------------------- Run texhash ---
134
135 sub run_texhash () {
136     print " Running texhash to update $TEXMF/ls-R ...\n";
137
138     if ( `which texhash` and -e "$TEXMF/ls-R" ) {
139         system("texhash");
140     } else {
141         warn " Error: texhash or $TEXMF/ls-R not found!\n";
142     }
143     print "\n";
144 }
145
146 #---------- Add font entries to special.map (called by check_specialmap()) ---
147
148 sub add_fonts ($$$$@) {
149     my ($specialmap, $supplier, $typeface, $fonts) = @_[1..4];
150     my $font = "";
151     my $entries = "";
152     foreach $font (@fonts) {
153         if (length($font) < 8) { $font .= "\t"; }
154         $entries .= "$font\t$supplier\t\t$typeface\n";
155     }
156
157     $_[0] =~ /((^\w+\s+$supplier\s+$typeface\n)+)/m;
158
159     if ($1 ne $entries) {
160         ($_[0] =~ s/(^\w+\s+$supplier\s+$typeface\n)+/$entries/m)
161             or ($_[0] =~ s/(?=^beam\s+public\s+music\n)/$entries/m)
162             or die " Can't add font entries to $specialmap: $!";
163         return 1;
164     } else {
165         return 0;
166     }
167 }
168
169 #---------------------------------- Check special.map and add font entries ---
170
171 sub check_specialmap () {
172     my $fontmap;
173     my $specialmap = "$TEXMF/fontname/special.map";
174     my $new = "$specialmap.new";
175     my $bak = "$specialmap.bak";
176
177     print " Checking font entries in $specialmap ...\n";
178
179     open(OLD, "< $specialmap")  or die " Can't open $specialmap for reading: $!";
180     undef $/;
181     if ($fontmap = <OLD>) {
182         if (correct_opus_fonts($fontmap, $specialmap) |
183             add_fonts($fontmap, $specialmap, $font_supplier, $font_typeface, @fonts))
184         {
185             print " Adding $pkg_name font entries to $specialmap ...\n";
186             open(NEW, "> $new")      or die " Can't open $new for writing: $!";
187             (print NEW $fontmap)     or die " Can't write to $new: $!";
188             close(NEW);
189             copy($specialmap, $bak)  or die " Can't backup $specialmap: $!";
190             rename($new, $specialmap)
191                 or ( copy($new, $specialmap), unlink($new) )
192                 or die " Can't update $specialmap: $!";
193         } else {
194             print " Entries okay.  Leaving $specialmap untouched.\n";
195         }
196         undef $fontmap;
197     } else {
198         warn " **\n";
199         warn " ** Can't read from $specialmap: $!\n";
200         warn " ** Please verify the content of $specialmap!\n";
201         warn " **\n";
202     }
203     $/ = "\n";
204     close(OLD);
205     print "\n";
206 }
207
208
209
210 #######################
211 # Main program 
212 #######################
213
214 print " Checking teTeX directory \$TEXMF ...";
215
216 chop($TEXMF = `kpsetool -v '\$TEXMF'`);
217
218 if ($? == 0 and $TEXMF ne "") {
219     print " okay.";
220 } else {
221     warn "\n Error: kpsetool not found or \$TEXMF not set!\n";
222     warn " Assuming \$TEXMF=$std_TEXMF\n";
223     $TEXMF = $std_TEXMF;
224     if (not -d $TEXMF) {
225         warn " ... but directory '$TEXMF' does not exist either!\n";
226         die " Please check your teTeX configuration.\n"
227     }
228 }
229
230 if ($TEXMF ne $std_TEXMF) {
231     check_texmfcnf();
232 }
233
234 print "\n";
235
236 run_texhash();
237 check_specialmap();
238
239 print " $pkg_name configuration completed.\n";
240 print " Please read /usr/doc/$package/README.Debian to get started.\n";