2023-05-11 16:43:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-11-18 21:41:22 +00:00
|
|
|
if [[ $# -ne 1 ]]; then
|
2023-05-11 16:43:13 +00:00
|
|
|
echo "usage: $0 <MAX_SIZE_IN_GB>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-01-24 01:17:47 +00:00
|
|
|
if ! [[ -d target ]]; then
|
|
|
|
echo "target directory does not exist yet"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-05-11 16:43:13 +00:00
|
|
|
max_size_gb=$1
|
|
|
|
|
|
|
|
current_size=$(du -s target | cut -f1)
|
|
|
|
current_size_gb=$(expr ${current_size} / 1024 / 1024)
|
|
|
|
|
|
|
|
echo "target directory size: ${current_size_gb}gb. max size: ${max_size_gb}gb"
|
|
|
|
|
|
|
|
if [[ ${current_size_gb} -gt ${max_size_gb} ]]; then
|
|
|
|
echo "clearing target directory"
|
|
|
|
rm -rf target
|
|
|
|
fi
|