programm-webhook/webhooks-git/programm-init.sh

45 lines
957 B
Bash

#!/bin/bash
#
# Initialize assets folder from repository
#
# - delete existing assets folder
# - fetch assets/main from repository
#
HTML_HOME="/html"
BRANCHES_FOLDER="/html/branches"
PROGRAMM_REPOSITORY="git_programm:AG-Programm/parteiprogramm.git"
#
# Remove all branch folders but assets
#
for dir in "$BRANCHES_FOLDER"/*/;
do
dir_name=$(basename "$dir")
if [ "$dir_name" != "assets" ];
then
echo "Deleting directory: $dir"
rm -rf "$dir"
fi
done
#
# Fetch all branch names
#
branches=()
while read -r ref; do
# Extract branch name from the reference
branch_name=$(echo "$ref" | awk '{print $2}' | sed 's/refs\/heads\///')
# put into array
branches+=("$branch_name")
done < <(git ls-remote --heads "$PROGRAMM_REPOSITORY")
for branch in "${branches[@]}";
do
echo "cloning $branch"
git clone --depth 1 --branch "$branch" --single-branch "$PROGRAMM_REPOSITORY" "$BRANCHES_FOLDER"/"$branch"
done