SOURCES: lighttpd-mime.types.sh (NEW) - autogenerator

glen glen at pld-linux.org
Tue Nov 15 14:45:21 CET 2005


Author: glen                         Date: Tue Nov 15 13:45:21 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- autogenerator

---- Files affected:
SOURCES:
   lighttpd-mime.types.sh (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/lighttpd-mime.types.sh
diff -u /dev/null SOURCES/lighttpd-mime.types.sh:1.1
--- /dev/null	Tue Nov 15 14:45:21 2005
+++ SOURCES/lighttpd-mime.types.sh	Tue Nov 15 14:45:16 2005
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Parse /etc/mime.types into lighttpd config format.
+# Copyright (c) 2005 Elan Ruusamäe <glen at pld-linux.org>
+
+mimetypes="$1"
+
+# build mime.types from system mime.types
+# get ones with extension
+awk '!/^#/ && $2 { print } ' $mimetypes | \
+# lay out mime types with multiple extension as separate lines \
+awk '{for (a=2; a <= NF; a++) {printf("%s\t%s\n", $1, $a)}}' | \
+# sort it \
+LC_ALL=C sort -u > mime.types
+
+# build lighttpd.conf fragment
+awk '{ printf("\t\".%s\"%s=> \"%s\",\n", $2, (length($2) > 4 ? "\t" : "\t\t"), $1)}' \
+	< mime.types | LC_ALL=C sort -r > mime.types.conf
+
+# sanity check. there can't be more than one mime type mapping for same extension
+dup=$(awk -F'"' '{print $2}' mime.types.conf | sort | uniq -c | grep -v '1' | awk '{print $NF}')
+if [ "$dup" ]; then
+	echo >&2 Found $(echo "$dup" | wc -w) extensions which have non-unique mime-type mapping:
+	echo "$dup" | sed -e 's,^,  ,' >&2
+	exit 1
+fi
+
+mv -f mime.types.conf mime.types.conf.tmp
+
+# header
+cat >> mime.types.conf <<EOF
+# mimetype mapping
+mimetype.assign = (
+EOF
+
+# save our hard work
+cat mime.types.conf.tmp >> mime.types.conf
+
+# footer
+cat >> mime.types.conf <<EOF
+)
+EOF
================================================================



More information about the pld-cvs-commit mailing list