From 687d1df9e0b0a6ccfb89578084012ddb8c5efc52 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Mon, 8 Feb 2021 11:06:32 +0100 Subject: [PATCH] Initial commit. --- dhtml.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 dhtml.sh diff --git a/dhtml.sh b/dhtml.sh new file mode 100755 index 0000000..8b74fe2 --- /dev/null +++ b/dhtml.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +set -e +set -o pipefail + +function hsize () { + size=$1 + + if [[ ${size} -lt 1024 ]] + then + size_h=${size}b + elif [[ ${size} -lt 1048576 ]] + then + size_h=$(bc <<<"scale=1;${size} / 1024.0")Kb + elif [[ ${size} -lt 1073741824 ]] + then + size_h=$(bc <<<"scale=1;${size} / (1024.0*1024.0)")Mb + else + size_h=$(bc <<<"scale=2;${size} / (1024.0*1024.0*1024.0)")Gb + fi + + echo ${size_h} +} + +while read line +do + + while [[ ${line} =~ @DATE ]] + do + DATE=$(date) + line=$(sed -e "s/@DATE/${DATE}/" <<<"${line}") + done + + while [[ ${line} =~ @EXEC ]] + do + command=$(sed -e "s/^.*@EXEC{\([^}]*\)}.*$/\1/" <<<"${line}") + prefix=$(sed -e "s/\(^.*\)@EXEC.*$/\1/" <<<"${line}") + suffix=$(sed -e "s/^.*@EXEC{[^}]*}\(.*\)$/\1/" <<<"${line}") + line=${prefix}$(${command})$suffix + done + + while [[ ${line} =~ @SIZE ]] + do + filename=$(sed -e "s/^.*@SIZE{\([^}]*\)}.*$/\1/" <<<"${line}") + if [[ ${filename} =~ ^http ]] + then + filesize=$(curl -LsI "${filename}" | grep -i ^Content-Length: | sed -e 's/^[^:]*: \([0-9]*\).*$/\1/') + else + filesize=$(stat -c %s "${filename}") + fi + filesize_h=$(hsize ${filesize}) + line=$(sed -e "s/@SIZE{\([^}]*\)}/${filesize_h}/" <<<"${line}") + done + + while [[ ${line} =~ @FILEDATE ]] + do + filename=$(sed -e "s/^.*@FILEDATE{\([^}]*\)}.*$/\1/" <<<"${line}") + filedate=$(date +'%b %e, %Y' -r "${filename}") + line=$(sed -e "s/@FILEDATE{\([^}]*\)}/${filedate}/" <<<"${line}") + done + + echo "${line}" +done -- 2.20.1