programm-webhook/webhooks-git/assets-hook.sh

39 lines
1.1 KiB
Bash

#!/bin/bash
#!/bin/bash
# Check if correct number of arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <repository_name> <branch_name>"
exit 1
fi
# Echo parameters
echo "Webhook recieved for repository: $repository_name and branch: $branch_name"
repository_name="$1"
branch_name=$(basename "$2")
if [ "$branch_name" != "main" ]; then
echo "Error: This hook must only update branch main, not $branch_name"
exit 1
fi
ASSETS_DIRECTORY="/html/branches/assets"
ASSETS_REPOSITORY="git_assets:AG-IT/assets.git"
# Check if the assets directory exists
if [ -d "$ASSETS_DIRECTORY" ]; then
echo "Directory $ASSETS_DIRECTORY exists, performing git pull..."
# Change directory to branch directory
cd "$ASSETS_DIRECTORY"
# Perform git pull
echo "Updating $ASSETS_DIRECTORY"
git pull origin main
else
echo "Directory $ASSETS_DIRECTORY does not exist, cloning branch..."
# Create branches directory if it doesn't exist
mkdir -p branches
# Clone the branch
git clone --depth 1 --branch "$branch_name" --single-branch "$ASSETS_REPOSITORY" "$branch_dir"
fi