-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-dir-list.sh
More file actions
executable file
·102 lines (71 loc) · 1.73 KB
/
generate-dir-list.sh
File metadata and controls
executable file
·102 lines (71 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
# Script to generate html files displaying folder structure.
# Originally copied the source from https://github.com/algesten/algesten.github.com
if [ "$1" = "" ]; then
echo "Usage: $0 <dir>" >&1
exit 1
fi
if [ ! -d "$1" ]; then
echo \'$1\' is not a directory. >&1
exit 1
fi
function escape {
echo $1 | sed -e "s/</</g" | sed -e "s/&/&/g"
}
function space {
echo $1 | awk '{for (i = 0; i < $1; i++) printf " "}'
}
function generate {
list=""
if [ "`pwd`" != "$startdir" ]; then
list="$list<a href=\"..\">../</a>"
fi
for a in *; do
if [ $a == "index.html" ]; then continue; fi;
info=`ls -lTd "$a"`
size=`echo $info | awk '{print $5}'`
date=`echo $info | awk '{printf ("%s-%s-%s %s",$6,$7,$9,$8)}'`
if [ -d "$a" ]; then
a="${a}/"
size="-"
fi
name=`escape "$a"`
namelen=`echo $name | wc -m`
let nameoff="60 - $namelen"
sizelen=`echo $size | wc -m`
let sizeoff="20 - $sizelen"
line=`printf "<a href=\"%s\">%s</a>" "$name" "$name"``space $nameoff`${date}`space $sizeoff`${size}
list="${list}
${line}"
done
bah="Index of /${base}`pwd | sed -e "s#$startdir##1"`"
bah=`escape "$bah"`
cat <<EOF >index.html
<html>
<head>
<title>${bah}</title>
</head>
<body>
<h1>${bah}</h1>
<hr>
<pre>${list}</pre>
<hr>
</body>
</html>
EOF
}
function traverse {
curdir=`pwd`
for f in `find "$startdir" -type d`; do
cd "$f"
echo "Generating ${f}..."
generate
cd "$curdir"
done
}
curdir=`pwd`
cd "$1"
startdir=`pwd`
base=`basename "$startdir"`
cd "$curdir"
traverse "$1"