docker-drone-nsd-zone/scp_and_reload.sh

37 lines
1.1 KiB
Bash

#!/bin/bash
CHFILENAMES=$(git diff-tree --no-commit-id --name-only $DRONE_COMMIT)
mkdir /root/.ssh
echo "$PLUGIN_KEY" > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
echo "Changed files: $CHFILENAMES"
for file in $CHFILENAMES; do
if [[ $file == *"zone" ]]; then
ZONE=$(echo $file | sed 's/\.zone//')
echo "Check zone file"
nsd-checkzone $ZONE $file
if [ $? -ne 0 ]; then
echo "Zone file check failed" 1>&2
exit 1
fi
echo "SCP of $file started"
scp -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $file "$PLUGIN_USER"@"$PLUGIN_HOSTS":"$PLUGIN_TARGET"/$file
if [ $? -ne 0 ]; then
echo "SCP failed" 1>&2
exit 1
fi
echo "Reload $ZONE zone"
ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$PLUGIN_USER"@"$PLUGIN_HOSTS" nsd-control reload $ZONE
if [ $? -ne 0 ]; then
echo "Reload of zone failed" 1>&2
exit 1
fi
else
echo "Nothing to upload"
fi
done
echo "All done"