Fix directory errors.

This commit is contained in:
2026-04-19 22:55:39 +01:00
parent 387fd99bdc
commit a31ff48998

View File

@@ -1,6 +1,7 @@
#!/usr/bin/bash
repos="/tmp/repos-$(cat /dev/urandom | base64 | tr -d '=+/' | head -c 8)"
mkdir -p "$repos"
tmp_portfolio="/tmp/portfolio-$(cat /dev/urandom | base64 | tr -d '=+/' | head -c 8)"
function safely_remove_tmp_repos() {
if [ "$repos" ] && [ -d "$repos" ]; then
if [ "$(find -name .git -type d | wc -l)" -eq 0 ]; then
@@ -10,10 +11,10 @@ function safely_remove_tmp_repos() {
fi
rm -rf "$repos"
fi
rm -r "$tmp_portfolio"
}
function cleanup() {
safely_remove_tmp_repos
rm -rf tmp-portfolio
}
directory="$1"
script_dir="$(dirname "$0")"
@@ -59,7 +60,7 @@ curl -s "$GIT_URL/api/v1/users/$GIT_USER/repos" \
.licenses
]'
}
mkdir -p tmp-portfolio
mkdir -p "$tmp_portfolio"
portfolio_index=""
while read project; do
i=0
@@ -143,7 +144,7 @@ EOF
)"
(cd "$repos/$name" &&
quarto render "$name.qmd" -o "$name.html" >/dev/null 2>/dev/null &&
mv "$name.html" "../../tmp-portfolio/$name.html"
mv "$name.html" "$tmp_portfolio/$name.html"
)
while read -r language; do
portfolio_index+="<li class='language'>$language</li>"
@@ -208,7 +209,7 @@ li.language {
</div>
EOF
)"
echo "$portfolio_index" > tmp-portfolio/index.html
echo "$portfolio_index" > "$tmp_portfolio/index.html"
if [ -d "$directory" ]; then
if [ "$(du -sb "$directory" | cut -f1)" -gt $((1024 * 1024 * 400)) ]; then
echo "Error: Directory '$directory' contains more than 400MB of data. Exiting to prevent data loss."
@@ -217,6 +218,5 @@ if [ -d "$directory" ]; then
else
mkdir -p "$directory"
fi
rsync -a "tmp-portfolio/" "$directory/"
rsync -a "$tmp_portfolio/" "$directory/"
safely_remove_tmp_repos
rm -r tmp-portfolio