generate-index-listing 1.9 KB

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