File: install

package info (click to toggle)
html2ps 1.0b7-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,208 kB
  • sloc: perl: 4,539; tcl: 1,799; sh: 38; makefile: 4
file content (443 lines) | stat: -rwxr-xr-x 14,040 bytes parent folder | download | duplicates (5)
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
: # Use perl
eval 'exec perl -S $0 "$@"'
  if $running_under_some_shell;

$vid=107;
use File::Copy;

$| = 1;
%p = ("ImageMagick" => "mogrify", "pbmplus" => "giftoppm",
      "netpbm" => "giftopnm", "TeX" => "tex", "Ghostscript" => "gs");
%DOS = ('html2ps.html' => 'html2ps.htm', 'html2psrc.5' => 'html2psr.5');
@reqpath = ();

die "I am sorry, html2ps requires Perl 5.\n" if($]<5);

if(-e '/dev/null') {
    $pathsep = ':';
    $dirsep = '/';
    $sys = 'unix';
    $prefix = '/usr/local';
} elsif (-e 'nul') {
    $pathsep = ';';
    $dirsep = '\\';
    $sys = 'dos';
    $prefix = 'C:\Program\html2ps';
    $p{Ghostscript} = 'gswin32c';
    $ENV{PATH} .= ';C:\Acrobat';
} else {
    &getval($goon, "n", "\nThis installation script is for Unix and Windows "
    ."systems, and yours does not\nseem to be one. Do you want to continue "
    ."anyway?");
    die "\n" if($goon=~/^n/i);
}
@perl = ("Image${dirsep}Magick.pm", "LWP${dirsep}UserAgent.pm");

print <<EOD;

This is the installation script for html2ps. To get full functionality, some
external program packages need to be installed. You may wish to install these
first (see the enclosed documentation for addresses):

 * For conversion on inline images, any of the packages ImageMagick, pbmplus
   or netpbm.

 * To retrieve remote documents you must have libwww-perl. Alternatively,
   some program like wget or lynx.

 * To be able to generate cross references and DSC PostScript, you must
   have Ghostscript installed.

 * To be able to convert documents using the MATH element from HTML 3.0,
   you need both TeX and dvips.

This script creates a file describing the local configuration. To make this
accurate, you should have your search PATH set to include the directories
where the abovementioned packages are. You must also have write access to
the directories where the files should be placed.
EOD

&getval($goon, "y", "\nDo you want to proceed with the installation?");
die "\n" if($goon!~/^y/i);

print "\n";
for $req (@perl) {
    print "Searching for $req: ";
    X:for $dir (@INC) {
        if(-f "$dir${dirsep}$req") {
            $module{$req} = 1;
            print "found ($dir${dirsep}$req)\n";
            last X;
        }
    }
    print "not found\n" if(!$module{$req});
}

$pack = "";
if(&exist("ImageMagick",1)) {
    $pack .= "    ImageMagick: 1;\n";
    $pack .= "    PerlMagick: 1;\n" if($module{"Image${dirsep}Magick.pm"});
} elsif(&exist("netpbm",1)) {
    $pack .= "    netpbm: 1;\n";
} elsif(&exist("pbmplus",1)) {
    $pack .= "    pbmplus: 1;\n";
}

print <<EOW if(!$pack);

Could not find any image conversion package (pbmplus, netpbm or ImageMagick)
in your search path. If you want to be able to have inline images (other than
XBM images) included in the PostScript code, you must install one of these
packages. If you do indeed have any of these packages installed, you will
have to edit the configuration file manually, see the documentation for
details.

EOW

for ("djpeg","TeX","dvips","Ghostscript") {
    if(&exist($_,1)) {
        $pack .= "    $_: 1;\n";
    }
}
if(&exist("weblint",1)) {
    $pack .= "    check: weblint;\n";
}

if($module{"LWP${dirsep}UserAgent.pm"}) {
    $pack .= "    libwww-perl: 1;\n";
} else {
    if(&exist("lynx",0)) {
        $lynx = 1;
        $lynxcmd = "lynx -source -mime_header";
        $getdef = $lynxcmd;
    }
    if(&exist("wget",0)) {
        $wget = 1;
        $ugcmd = "wget -s -q -O-";
        $getdef = $ugcmd;
    }
    $both = $wget && $lynx? " (for example '$ugcmd' or\n'$lynxcmd')": "";
    $none = $wget || $lynx? "":
           ", or press <return> to convert local files only";
    &getval($geturl, $getdef,
    "\nBy default html2ps uses libwww-perl to retrieve remote documents, "
    ."I cannot\nfind this on your system. You may instead use some command "
    ."that can retrieve\ndocuments _with_a_complete_MIME_header_$both\.\n"
    ."Enter such a command$none");
    $geturl = "/bin/true" if(!$geturl);
    $pack .= "    geturl: \"$geturl\";\n";
}

if(@reqpath) {
    $pack .= '    path: "'.join($pathsep, @reqpath).'";';
}

chop ($cd = `pwd`);

&getval($ans, "y",
 "\nBy default all files will be installed in subdirectories 'bin', 'lib',\n"
 ."and 'man' in a common directory. Is this OK?");
$def = $ans=~/^y/i;

if($def) {
    &getval($prefix, "$prefix", "\nEnter the name of this directory");
    &fixdir($prefix);
    while(!&goodprefix) {
	&getval($prefix, "$prefix", "\nEnter a new directory name");
    }
    &makedir($prefix,0);
}

if($def) {
    $bindir = "$prefix${dirsep}bin";
} else {
    &getval($bindir, "$prefix${dirsep}bin",
     "\nEnter the directory where the html2ps script should be put");
    &fixdir($bindir);
    ($prefix) = $bindir=~m|(.*)\Q$dirsep\E[^\Q$dirsep\E]+|;
}
&makedir($bindir,$def);

if($def) {
    $glob = "$prefix${dirsep}lib${dirsep}html2ps";
} else {
    &getval($glob, "$prefix${dirsep}lib${dirsep}html2ps",
     "\nEnter the the directory where the global configuration file for\n"
    ."html2ps should be put");
    $glob =~ s|/$||g;
    &fixdir($glob);
}
&makedir($glob,$def);
$repl = "y";
if(-f "$glob${dirsep}html2psrc") {
    &getval($repl, "y", "\nA file $glob${dirsep}html2psrc already exists, replace?");
}

if($def) {
    $man1 = "$prefix${dirsep}man${dirsep}man1";
} else {
    &getval($man1, "$prefix${dirsep}man${dirsep}man1",
     "\nEnter the directory for the html2ps manual page");
    &fixdir($man1);
}
&makedir($man1,$def);

if($def) {
    $man5 = "$prefix${dirsep}man${dirsep}man5";
} else {
    &getval($man5, "$prefix${dirsep}man${dirsep}man5",
     "\nEnter the directory for the manual page describing the configuration\n"
     ."file format for html2ps");
    &fixdir($man5);
}
&makedir($man5,$def);

$ht = "\nTo use the automatic hyphenation feature, hyphenation pattern files\n"
     ."from the TeX distribution are needed.";
$cophy = 1;
if($exist{'TeX'}) {
    $hfile = "";
    ($texdir = $dir{'TeX'}) =~ s|/bin$||;
    SW:for("texmf/tex/generic/hyphen","macros","inputs","lib/macros",
        "lib/inputs","lib/tex/macros","lib/tex/inputs") {
        if(-f "$texdir/$_/ushyph1.tex") {
            $hyph = "$texdir/$_";
            $hfile = "$hyph/ushyph1.tex";
            last SW;
        }
        if(-f "$texdir/$_/hyphen.tex") {
            $hyph = "$texdir/$_";
            $hfile = "$hyph/hyphen.tex";
            last SW;
        }
    }
    if($hfile) {
        &getval($hdef, "y", "$ht I believe that I have found\nthe pattern "
         ."file for English in your TeX installation:\n\n  "
         ."$hfile\n\nWould you like to use this instead of the "
         ."file included with html2ps?");
        if($hdef=~/^y/i) {
            $cophy = 0;
        } else {
            $hfile = "";
        }
    } else {
        &getval($hfile, "", "$ht I cannot find the pattern\nfile for English "
         ."in your TeX installation. (It should be called\n'hyphen.tex', "
         ."or perhaps 'ushyph1.tex', somewhere in the directory\ntree "
         ."'$texdir'.)\n\nIf you know where this file is and want to use it "
         ."instead of the\nfile included with html2ps, enter the full path "
         ."name for this file,\notherwise press <return>");
        while($hfile && !-f $hfile) {
            &getval($hfile, "", "\nNo such file: $hfile\nEnter new name, or "
             ."press <return> to use the supplied file");
        }
        $cophy = $hfile !~ /\S/;
    }
    if(!$hfile) {
        if($def) {
            $hyph = "$prefix${dirsep}lib${dirsep}html2ps";
        } else {
            &getval($hyph, "$prefix${dirsep}lib${dirsep}html2ps",
             "\nOK, I will use the supplied pattern file for English. Enter "
            ."the directory\nwhere this file should be put");
            &fixdir($hyph);
        }
    }
} else {
    if($def) {
        $hyph = "$prefix${dirsep}lib${dirsep}html2ps";
    } else {
    &getval($hyph, "$prefix${dirsep}lib${dirsep}html2ps", "$ht A pattern file for English is\n"
     ."included with html2ps (see the documentation how to install pattern\n"
     ."files for other languages). Enter the directory where this file\n"
     ."should be put");
    }
}
if($cophy) {
    &makedir($hyph,0);
    $hfile = "$hyph${dirsep}hyphen.tex";
}

if($def) {
    $html = "$prefix${dirsep}lib${dirsep}html2ps";
} else {
    &getval($html, "$prefix${dirsep}lib${dirsep}html2ps",
     "\nEnter a directory where to put the HTML document describing\nhtml2ps");
    &fixdir($html);
}
&makedir($html,$def);

$paper = "";
&getval($format, "A4",
 "\nEnter the default paper type, possible choices are:\nA0, A1, A2, A3, A4,"
 ." A5, A6, A7, A8, A9, A10,\nB0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10,\n"
 ."letter, legal, arche, archd, archc, archb, archa,\nflsa, flse, halfletter,"
 ." 11x17, ledger, other");
if($format !~ /^other$/i) {
    $paper .= "    type: $format;";
} else {
    &getval($height, "",
     "\nDefault paper height i centimeters (1 inch = 2.54 centimeters)");
    &getval($width, "", "\nDefault paper width i centimeters");
    $paper .= "    height: $height;\n";
    $paper .= "    width: $width;";
}

open(RC,">html2psrc") || die "*** Error opening html2psrc\n";
print RC "/* Global configuration file for html2ps */\n\n"
  ."\@html2ps {\n  package {\n$pack\n  }\n  paper {\n$paper\n  }\n"
  ."  hyphenation {\n    en {\n      file: \"$hfile\";\n    }\n  }\n}\n";
close RC;

undef $/;
open(HTML2PS,"html2ps") || die "*** Error opening html2ps\n";
($code = <HTML2PS>) =~ s|\$globrc=.*|\$globrc='$glob${dirsep}html2psrc';|;
$code =~ s/exec \S+/exec $^X/;
$code =~ s|\$ug=.*|\$ug='$html${dirsep}html2ps.html';|;
close HTML2PS;
open(HTML2PS,">html2ps") || die "*** Error opening html2ps\n";
print HTML2PS $code;
close HTML2PS;
chmod 0755, "html2ps";

$files = <<EOF;
.TP
$glob/html2psrc
Global configuration file. See html2psrc(5).
.TP
\$HOME/.html2psrc
User configuration file. See html2psrc(5).
.TP
$html/html2ps.html
Documentation for html2ps.
EOF

open(MAN1,"html2ps.1") || die "*** Error opening html2ps.1\n";
($code = <MAN1>) =~ s|(\.SH FILES)[\w\W]*(\.SH SEE ALSO)|$1\n$files$2|;
close MAN1;
open(MAN1,">html2ps.1") || die "*** Error opening html2ps.1\n";
print MAN1 $code;
close MAN1;

$odir = "oldfiles.$vid";
$saved = -f "backout.dat";

print "\n";
&inst($bindir,"html2ps");
if(!$saved && -f "$glob${dirsep}html2psrc") {
    $backout .= "html2psrc $glob\n";
    copy "$glob${dirsep}html2psrc" => $odir or die "*** Cannot write to $odir\n";
}
if($repl=~/^y/i) {
    print "Installing html2psrc in $glob\n";
    copy 'html2psrc' => $glob or die "*** Cannot write to $glob\n";
}
&inst($man1,"html2ps.1");
&inst($man5,"html2psrc.5");
if($cophy) {
    print "Installing hyphen.tex in $hyph\n";
    copy 'hyphen.tex' => $hyph or die "*** Cannot write to $hyph\n";
}
&inst($html,"html2ps.html");

if(!$saved && $backout) {
    open(BACKOUT,">backout.dat") || die "*** Error opening backout\n";
    print BACKOUT "$odir\n$backout";
    close BACKOUT;
}
if(-d $odir) {
    print "\nIf you are not satisfied with this version of html2ps; you can "
         ."execute\nthe script 'backout' to reinstall your earlier version.\n";
}

if($repl!~/^y/i) {
    print "\nA new global configuration file 'html2psrc' has been created in "
         ."the current\ndirectory. You can compare this with your old "
         ."configuration file to see if\nany changes need to be done.\n";
}

print "\nTesting the installation.\n"
  ."Converting the documentation file 'html2ps.html', using the configuration"
  ."\nfile 'sample'. The output will be written to 'html2ps.ps'.\n";
chmod 0755, "$bindir${dirsep}html2ps";
print `perl $bindir${dirsep}html2ps -T -f sample -o html2ps.ps $html${dirsep}html2ps.html`;
print $?? "Something went wrong...\n":
          "\nInstallation completed.\nYou may now try to print the file "
         ."'html2ps.ps' (a users guide on about\n30 pages) in the current "
         ."directory.\n";

sub exist {
    local($package,$flag) = @_;
    $program = $p{$package}? $p{$package}: $package;
    print "Searching for $package: ";
    for $dir (split(/\Q$pathsep/,$ENV{PATH})) {
        if(-f "$dir$dirsep$program" || -f "$dir$dirsep$program.exe") {
            $exist{$package} = 1;
            $dir{$package} = $dir;
            print "found ($dir$dirsep$program)\n";
            push(@reqpath,$dir) if(!grep(/^$dir$/,@reqpath) && $flag);
            $dir = $dir;
            return 1;
        }
    }
    print "not found\n";
    0;
}

sub makedir {
    while(!-d $_[0]) {
	$cre = "n";
	while(!-d $_[0] && !$_[1] && $cre!~/^(y|$)/i) {
	    &getval($cre, "y", "\nDirectory $_[0] does not exist, create?");
	    &getval($_[0], "", "\nEnter new directory name") if($cre!~/^y/i);
	    die "*** Configuration aborted\n" if($_[0] eq "");
	}
     S: while($_[0]=~/\Q$dirsep\E|$/g) {
    	    if($` && !-d $`) {
		if(mkdir($`, 0755)) {
		    print "Created directory $`\n";
		} else {
		    print "*** Error creating directory $`: $!\n";
		    &getval($_[0], "", "\nEnter new directory name");
		    die "*** Configuration aborted\n" if($_[0] eq "");
		    last S;
		}
	    }
        }
    }
}

sub fixdir {
    $_[0] = "$cd/$_[0]" if($_[0]!~/^\// && $dirsep eq '/');
    while($_[0]=~m|[^/]*/\.\./|) {$_[0] = $`.$'};
    $_[0] =~ s|/\./|/|g;
}

sub getval {
    $text = $_[1]? "$_[2] [$_[1]]": $_[2];
    print "$text: ";
    ($_[0] = <STDIN>) =~ s/^\s+|[\/\s]+$//g;
    $_[0] = $_[1] if(!$_[0]);
}
sub inst {
    if(!$saved && -f $_[0].$dirsep.$_[1]) {
        mkdir($odir,0755) || die "*** Error creating $odir\n" if(!-d $odir);
        $backout .= "$_[1] $_[0]\n";
        copy $_[0].$dirsep.$_[1] => $odir or die "*** Cannot write to $odir\n";
    }
    $from = -e $_[1]? $_[1]: $DOS{$_[1]};
    print "Installing $from in $_[0]\n";
    copy $from => $_[0].$dirsep.$_[1] or die "*** Cannot write to $_[0]\n";
}
sub goodprefix {
    for ($prefix, "$prefix${dirsep}bin", "$prefix${dirsep}lib",
	 "$prefix${dirsep}man")
    {
	if (-d $_ && !-w $_) {
	    print "*** Cannot write to directory $_\n";
	    return 0;
	}
    }
    1;
}