diff --git a/index-recursive.sh b/index-recursive.sh new file mode 100755 index 0000000..332f744 --- /dev/null +++ b/index-recursive.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Variables +find_list="/tmp/find_list" +files_list="/tmp/files_list" +path_gen=$(pwd) +make_file=${path_gen}/index.sh + +# Show help and init generate index files recursively +if [ -z "${1}" ] ; then + echo "" + echo "Usage: $0 " + echo "" +else + cp -rf ${path_gen}/index.sh ${path_gen}/.index.sh 2> /dev/null + chmod +x ${make_file} + bash ${path_gen}/index.sh "${1}" + # Generate index recursive + if [ -d "${1}" ] ; then + list_find=$(find "${1}"/ -type d \( ! -iname ".*" \)) + echo > ${find_list} + for list in $list_find ; do + check_list=$(echo $list | grep "/res") + if [ -z ${check_list} ] ; then + echo ${list} >> ${find_list} + else + echo > /dev/null + fi + done + count_find=$(wc -l ${find_list} | cut -d " " -f 1) + countf=1 + while [ ${countf} -le ${count_find} ] ; do + find_read=$(cat ${find_list} | head -${countf} | tail -1) + rm -rf ${find_read}/.res/res 2> /dev/null + cp -rf ${path_gen}/.res ${find_read}/ 2> /dev/null + cp -rf ${path_gen}/res ${find_read}/.res 2> /dev/null + cp -rf ${path_gen}/index.sh ${find_read}/.index.sh 2> /dev/null + cp -rf ${path_gen}/.index.sh ${find_read}/.index.sh 2> /dev/null + #cp -rf ${path_gen}/index-recursive.sh ${find_read}/.index-recursive.sh 2> /dev/null + #cp -rf ${path_gen}/.index-recursive.sh ${find_read}/.index-recursive.sh 2> /dev/null + if [ ! -z "${find_read}" ] ; then + echo "# Generating index files for ${find_read}" + fi + cd ${find_read} + chmod +x .index.sh 2> /dev/null + bash .index.sh . 2> /dev/null + cd ${path_gen} + countf=$(expr ${countf} + 1) + done + #rm -rf ${find_list} + else + echo "# Folder '${1}' not found" + fi +fi diff --git a/index.sh b/index.sh new file mode 100755 index 0000000..b2fe392 --- /dev/null +++ b/index.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Variables +find_list="/tmp/find_list" +files_list="/tmp/files_list" +path_gen=$(pwd) + +# Commands +ls_command="/bin/ls" + +# Show help and init generate index files +if [ -z "${1}" ] ; then + echo "" + echo "Usage: $0 " + echo "" +else + # Generate main index folder + if [ -d "${1}" ] ; then + #echo "# Generating index files for ${1}" + ${ls_command} -1 --group-directories-first "${1}"/ > ${files_list} + rm -rf ${1}/.res/res 2> /dev/null + cp -rf ${path_gen}/res ${1}/.res 2> /dev/null + cp -rf ${path_gen}/res/head.html ${1}/.index.html 2> /dev/null + cp -rf ${path_gen}/.res ${1}/ 2> /dev/null + cp -rf ${path_gen}/.res/head.html ${1}/.index.html 2> /dev/null + count_list=$(wc -l ${files_list} | cut -d " " -f 1) + count=1 + while [ ${count} -le ${count_list} ] ; do + line_read=$(cat ${files_list} | head -${count} | tail -1) + if [ "${line_read}" == "index.sh" ] ; then + count=$(expr ${count} + 1) + elif [ "${line_read}" == "index-recursive.sh" ] ; then + count=$(expr ${count} + 1) + elif [ "${line_read}" == "index.html" ] ; then + count=$(expr ${count} + 1) + elif [ "${line_read}" == "res" ] ; then + count=$(expr ${count} + 1) + else + if [ -d "${line_read}" ] ; then + echo "# Generating entry for '${line_read}'" + echo -n '
  • > ${1}/.index.html + echo -n '">' >> ${1}/.index.html + echo -n "${line_read}" >> ${1}/.index.html + echo '
  • ' >> ${1}/.index.html + count=$(expr ${count} + 1) + elif [ -f "${line_read}" ] ; then + echo "# Generating entry for '${line_read}'" + echo -n '
  • > ${1}/.index.html + echo -n '">' >> ${1}/.index.html + echo -n "${line_read}" >> ${1}/.index.html + echo '
  • ' >> ${1}/.index.html + count=$(expr ${count} + 1) + else + echo "# Generating entry for '${line_read}'" + echo -n '
  • > ${1}/.index.html + echo -n '">' >> ${1}/.index.html + echo -n "${line_read}" >> ${1}/.index.html + echo '
  • ' >> ${1}/.index.html + count=$(expr ${count} + 1) + fi + fi + done + cat ${path_gen}/res/tail.html >> ${1}/.index.html 2> /dev/null + cat ${path_gen}/.res/tail.html >> ${1}/.index.html 2> /dev/null + rm -rf ${files_list} + else + echo "# Folder '${1}' not found" + fi +fi