#!/bin/bash base="index" #----------------------------------------------------------------------------- index="${base}.html" tmp="${base}-tmp.html" old="${base}-old.html" check_bin () { if [ ! -x "${1}" ]; then echo "ERROR: Cannot find required program: ${1}" exit 1 fi } get_filesize_text () { local bytes=$(${stat_bin} --format="%s" "${*}") local size=0 local units="" size="${bytes}" units="B" if [ "${bytes}" -gt 100000000000 ]; then size=$(echo "scale=2; ${bytes} / 100000000000" | ${bc_bin}) units="EB" elif [ "${bytes}" -gt 1000000000 ]; then size=$(echo "scale=2; ${bytes} / 1000000000" | ${bc_bin}) units="GB" elif [ "${bytes}" -gt 1000000 ]; then size=$(echo "scale=2; ${bytes} / 1000000" | ${bc_bin}) units="MB" elif [ "${bytes}" -gt 1000 ]; then size=$(echo "scale=2; ${bytes} / 1000" | ${bc_bin}) units="KB" fi echo "${size} ${units}" } cat_bin="/bin/cat" ; check_bin "${cat_bin}" ls_bin="/bin/ls" ; check_bin "${ls_bin}" sort_bin="/usr/bin/sort" ; check_bin "${sort_bin}" awk_bin="/usr/bin/awk" ; check_bin "${awk_bin}" sed_bin="/bin/sed" ; check_bin "${sed_bin}" basename_bin="/usr/bin/basename" ; check_bin "${basename_bin}" stat_bin="/usr/bin/stat" ; check_bin "${stat_bin}" bc_bin="/usr/bin/bc" ; check_bin "${bc_bin}" bg_color="d5f3bc" ${cat_bin} > ${tmp} << EOF Laurel Church of Christ :: Sermons Online

Sermons Online

EOF for file in $(${ls_bin} -1 [0-9]* | ${sort_bin} -r); do base_file=$(echo "${file}" | sed 's,\.[^\.]*$,,g') date=$(\ echo "${base_file}" \ | ${awk_bin} -F___ '{print $1}' \ ) title=$(\ echo "${base_file}" \ | ${awk_bin} -F___ '{print $2}' \ | ${sed_bin} 's,_, ,g' \ ) speaker=$(\ echo "${base_file}" \ | ${awk_bin} -F___ '{print $3}' \ | ${sed_bin} 's,_, ,g' \ ) extension=$(echo "${file}" | sed 's,^.*\.,,g') if [ ! -f "${extension}.gif" ]; then echo "*** ERROR: Missing icon: ${extension}.gif" fi file_size=$(get_filesize_text "${file}") rm -f "play-*.html" if [ ! -z "${date}" ]; then case "${extension}" in [Mm][Pp]3) ${cat_bin} > play-${date}.html << EOF Laurel Church of Christ :: Sermons Online :: ${title}
  ${date} ${title} ${speaker} ${file_size}  
EOF ;; esac fi ${cat_bin} >> ${tmp} << EOF   EOF case "${extension}" in [Mm][Pp]3) ${cat_bin} >> ${tmp} << EOF EOF ;; esac ${cat_bin} >> ${tmp} << EOF ${date} ${title} ${speaker} ${file_size}   EOF done ${cat_bin} >> ${tmp} << EOF EOF mv "${index}" "${old}" mv "${tmp}" "${index}" rm "${old}" # vim:ts=2:shiftwidth=2:filetype=sh:syntax=sh: