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

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