2 # Parse /etc/mime.types into lighttpd config format.
3 # Copyright (c) 2005 Elan Ruusamäe <glen@pld-linux.org>
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)}}' | \
13 LC_ALL=C sort -u > mime.types
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
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}')
22 echo >&2 Found $(echo "$dup" | wc -w) extensions which have non-unique mime-type mapping:
23 echo "$dup" | sed -e 's,^, ,' >&2
27 mv -f mime.types.conf mime.types.conf.tmp
30 cat >> mime.types.conf <<EOF
36 cat mime.types.conf.tmp >> mime.types.conf
39 cat >> mime.types.conf <<EOF
43 rm -f mime.types.conf.tmp