docker-drone-nsd-zone/scp_and_reload.sh

37 lines
1.1 KiB
Bash
Raw Normal View History

2021-01-18 13:09:30 +00:00
#!/bin/bash
2021-01-18 16:17:46 +00:00
CHFILENAMES=$(git diff-tree --no-commit-id --name-only $DRONE_COMMIT)
2021-01-18 17:06:13 +00:00
mkdir /root/.ssh
2021-01-18 17:15:10 +00:00
echo "$PLUGIN_KEY" > /root/.ssh/id_rsa
2021-01-18 17:06:13 +00:00
chmod 600 /root/.ssh/id_rsa
2021-01-18 16:17:46 +00:00
2021-01-18 16:41:55 +00:00
echo "Changed files: $CHFILENAMES"
2021-01-18 16:17:46 +00:00
for file in $CHFILENAMES; do
if [[ $file == *"zone" ]]; then
ZONE=$(echo $file | sed 's/\.zone//')
echo "Check zone file"
nsd-checkzone $ZONE $file
2021-01-18 16:41:55 +00:00
if [ $? -ne 0 ]; then
echo "Zone file check failed" 1>&2
2021-01-18 16:41:55 +00:00
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
2021-01-18 17:32:56 +00:00
if [ $? -ne 0 ]; then
echo "SCP failed" 1>&2
2021-01-18 17:32:56 +00:00
exit 1
fi
2021-01-18 16:41:55 +00:00
echo "Reload $ZONE zone"
2021-01-18 17:19:37 +00:00
ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$PLUGIN_USER"@"$PLUGIN_HOSTS" nsd-control reload $ZONE
2021-01-18 16:41:55 +00:00
if [ $? -ne 0 ]; then
2021-01-18 16:51:01 +00:00
echo "Reload of zone failed" 1>&2
2021-01-18 16:41:55 +00:00
exit 1
fi
else
echo "Nothing to upload"
2021-01-18 16:17:46 +00:00
fi
done
2021-01-18 16:41:55 +00:00
echo "All done"