make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / PMdirindex
blobd78998e4b0bd09f1c14783c6511ac8dd2eed2715
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 PMdirindex - Poor man's directory index generator, output HTML
10 =cut
12 EOF
14 switch=''
15 total=0
16 self=`basename "$0"`
17 output=./index.html
20 human_number() {
21 n=$1
22 m=''
23 i=${#n}
24 while [ $i -gt 0 ]
26 let i--
27 [ $[(${#n}-$i)%3] == 1 ] && s=" " || s=''
28 m="${n:$i:1}$s$m"
29 done
30 m=${m:0:$[${#m}-1]}
31 echo -n "$m"
35 while [ -n "$1" ]
37 if [ .${1:0:1} = .- ] && expr "${1:1}" : "[AasrctuvU]\+\$" >/dev/null
38 then
39 switch="$switch $1"
40 else
41 echo "$self: ignored: $1" >&2
43 shift
44 done
46 if [ -t 1 ]
47 then
48 if [ ! -f "$output" ]
49 then
50 echo "$self: output: $output" >&2
51 exec > "$output"
52 else
53 echo "$self: $output: already exists." >&2
54 exit 1
59 echo "<pre class='poorMansDirecoryIndex'>"
60 echo "date time size name"
61 echo "------------------------- -------------- --------------"
63 ls -1 --group-directories-first ${switch:--At} | {
64 while read file
66 time=$(date +'%Y-%m-%d %H:%M:%S %z' -d@$(stat -c %Y "$file"))
67 size=$(stat -c %s "$file")
68 sz=`human_number $size`
69 type=''
70 if [ -d "$file" ]; then type=/; size=''
71 elif [ -L "$file" ]; then type=@
72 elif [ -x "$file" ]; then type=*
74 total=$(( total+size ))
76 printf "%s %14s <a href='%s'>%s</a>%s\n" "$time" "$sz" "$file" "$file" "$type"
77 done
79 echo "------------------------- -------------- --------------"
80 printf "%40s\n" "`human_number $total`"
83 echo "</pre>"