1 | #!/usr/athena/bin/perl |
---|
2 | |
---|
3 | # $Id: banner.pl,v 1.2 1999-05-11 18:40:31 mwhitson Exp $ |
---|
4 | |
---|
5 | $template = "/usr/athena/lib/filters/banner.ps"; |
---|
6 | $motdfile = "/etc/athena/print.motd"; |
---|
7 | $logofile = "/etc/athena/print.logo.ps"; |
---|
8 | |
---|
9 | # default to pass to banner.ps |
---|
10 | $bannertype = "random"; |
---|
11 | |
---|
12 | use Getopt::Std; |
---|
13 | use POSIX; # for strftime() |
---|
14 | |
---|
15 | # See section 6 of the LPRng HOWTO for list of possible command-line |
---|
16 | # options; this gets invoked like a filter. |
---|
17 | |
---|
18 | getopt('CFHJLPQRZacdefhijklnprswxy'); |
---|
19 | |
---|
20 | # Possible error codes, also from section 6 of the HOWTO: |
---|
21 | # Key Value Meaning |
---|
22 | # JSUCC 0 Successful |
---|
23 | # JFAIL 1, 32 Failed - retry later |
---|
24 | # JABORT 2, 33 Abort - terminate queue processing |
---|
25 | # JREMOVE 3, 34 Failed - remove job |
---|
26 | # JHOLD 6, 37 Failed - hold this job |
---|
27 | # Other Abort - terminate queue processing |
---|
28 | |
---|
29 | # Search for -Zbanner=XXX |
---|
30 | |
---|
31 | for $opt (split(/\,/, $opt_Z)) { |
---|
32 | $bannertype = $1 if ($opt =~ /^banner\W*\=\W*(\w+)/i); |
---|
33 | } |
---|
34 | |
---|
35 | $jobname = $opt_J; |
---|
36 | ($host = "\L$opt_h") =~ s/\.mit\.edu$//; # downcase and chop off .mit.edu |
---|
37 | $user = $opt_n; |
---|
38 | $queue = $opt_P; |
---|
39 | $queuejob = $queue . ":" . $jobname; |
---|
40 | $date = strftime("%A, %e %B %Y %H:%M:%S", localtime); |
---|
41 | |
---|
42 | open(TEMPLATE, $template) || exit 0; # JSUCC -- if the banner failed, |
---|
43 | # that's no reason to nuke the job. |
---|
44 | |
---|
45 | if (open(MOTD, $motdfile)) { # Try to open the motd file. If we can't, |
---|
46 | $oldrs = $/; # just set the motd to an empty string. |
---|
47 | undef $/; |
---|
48 | $motd = <MOTD>; |
---|
49 | $/ = $oldrs; |
---|
50 | chomp $motd; |
---|
51 | $motd =~ s/([\(\)])/\\$1/g; # rudimentary PS string quoting semantics |
---|
52 | close MOTD; |
---|
53 | } else { |
---|
54 | $motd = ""; |
---|
55 | } |
---|
56 | |
---|
57 | print <<EOF; |
---|
58 | %! |
---|
59 | /queuejob ($queuejob) def |
---|
60 | /host ($host) def |
---|
61 | /user ($user) def |
---|
62 | /date ($date) def |
---|
63 | /bannertype /$bannertype def |
---|
64 | /motd ($motd) def |
---|
65 | EOF |
---|
66 | |
---|
67 | # The logo file should define a PS function "logo", which is called by |
---|
68 | # banner.ps. If nonexistent, we define a null logo. |
---|
69 | |
---|
70 | if (open(LOGO, $logofile)) { |
---|
71 | print while <LOGO>; |
---|
72 | close LOGO; |
---|
73 | } else { |
---|
74 | print "/logo { } def\n"; |
---|
75 | } |
---|
76 | |
---|
77 | # Now spew out the template file. |
---|
78 | |
---|
79 | print while <TEMPLATE>; |
---|
80 | close TEMPLATE; |
---|
81 | |
---|
82 | exit 0; |
---|