Signed-off-by: Jessica Frazelle <acidburn@docker.com>
| 1 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,74 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+set -e |
|
| 2 |
+ |
|
| 3 |
+# This script generates index files for the directory structure |
|
| 4 |
+# of the apt and yum repos |
|
| 5 |
+ |
|
| 6 |
+: ${DOCKER_RELEASE_DIR:=$DEST}
|
|
| 7 |
+APTDIR=$DOCKER_RELEASE_DIR/apt |
|
| 8 |
+YUMDIR=$DOCKER_RELEASE_DIR/yum |
|
| 9 |
+ |
|
| 10 |
+if [ ! -d $APTDIR ] && [ ! -d $YUMDIR ]; then |
|
| 11 |
+ echo >&2 'release-rpm or release-deb must be run before generate-index-listing' |
|
| 12 |
+ exit 1 |
|
| 13 |
+fi |
|
| 14 |
+ |
|
| 15 |
+create_index() {
|
|
| 16 |
+ local directory=$1 |
|
| 17 |
+ local original=$2 |
|
| 18 |
+ local cleaned=${directory#$original}
|
|
| 19 |
+ |
|
| 20 |
+ # the index file to create |
|
| 21 |
+ local index_file="${directory}/index"
|
|
| 22 |
+ |
|
| 23 |
+ # cd into dir & touch the index file |
|
| 24 |
+ cd $directory |
|
| 25 |
+ touch $index_file |
|
| 26 |
+ |
|
| 27 |
+ # print the html header |
|
| 28 |
+ cat <<-EOF > "$index_file" |
|
| 29 |
+ <!DOCTYPE html> |
|
| 30 |
+ <html> |
|
| 31 |
+ <head><title>Index of ${cleaned}/</title></head>
|
|
| 32 |
+ <body bgcolor="white"> |
|
| 33 |
+ <h1>Index of ${cleaned}/</h1><hr>
|
|
| 34 |
+ <pre><a href="../">../</a> |
|
| 35 |
+ EOF |
|
| 36 |
+ |
|
| 37 |
+ # start of content output |
|
| 38 |
+ ( |
|
| 39 |
+ # change IFS locally within subshell so the for loop saves line correctly to L var |
|
| 40 |
+ IFS=$'\n'; |
|
| 41 |
+ |
|
| 42 |
+ # pretty sweet, will mimick the normal apache output |
|
| 43 |
+ for L in $(find -L . -mount -depth -maxdepth 1 -type f ! -name 'index' -printf "<a href=\"%f\">%-44f@_@%Td-%Tb-%TY %Tk:%TM @%f@\n"|sort|sed 's,\([\ ]\+\)@_@,</a>\1,g'); |
|
| 44 |
+ do |
|
| 45 |
+ # file |
|
| 46 |
+ F=$(sed -e 's,^.*@\([^@]\+\)@.*$,\1,g'<<<"$L"); |
|
| 47 |
+ |
|
| 48 |
+ # file with file size |
|
| 49 |
+ F=$(du -bh $F | cut -f1); |
|
| 50 |
+ |
|
| 51 |
+ # output with correct format |
|
| 52 |
+ sed -e 's,\ @.*$, '"$F"',g'<<<"$L"; |
|
| 53 |
+ done; |
|
| 54 |
+ ) >> $index_file; |
|
| 55 |
+ |
|
| 56 |
+ # now output a list of all directories in this dir (maxdepth 1) other than '.' outputting in a sorted manner exactly like apache |
|
| 57 |
+ find -L . -mount -depth -maxdepth 1 -type d ! -name '.' -printf "<a href=\"%f\">%-43f@_@%Td-%Tb-%TY %Tk:%TM -\n"|sort -d|sed 's,\([\ ]\+\)@_@,/</a>\1,g' >> $index_file |
|
| 58 |
+ |
|
| 59 |
+ # print the footer html |
|
| 60 |
+ echo "</pre><hr></body></html>" >> $index_file |
|
| 61 |
+ |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+get_dirs() {
|
|
| 65 |
+ local directory=$1 |
|
| 66 |
+ |
|
| 67 |
+ for d in `find ${directory} -type d`; do
|
|
| 68 |
+ create_index $d $directory |
|
| 69 |
+ done |
|
| 70 |
+} |
|
| 71 |
+ |
|
| 72 |
+get_dirs $APTDIR |
|
| 73 |
+get_dirs $YUMDIR |