Files
ethereum-rpc-docker/show-size.sh
2024-11-03 10:13:32 +01:00

57 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
BASEPATH="$(dirname "$0")"
source $BASEPATH/.env
IFS=':' read -ra parts <<< $COMPOSE_FILE
blacklist=("drpc.yml" "drpc-free.yml" "base.yml" "rpc.yml" "monitoring.yml" "ftp.yml" "backup-http.yml")
total_size=0
static_size=0
for part in "${parts[@]}"; do
include=true
for word in "${blacklist[@]}"; do
if echo "$part" | grep -qE "$word"; then
#echo "The path $path contains a blacklisted word: $word"
include=false
fi
done
# Check if any parameters were passed
if [ $# -gt 0 ]; then
# Put parameters into an array (list)
params=("$@")
# Check if a string is part of the list
if [[ " ${params[@]} " =~ " ${part%.yml} " ]]; then
include=$include # don't change anything
else
include=false
fi
fi
if $include; then
static_ratio="$($BASEPATH/show-static-file-size.sh ${part%.yml})"
static_ratio="0$static_ratio"
total_kb=$($BASEPATH/show-file-size.sh ${part%.yml})
total_size=$((total_size + total_kb))
#output=$(echo "$((total_kb * 1024))" | numfmt --to=iec --suffix=B --format="%.2f")
#echo "$output"
static_part=$(echo "$total_kb * $static_ratio" | bc)
static_size=$(echo "$static_size + $static_part" | bc)
#output=$(echo "$static_size" | numfmt --to=iec --suffix=B --format="%.2f")
#echo "$output"
fi
done
total=$(echo "$(( total_size * 1024 ))" | numfmt --to=iec --suffix=B --format="%.2f")
static=$(echo $(echo "$static_size * 1024" | bc) | numfmt --to=iec --suffix=B --format="%.2f")
echo "total: $total"
echo "static: $static"