lilypond-0.1.36
[lilypond.git] / debian / postinst
blob2e1f5e0d0c28c438a5cefb0b28aa1c83301a8418
1 #!/usr/bin/perl -w
3 # postinst script for the Debian GNU/Linux lilypond package
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
9 use strict;
10 use File::Copy;
12 my ($package, $pkg_name, $font_supplier, $font_typeface, $std_TEXMF, $TEXMF,
13 $TEXINPUTS, $MFINPUTS, $TFMFONTS, @fonts);
15 sub correct_opus_fonts ($$);
16 sub check_texmfcnf ();
17 sub run_texhash ();
18 sub add_fonts ($$$$@);
19 sub check_specialmap ();
21 $| = 1;
24 #######################
25 # Variables
26 #######################
28 $package = "lilypond"; # This is used for filenames! Don't change it!
29 $pkg_name = "GNU LilyPond";
31 $font_supplier = "public";
32 $font_typeface = "lilypond";
33 @fonts = qw( feta );
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//";
41 #######################
42 # Subroutine
43 #######################
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. ^_^
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 = "";
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";
64 ($_[0] =~ s/(^\w+\s+public\s+$typeface\n)+/$entries/m)
65 or die " Can't correct font entries in $specialmap: $!";
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");
72 print "\n";
73 return 1;
74 } else {
75 return 0;
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
83 sub check_texmfcnf () {
84 my $texmfcnf;
86 print "\n You have a custom teTeX installation in $TEXMF.\n";
88 chop($texmfcnf = `kpsewhich cnf texmf.cnf`);
90 if ($? == 0 and $texmfcnf ne "") {
91 my($filebuf, $line);
92 my $new = "$texmfcnf.new";
93 my $bak = "$texmfcnf.bak";
95 open(OLD, "< $texmfcnf") or die " Can't open $texmfcnf for reading: $!";
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 ...";
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";
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";
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";
133 #------------------------------------------------------------- Run texhash ---
135 sub run_texhash () {
136 print " Running texhash to update $TEXMF/ls-R ...\n";
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";
143 print "\n";
146 #---------- Add font entries to special.map (called by check_specialmap()) ---
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";
157 $_[0] =~ /((^\w+\s+$supplier\s+$typeface\n)+)/m;
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;
169 #---------------------------------- Check special.map and add font entries ---
171 sub check_specialmap () {
172 my $fontmap;
173 my $specialmap = "$TEXMF/fontname/special.map";
174 my $new = "$specialmap.new";
175 my $bak = "$specialmap.bak";
177 print " Checking font entries in $specialmap ...\n";
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))
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";
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";
203 $/ = "\n";
204 close(OLD);
205 print "\n";
210 #######################
211 # Main program
212 #######################
214 print " Checking teTeX directory \$TEXMF ...";
216 chop($TEXMF = `kpsetool -v '\$TEXMF'`);
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"
230 if ($TEXMF ne $std_TEXMF) {
231 check_texmfcnf();
234 print "\n";
236 run_texhash();
237 check_specialmap();
239 print " $pkg_name configuration completed.\n";
240 print " Please read /usr/doc/$package/README.Debian to get started.\n";