This commit is contained in:
goldsquid
2025-12-19 15:15:28 +07:00
parent 8e7c8057bd
commit 4ef3d5c55f

View File

@@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
BASEPATH="$(dirname "$0")"
static_file_list="$BASEPATH/static-file-path-list.txt"
# Read the JSON input and extract the list of keys # Read the JSON input and extract the list of keys
keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]')
@@ -16,19 +19,31 @@ for key in $keys; do
total_size=$((total_size + volume_size)) total_size=$((total_size + volume_size))
while IFS= read -r path; do # Only check static files if the list exists
# Check if the path exists if [[ -f "$static_file_list" ]]; then
if [[ -e "$prefix/_data/$path" ]]; then while IFS= read -r path; do
# Print the size of the file or directory # Skip empty lines
size=$(du -sL "$prefix/_data/$path" 2>/dev/null | awk '{print $1}') [[ -z "$path" ]] && continue
static_size=$((static_size + size))
# Format size in human-readable format # Check if the path exists
size_formatted=$(echo "$(( size * 1024 ))" | numfmt --to=iec --suffix=B --format="%.2f") if [[ -e "$prefix/_data/$path" ]]; then
# Print the detected path with size to stderr (one per line) # Print the size of the file or directory
echo "$size_formatted $prefix/_data/$path" >&2 size=$(du -sL "$prefix/_data/$path" 2>/dev/null | awk '{print $1}')
static_size=$((static_size + size))
# Format size in human-readable format
size_formatted=$(echo "$(( size * 1024 ))" | numfmt --to=iec --suffix=B --format="%.2f")
# Print the detected path with size to stderr (one per line)
echo "$size_formatted $prefix/_data/$path" >&2
fi
done < "$static_file_list"
fi fi
done < static-file-path-list.txt
done done
ratio=$(bc -l <<< "scale=2; $static_size/$total_size") # Calculate ratio, handling division by zero
if [[ $total_size -eq 0 ]]; then
ratio="0.00"
else
ratio=$(bc -l <<< "scale=2; $static_size/$total_size")
fi
echo "$ratio" echo "$ratio"