3 # Karsten Kruse - www.tecneeq.de
5 # dir2html - create HTML-listung for a directory
7 # Copyright (c) 2001 - 2004, Karsten Kruse tecneeq(at)tecneeq(dot)de
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in
18 # the documentation and/or other materials provided with the
20 # 3. Neither the name of the author nor the names of its contributors
21 # may be used to endorse or promote products derived from this
22 # software without specific prior written permission.
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 # any last words before we die?
47 `basename $0` [Options]
51 -o out.html => output to file => default: $my_output
52 -t title => title => default: $my_title
53 -s file.css => path to a css => default: $my_style
54 -e exclude => exclude this from listing => default: $my_exclude
55 -k keywords => keywords for metatag => default: $my_keywords
56 -d diricon => icon for directorys => default: $my_diricon
57 -f fileicon => icon for files => default: $my_fileicon
58 -p path => directory to HTMLifiy => default: $my_dir
65 my_title="Filelisting"
67 my_exclude="index.html"
68 my_keywords="Files, Stuff"
69 my_diricon="/icons/folder.gif"
74 while getopts ho:t:s:e:k:i:d:f:p: opt ; do
77 o) my_output="$OPTARG" ;;
78 t) my_title="$OPTARG" ;;
79 s) my_style="$OPTARG" ;;
80 e) my_exclude="$OPTARG" ;;
81 k) my_keywords="$OPTARG" ;;
82 d) my_diricon="$OPTARG" ;;
83 f) my_fileicon="$OPTARG" ;;
84 p) my_dir="$OPTARG" ;;
85 \?) usage >&2 ; exit 1 ;;
88 shift `expr $OPTIND - 1`
92 cd $my_dir || die "Could not change directory to $my_dir"
95 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
98 <title>$my_title</title>
99 <meta name="description" content="$my_title">
100 <meta name="keywords" content="$my_keywords">
101 <meta name="generator" content="dir2html from www.tecneeq.de">
102 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
105 if [ ! $my_style = unset ] ; then
106 echo " <link rel=\"stylesheet\" href=\"'$my_style'\" type=\"text/css\">"
113 <h1 align="center">$my_title</h1>
114 <table summary="Verzeichnislisting" align="center" border="1" cellpadding="6" cellspacing="0">
123 for i in `find -type d -maxdepth 1 -printf "%f\n" | sort | sed 's/ /+++A_BLANK+++/g'` ; do
125 for e in $(echo "$my_exclude .") ; do
126 if [ "$i" = "$e" ] ; then
131 if [ $doit = true ] ; then
132 rname="$(echo $i | sed 's/+++A_BLANK+++/ /g')"
134 echo " <td><img src=\"$my_diricon\" alt=\"Verzeichnis\"></td>"
135 echo " <td><a href=\"$rname\">$rname/</a></td>"
136 echo " <td> </td>"
137 echo " <td>Verzeichnis</td>"
142 for i in `find ! -type d -maxdepth 1 -printf "%f\n" | sort | sed 's/ /+++A_BLANK+++/g'` ; do
144 for e in $(echo "$my_exclude") ; do
145 if [ "$e" = "$i" ] ; then
150 if [ $doit = true ] ; then
151 rname="$(echo $i | sed 's/+++A_BLANK+++/ /g')"
153 echo " <td><img src=\"$my_fileicon\" alt=\"File \"></td>"
154 echo " <td><a href=\"$rname\">$rname</a></td>"
155 echo " <td>$([ -h "$rname" ] || du -h "$rname" | awk '{print $1}') </td>"
156 echo " <td>$(file -biL "$rname" | awk '{print $1}' | sed 's/;//g') </td>"
163 <p align="center"><small>Created with <a href="http://www.tecneeq.de/">dir2html</a>.</small></p>
170 if [ $my_output = "stdout" ] ; then
173 echo Writing to $my_output