2024-08-20 19:31:36 +02:00
|
|
|
name: DNS automated deployment
|
2023-10-24 18:04:11 +02:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
2023-10-25 00:53:02 +02:00
|
|
|
- 'main'
|
2023-10-24 18:04:11 +02:00
|
|
|
|
|
|
|
jobs:
|
2024-08-20 19:31:36 +02:00
|
|
|
deploy:
|
2023-10-24 18:04:11 +02:00
|
|
|
runs-on: linux_amd64
|
|
|
|
steps:
|
2024-08-20 16:45:39 +02:00
|
|
|
- name: Apply zone changes
|
2023-10-24 18:04:11 +02:00
|
|
|
shell: bash
|
2024-08-20 16:51:32 +02:00
|
|
|
run: |
|
2024-08-20 19:31:36 +02:00
|
|
|
LAST_RUN=$(cat /home/runner/last_run)
|
2024-08-20 17:35:01 +02:00
|
|
|
CURRENT_ZONE=
|
2024-08-20 16:51:32 +02:00
|
|
|
echo "Preparing to update ${{ vars.DNS_SERVER }}..."
|
2024-08-20 17:27:39 +02:00
|
|
|
git clone ${{ gitea.server_url }}/${{ gitea.repository }} dns
|
|
|
|
cd dns
|
2024-08-20 19:31:36 +02:00
|
|
|
git diff $LAST_RUN ${{ env.GITHUB_SHA }} > zone_diff.txt
|
2024-08-20 18:07:37 +02:00
|
|
|
echo "${{ secrets.TSIG_KEY }}" | base64 -d > temp_keyfile
|
2024-08-20 17:29:06 +02:00
|
|
|
while IFS= read -r line; do
|
2024-08-20 19:48:05 +02:00
|
|
|
echo "* line: $line"
|
2024-08-20 17:29:06 +02:00
|
|
|
case "$line" in
|
|
|
|
"--- "*".zone")
|
2024-08-20 17:40:11 +02:00
|
|
|
NAME=$(echo "$line" .zone | sed 's/--- //' | sed 's|a/||')
|
|
|
|
CURRENT_ZONE=$(basename $NAME)
|
2024-08-20 17:42:37 +02:00
|
|
|
echo "*** Updating $CURRENT_ZONE"
|
2024-08-20 17:29:06 +02:00
|
|
|
;;
|
2024-08-20 17:35:01 +02:00
|
|
|
"--- "*)
|
|
|
|
CURRENT_ZONE=
|
|
|
|
;;
|
2024-08-20 17:29:06 +02:00
|
|
|
"+++"*)
|
|
|
|
;;
|
2024-08-20 19:51:09 +02:00
|
|
|
"-"*IN* | "+"*IN*)
|
2024-08-20 17:36:31 +02:00
|
|
|
if [ ! -z $CURRENT_ZONE ]; then
|
2024-08-20 17:35:01 +02:00
|
|
|
if [[ $line == -* ]]; then # Enregistrement supprimé
|
2024-08-20 19:46:13 +02:00
|
|
|
RECORD=$(echo "$line" | sed 's/^-//' | sed "s/^\([^ ]\+\)\(\s\+\)\(IN\s\+\)\([^ ]\+\)\s.*/\1.${CURRENT_ZONE}.\2\3\4/")
|
2024-08-20 17:49:34 +02:00
|
|
|
echo "update delete $RECORD"
|
2024-08-20 18:10:07 +02:00
|
|
|
echo -e "server ${{vars.DNS_SERVER}}\nupdate delete $RECORD\nsend" > temp_delete
|
2024-08-20 18:35:24 +02:00
|
|
|
nsupdate -k temp_keyfile temp_delete
|
2024-08-20 17:57:43 +02:00
|
|
|
rm temp_delete
|
2024-08-20 17:35:01 +02:00
|
|
|
elif [[ $line == +* ]]; then # Enregistrement ajouté
|
2024-08-20 19:53:27 +02:00
|
|
|
RECORD=$(echo "$line" | sed 's/^+//' | sed "s/^\([^ ]\+\)\(\s\+\)\(IN\s\+\)\([^ ]\+\)\(\s\+\)/\1.${CURRENT_ZONE}.\2\3\4\5/")
|
2024-08-20 18:29:12 +02:00
|
|
|
echo "update add $RECORD"
|
2024-08-20 18:48:39 +02:00
|
|
|
echo -e "server ${{vars.DNS_SERVER}}\nttl 3600\nupdate add $RECORD\nsend" > temp_add
|
2024-08-20 18:35:24 +02:00
|
|
|
nsupdate -k temp_keyfile temp_add
|
2024-08-20 17:57:43 +02:00
|
|
|
rm temp_add
|
2024-08-20 17:35:01 +02:00
|
|
|
fi
|
2024-08-20 17:29:06 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2024-08-20 18:00:55 +02:00
|
|
|
done < zone_diff.txt
|
2024-08-20 19:31:36 +02:00
|
|
|
rm temp_keyfile
|
|
|
|
echo ${{ env.GITHUB_SHA }} > /home/runner/last_run
|