bundlewrap/bundles/build-server/files/ci
2022-03-13 18:11:11 +01:00

31 lines
945 B
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)
SSH_OPTIONS='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
for INTEGRATION in "$(cat $CONFIG_PATH | jq -r '.ci | values[]')"
do
echo '-----------------------'
echo $INTEGRATION
[[ $(jq -r '.repo' <<< $INTEGRATION) = $REPO_NAME ]] || continue
HOSTNAME=$(jq -r '.hostname' <<< $INTEGRATION)
DESTINATION_PATH=$(jq -r '.path' <<< $INTEGRATION)
DESTINATION_GROUP=$(jq -r '.group' <<< $INTEGRATION)
cd ~
rm -rf "$REPO_NAME"
git clone "$CLONE_URL" "$REPO_NAME"
ssh $SSH_OPTIONS "build-ci@$HOSTNAME" "find \"$DESTINATION_PATH\" -mindepth 1 -delete"
scp -r $SSH_OPTIONS "$REPO_NAME"/* "build-ci@$HOSTNAME:$DESTINATION_PATH"
ssh $SSH_OPTIONS "build-ci@$HOSTNAME" "sudo chown -R build-ci:$DESTINATION_GROUP $(printf "%q" "$DESTINATION_PATH")"
done