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

Last change on this file since 1 was 1, checked in by jbarnold, 18 years ago
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 scm
28);
29
30my @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
56my %map;
57open(TYPES, "./mime.types");
58while(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}
67close(TYPES);
68
69undef $/;
70my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)';
71
72# Read existing binfmt file
73
74open(BINFMT, "./execsys-binfmt.pre");
75my $file = <BINFMT>;
76my ($fstart, $fend) = ($file =~ /$regexp/s);
77close(BINFMT);
78
79# Write new binfmt file
80
81open(BINFMT, ">./execsys-binfmt");
82print BINFMT $fstart, "\n";
83
84foreach 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
89foreach my $ext (@static) {
90        print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n";
91}
92print BINFMT $fend;
93close(BINFMT);
94
95open(CONF, ">./execsys.conf");
96
97foreach my $ext (@dynamic, @static) {
98        print CONF <<END
99<Files *.$ext>
100        SetHandler cgi-script
101        Options +ExecCGI
102</Files>
103
104END
105}
106close(CONF);
107
108open(CAT, "./staticsys-cat.c.pre");
109$file = <CAT>;
110($fstart, $fend) = ($file =~ /$regexp/s);
111close(CAT);
112
113open(CAT, ">./staticsys-cat.c");
114print CAT $fstart, "\n";
115print CAT '#define NEXTS ', scalar(@static), "\n";
116print CAT "const char *map[2 * NEXTS] = {\n";
117for(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}
121print CAT "};\n";
122print CAT $fend;
123close(CAT);
Note: See TracBrowser for help on using the repository browser.