1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | # upd-execsys |
---|
5 | # Copyright (C) 2006 Jeff Arnold <jbarnold@mit.edu> |
---|
6 | # |
---|
7 | # This program is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License |
---|
9 | # as published by the Free Software Foundation; either version 2 |
---|
10 | # of the License, or (at your option) any later version. |
---|
11 | # |
---|
12 | # This program is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with this program; if not, write to the Free Software |
---|
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
---|
20 | # |
---|
21 | # See /COPYRIGHT in this repository for more information. |
---|
22 | |
---|
23 | my @dynamic = qw( |
---|
24 | pl |
---|
25 | php |
---|
26 | py |
---|
27 | scm |
---|
28 | ); |
---|
29 | |
---|
30 | my @static = qw( |
---|
31 | html |
---|
32 | css |
---|
33 | gif |
---|
34 | jpg |
---|
35 | png |
---|
36 | htm |
---|
37 | jpeg |
---|
38 | js |
---|
39 | ico |
---|
40 | xml |
---|
41 | xsl |
---|
42 | tiff |
---|
43 | tif |
---|
44 | tgz |
---|
45 | tar |
---|
46 | jar |
---|
47 | pdf |
---|
48 | ps |
---|
49 | doc |
---|
50 | xls |
---|
51 | ppt |
---|
52 | swf |
---|
53 | mp3 |
---|
54 | ); |
---|
55 | |
---|
56 | my %map; |
---|
57 | open(TYPES, "./mime.types"); |
---|
58 | while(my $line = <TYPES>) { |
---|
59 | next if($line =~ /^\#/ or $line =~ /^\s*$/); |
---|
60 | my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/); |
---|
61 | next if($exts =~ /^\s*$/); |
---|
62 | |
---|
63 | foreach my $ext (split " ", $exts) { |
---|
64 | $map{$ext} = $type; |
---|
65 | } |
---|
66 | } |
---|
67 | close(TYPES); |
---|
68 | |
---|
69 | undef $/; |
---|
70 | my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)'; |
---|
71 | |
---|
72 | # Read existing binfmt file |
---|
73 | |
---|
74 | open(BINFMT, "./execsys-binfmt.pre"); |
---|
75 | my $file = <BINFMT>; |
---|
76 | my ($fstart, $fend) = ($file =~ /$regexp/s); |
---|
77 | close(BINFMT); |
---|
78 | |
---|
79 | # Write new binfmt file |
---|
80 | |
---|
81 | open(BINFMT, ">./execsys-binfmt"); |
---|
82 | print BINFMT $fstart, "\n"; |
---|
83 | |
---|
84 | foreach my $ext (@dynamic) { |
---|
85 | my $path = $ENV{"${ext}_path"}; |
---|
86 | print BINFMT "echo \":${ext}:E::${ext}::${path}:\" > /proc/sys/fs/binfmt_misc/register\n" if($path); |
---|
87 | } |
---|
88 | |
---|
89 | foreach my $ext (@static) { |
---|
90 | print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n"; |
---|
91 | } |
---|
92 | print BINFMT $fend; |
---|
93 | close(BINFMT); |
---|
94 | |
---|
95 | open(CONF, ">./execsys.conf"); |
---|
96 | |
---|
97 | foreach my $ext (@dynamic, @static) { |
---|
98 | print CONF <<END |
---|
99 | <Files *.$ext> |
---|
100 | SetHandler cgi-script |
---|
101 | Options +ExecCGI |
---|
102 | </Files> |
---|
103 | |
---|
104 | END |
---|
105 | } |
---|
106 | close(CONF); |
---|
107 | |
---|
108 | open(CAT, "./staticsys-cat.c.pre"); |
---|
109 | $file = <CAT>; |
---|
110 | ($fstart, $fend) = ($file =~ /$regexp/s); |
---|
111 | close(CAT); |
---|
112 | |
---|
113 | open(CAT, ">./staticsys-cat.c"); |
---|
114 | print CAT $fstart, "\n"; |
---|
115 | print CAT '#define NEXTS ', scalar(@static), "\n"; |
---|
116 | print CAT "const char *map[2 * NEXTS] = {\n"; |
---|
117 | for(my $i = 0; $i < scalar(@static); $i++) { |
---|
118 | my $comma = ( $i < scalar(@static)-1 ? "," : "" ); |
---|
119 | print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n"; |
---|
120 | } |
---|
121 | print CAT "};\n"; |
---|
122 | print CAT $fend; |
---|
123 | close(CAT); |
---|