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

43 lines
900 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
#
git ls-remote --heads "$PROGRAMM_REPOSITORY" |
# Extract branch names
awk '{print $2}' |
# Remove "refs/heads/" prefix to get only branch names
sed 's#refs/heads/##' |
# Store branch names in an array
mapfile -t branches
for branch in "${branches[@]}";
do
git clone --depth 1 --branch "$branch" --single-branch "$PROGRAMM_REPOSITORY" "$BRANCHES_FOLDER"/"$branch"
done