Make the script work out-of-directory.
This commit is contained in:
@@ -1,12 +1,42 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
repos="/tmp/repos-$(cat /dev/urandom | base64 | tr -d '=+/' | head -c 8)"
|
||||||
|
mkdir -p "$repos"
|
||||||
|
function safely_remove_tmp_repos() {
|
||||||
|
if [ "$repos" ] && [ -d "$repos" ]; then
|
||||||
|
if [ "$(find -name .git -type d | wc -l)" -eq 0 ]; then
|
||||||
|
echo "Warning: No git repositories found in '$repos'. Not deleting to prevent data loss."
|
||||||
|
rmdir "$repos" 2>/dev/null
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
rm -rf "$repos"
|
||||||
|
fi
|
||||||
|
}
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
rm -rf repos tmp-portfolio
|
safely_remove_tmp_repos
|
||||||
|
rm -rf tmp-portfolio
|
||||||
}
|
}
|
||||||
directory="$1"
|
directory="$1"
|
||||||
|
script_dir="$(dirname "$0")"
|
||||||
if [ ! "$directory" ]; then
|
if [ ! "$directory" ]; then
|
||||||
echo "Usage: $0 <directory>"
|
echo "Usage: $0 <directory>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if ! command -v pass >/dev/null 2>&1; then
|
||||||
|
echo "Error: 'pass' command not found. Please install 'pass' and set up your Gitea API token."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v jq >/dev/null 2>&1; then
|
||||||
|
echo "Error: 'jq' command not found. Please install 'jq' to process JSON data."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v Rscript >/dev/null 2>&1; then
|
||||||
|
echo "Error: 'Rscript' command not found. Please install R to generate language distribution plots."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v quarto >/dev/null 2>&1; then
|
||||||
|
echo "Error: 'quarto' command not found. Please install Quarto to render project pages."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
GIT_URL='https://git.seanhealy.ie'
|
GIT_URL='https://git.seanhealy.ie'
|
||||||
GIT_USER=sean
|
GIT_USER=sean
|
||||||
@@ -44,7 +74,7 @@ while read project; do
|
|||||||
awk -v total="$total_bytes" '{print $2 / total"\t"$1}' |
|
awk -v total="$total_bytes" '{print $2 / total"\t"$1}' |
|
||||||
sort -n -r
|
sort -n -r
|
||||||
)
|
)
|
||||||
git clone --depth 1 -b main --single-branch "$GIT_URL/$GIT_USER/$name" "repos/$name" 2>/dev/null >/dev/null
|
git clone --depth 1 -b main --single-branch "$GIT_URL/$GIT_USER/$name" "$repos/$name" 2>/dev/null >/dev/null
|
||||||
echo $'Percentage\tLanguages' > /tmp/languages.tsv
|
echo $'Percentage\tLanguages' > /tmp/languages.tsv
|
||||||
echo "$languages_percentages" >> /tmp/languages.tsv
|
echo "$languages_percentages" >> /tmp/languages.tsv
|
||||||
(cat > /tmp/plot.R) <<EOF
|
(cat > /tmp/plot.R) <<EOF
|
||||||
@@ -61,7 +91,7 @@ while read project; do
|
|||||||
theme_void() +
|
theme_void() +
|
||||||
scale_fill_brewer(palette="Set3") +
|
scale_fill_brewer(palette="Set3") +
|
||||||
theme(legend.text=element_text(size=16), legend.title=element_text(size=18))
|
theme(legend.text=element_text(size=16), legend.title=element_text(size=18))
|
||||||
ggsave("repos/$name/$name-languages.png", plot, width=5, height=5)
|
ggsave("$repos/$name/$name-languages.png", plot, width=5, height=5)
|
||||||
EOF
|
EOF
|
||||||
Rscript /tmp/plot.R
|
Rscript /tmp/plot.R
|
||||||
language_list="$(
|
language_list="$(
|
||||||
@@ -73,9 +103,8 @@ EOF
|
|||||||
updated_at=$(date -d "$updated_at" +"%B %d, %Y")
|
updated_at=$(date -d "$updated_at" +"%B %d, %Y")
|
||||||
avatar_url=$(jq -r ".[$i]" <<< "$project"); i=$((i + 1))
|
avatar_url=$(jq -r ".[$i]" <<< "$project"); i=$((i + 1))
|
||||||
licenses=$(jq -r '.['$i'] | join(", ")' <<< "$project"); i=$((i + 1))
|
licenses=$(jq -r '.['$i'] | join(", ")' <<< "$project"); i=$((i + 1))
|
||||||
mkdir -p repos
|
cp "$script_dir/project-style.css" "$repos/$name/"
|
||||||
cp project-style.css "repos/$name/"
|
(cd "$repos/$name" && (cat > "$name.qmd") <<EOF
|
||||||
(cd "repos/$name" && (cat > "$name.qmd") <<EOF
|
|
||||||
---
|
---
|
||||||
execute:
|
execute:
|
||||||
enabled: false
|
enabled: false
|
||||||
@@ -189,5 +218,5 @@ else
|
|||||||
mkdir -p "$directory"
|
mkdir -p "$directory"
|
||||||
fi
|
fi
|
||||||
rsync -a "tmp-portfolio/" "$directory/"
|
rsync -a "tmp-portfolio/" "$directory/"
|
||||||
rm -rf repos
|
safely_remove_tmp_repos
|
||||||
rm -r tmp-portfolio
|
rm -r tmp-portfolio
|
||||||
|
|||||||
Reference in New Issue
Block a user