source: server/common/oursrc/execsys/upd-execsys @ 163

Last change on this file since 163 was 163, checked in by presbrey, 15 years ago
mono interpreter
File size: 2.6 KB
Line 
1#!/usr/bin/perl -w
2use 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
23my @dynamic = qw(
24 pl
25 php
26 py
27 cgi
28 scm
29 exe
30);
31
32my @static = qw(
33 html
34 css
35 gif
36 jpg
37 png
38 htm
39 jpeg
40 js
41 ico
42 xml
43 xsl
44 tiff
45 tif
46 tgz
47 tar
48 jar
49 pdf
50 ps
51 doc
52 xls
53 ppt
54 swf
55 mp3
56 JPG
57);
58
59my %map;
60open(TYPES, "./mime.types");
61while(my $line = <TYPES>) {
62        next if($line =~ /^\#/ or $line =~ /^\s*$/);
63        my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/);
64        next if($exts =~ /^\s*$/);
65       
66        foreach my $ext (split " ", $exts) {
67                $map{$ext} = $type;
68                $map{uc($ext)} = $type;
69        }
70}
71close(TYPES);
72
73undef $/;
74my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)';
75
76# Read existing binfmt file
77
78open(BINFMT, "./execsys-binfmt.pre");
79my $file = <BINFMT>;
80my ($fstart, $fend) = ($file =~ /$regexp/s);
81close(BINFMT);
82
83# Write new binfmt file
84
85open(BINFMT, ">./execsys-binfmt");
86print BINFMT $fstart, "\n";
87
88foreach my $ext (@dynamic) {
89  my $path = $ENV{"${ext}_path"};
90  print BINFMT "echo \":${ext}:E::${ext}::${path}:\" > /proc/sys/fs/binfmt_misc/register\n" if($path);
91}
92
93foreach my $ext (@static) {
94        print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n";
95}
96print BINFMT $fend;
97close(BINFMT);
98
99open(CONF, ">./execsys.conf");
100
101foreach my $ext (@dynamic, @static) {
102        print CONF <<END
103<Files *.$ext>
104        SetHandler cgi-script
105        Options +ExecCGI
106</Files>
107
108END
109}
110close(CONF);
111
112open(CAT, "./static-cat.c.pre");
113$file = <CAT>;
114($fstart, $fend) = ($file =~ /$regexp/s);
115close(CAT);
116
117open(CAT, ">./static-cat.c");
118print CAT $fstart, "\n";
119print CAT '#define NEXTS ', scalar(@static), "\n";
120print CAT "const char *map[2 * NEXTS] = {\n";
121for(my $i = 0; $i < scalar(@static); $i++) {
122        my $comma = ( $i < scalar(@static)-1 ? "," : "" );
123        print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n";
124}
125print CAT "};\n";
126print CAT $fend;
127close(CAT);
Note: See TracBrowser for help on using the repository browser.