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
20 # add charset for "text/*" types
22 type = "\"" type "\" + mimetype_textcharsetheader"
27 printf("\t\".%s\"%s=> %s,\n", ext, (length(ext) > 4 ? "\t" : "\t\t"), type);
29 < mime.types | LC_ALL=C sort -r > mime.types.conf
31 # sanity check. there can't be more than one mime type mapping for same extension
32 dup=$(awk -F'"' '{print $2}' mime.types.conf | sort | uniq -c | grep -v '1' | awk '{print $NF}')
34 echo >&2 Found $(echo "$dup" | wc -w) extensions which have non-unique mime-type mapping:
35 echo "$dup" | sed -e 's,^, ,' >&2
39 mv -f mime.types.conf mime.types.conf.tmp
42 cat >> mime.types.conf <<EOF
43 # charset used for "text/*" mimetypes
44 # Apache's AddCharset equivalent. Leave empty to add no charset.
45 # AddCharset "utf-8" would be "; charset=\"utf-8\""
46 # See this post about what it affects:
47 # http://lists.pld-linux.org/mailman/pipermail/pld-devel-en/2012-February/022499.html
48 mimetype_textcharsetheader = ""
49 #mimetype_textcharsetheader = "; charset=\"utf-8\""
56 cat mime.types.conf.tmp >> mime.types.conf
59 cat >> mime.types.conf <<EOF
63 rm -f mime.types.conf.tmp