Index scripts
This commit is contained in:
parent
e4896f1890
commit
5a246ac75d
54
index-recursive.sh
Executable file
54
index-recursive.sh
Executable file
|
@ -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 <folder>"
|
||||
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
|
72
index.sh
Executable file
72
index.sh
Executable file
|
@ -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 <folder>"
|
||||
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 '<li class="list-group-item"><center><img src=".res/folder.png" width="21" height="21"> <a href="' >> ${1}/.index.html
|
||||
echo -n "${line_read}/.index.html" >> ${1}/.index.html
|
||||
echo -n '">' >> ${1}/.index.html
|
||||
echo -n "${line_read}" >> ${1}/.index.html
|
||||
echo '</a></center></li>' >> ${1}/.index.html
|
||||
count=$(expr ${count} + 1)
|
||||
elif [ -f "${line_read}" ] ; then
|
||||
echo "# Generating entry for '${line_read}'"
|
||||
echo -n '<li class="list-group-item"><center><img src=".res/file.png" width="21" height="21"> <a href="' >> ${1}/.index.html
|
||||
echo -n "${line_read}" >> ${1}/.index.html
|
||||
echo -n '">' >> ${1}/.index.html
|
||||
echo -n "${line_read}" >> ${1}/.index.html
|
||||
echo '</a></center></li>' >> ${1}/.index.html
|
||||
count=$(expr ${count} + 1)
|
||||
else
|
||||
echo "# Generating entry for '${line_read}'"
|
||||
echo -n '<li class="list-group-item"><center><img src=".res/link.png" width="23" height="21"> <a href="' >> ${1}/.index.html
|
||||
echo -n "${line_read}/.index.html" >> ${1}/.index.html
|
||||
echo -n '">' >> ${1}/.index.html
|
||||
echo -n "${line_read}" >> ${1}/.index.html
|
||||
echo '</a></center></li>' >> ${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
|
Loading…
Reference in New Issue
Block a user