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