#!/usr/bin/env bash set -Eeuo pipefail info="/run/shm/msg.html" escape () { local s s=${1//&/\&} s=${s//\<} s=${s//>/\>} s=${s//'"'/\"} printf -- %s "$s" return 0 } path="$1" total="$2" body=$(escape "$3") if [[ "$body" == *"..." ]]; then body="
${body::-3}
" fi while true do if [ ! -s "$path" ] && [ ! -d "$path" ]; then bytes="0" else bytes=$(du -sb "$path" | cut -f1) fi if (( bytes > 4096 )); then if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/') else size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')" size="$size%" fi [[ "$size" != "0.0%" ]] && echo "${body//(\[P\])/($size)}"> "$info" fi sleep 1 & wait $! done