]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd-mime.types.sh
- release 6
[packages/lighttpd.git] / lighttpd-mime.types.sh
1 #!/bin/sh
2 # Parse /etc/mime.types into lighttpd config format.
3 # Copyright (c) 2005 Elan Ruusamäe <glen@pld-linux.org>
4
5 mimetypes="$1"
6
7 # build mime.types from system mime.types
8 # get ones with extension
9 awk '!/^#/ && $2 { print } ' $mimetypes | \
10 # lay out mime types with multiple extension as separate lines \
11 awk '{for (a=2; a <= NF; a++) {printf("%s\t%s\n", $1, $a)}}' | \
12 # sort it \
13 LC_ALL=C sort -u > mime.types
14
15 # build lighttpd.conf fragment
16 awk '{ printf("\t\".%s\"%s=> \"%s\",\n", $2, (length($2) > 4 ? "\t" : "\t\t"), $1)}' \
17         < mime.types | LC_ALL=C sort -r > mime.types.conf
18
19 # sanity check. there can't be more than one mime type mapping for same extension
20 dup=$(awk -F'"' '{print $2}' mime.types.conf | sort | uniq -c | grep -v '1' | awk '{print $NF}')
21 if [ "$dup" ]; then
22         echo >&2 Found $(echo "$dup" | wc -w) extensions which have non-unique mime-type mapping:
23         echo "$dup" | sed -e 's,^,  ,' >&2
24         exit 1
25 fi
26
27 mv -f mime.types.conf mime.types.conf.tmp
28
29 # header
30 cat >> mime.types.conf <<EOF
31 # mimetype mapping
32 mimetype.assign = (
33 EOF
34
35 # save our hard work
36 cat mime.types.conf.tmp >> mime.types.conf
37
38 # footer
39 cat >> mime.types.conf <<EOF
40 )
41 EOF
42
43 rm -f mime.types.conf.tmp
This page took 0.056551 seconds and 3 git commands to generate.