31 lines
1 KiB
Bash
31 lines
1 KiB
Bash
#!/bin/bash
|
|
|
|
set -xu
|
|
|
|
|
|
CONFIG_PATH=${config_path}
|
|
JSON="$1"
|
|
REPO_NAME=$(jq -r .repository.name <<< $JSON)
|
|
CLONE_URL=$(jq -r .repository.clone_url <<< $JSON)
|
|
REPO_BRANCH=$(jq -r .ref <<< $JSON | cut -d'/' -f3)
|
|
SSH_OPTIONS='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
|
|
|
for INTEGRATION in "$(cat $CONFIG_PATH | jq -r '.ci | values[]')"
|
|
do
|
|
[[ $(jq -r '.repo' <<< $INTEGRATION) = "$REPO_NAME" ]] || continue
|
|
[[ $(jq -r '.branch' <<< $INTEGRATION) = "$REPO_BRANCH" ]] || continue
|
|
|
|
HOSTNAME=$(jq -r '.hostname' <<< $INTEGRATION)
|
|
DEST_PATH=$(jq -r '.path' <<< $INTEGRATION)
|
|
DEST_GROUP=$(jq -r '.group' <<< $INTEGRATION)
|
|
|
|
[[ -z "$HOSTNAME" ]] || [[ -z "$DEST_PATH" ]] || [[ -z "$DEST_GROUP" ]] && exit 5
|
|
|
|
cd ~
|
|
rm -rf "$REPO_NAME"
|
|
git clone "$CLONE_URL" "$REPO_NAME"
|
|
|
|
ssh $SSH_OPTIONS "build-ci@$HOSTNAME" "find \"$DEST_PATH\" -mindepth 1 -delete"
|
|
scp -r $SSH_OPTIONS "$REPO_NAME"/* "build-ci@$HOSTNAME:$DEST_PATH"
|
|
ssh $SSH_OPTIONS "build-ci@$HOSTNAME" "sudo chown -R build-ci:$DEST_GROUP $(printf "%q" "$DEST_PATH")"
|
|
done
|