name: DNS automated deployment on: push: branches: - 'main' jobs: deploy: runs-on: linux_amd64 steps: - name: Apply zone changes shell: bash run: | LAST_RUN=$(cat /home/runner/last_run) CURRENT_ZONE= echo "Preparing to update ${{ vars.DNS_SERVER }}..." git clone ${{ gitea.server_url }}/${{ gitea.repository }} dns cd dns git diff $LAST_RUN ${{ env.GITHUB_SHA }} > zone_diff.txt echo "${{ secrets.TSIG_KEY }}" | base64 -d > temp_keyfile while IFS= read -r line; do echo "* line: $line" case "$line" in "--- "*".zone") NAME=$(echo "$line" .zone | sed 's/--- //' | sed 's|a/||') CURRENT_ZONE=$(basename $NAME) echo "*** Updating $CURRENT_ZONE" ;; "--- "*) CURRENT_ZONE= ;; "+++"*) ;; "-"*IN* | "+"*IN*) if [ ! -z $CURRENT_ZONE ]; then if [[ $line == -* ]]; then # Enregistrement supprimé RECORD=$(echo "$line" | sed 's/^-//' | sed "s/^\([^ ]\+\)\(\s\+\)\(IN\s\+\)\([^ ]\+\)\s.*/\1.${CURRENT_ZONE}.\2\3\4/") echo "update delete $RECORD" echo -e "server ${{vars.DNS_SERVER}}\nupdate delete $RECORD\nsend" > temp_delete nsupdate -k temp_keyfile temp_delete rm temp_delete elif [[ $line == +* ]]; then # Enregistrement ajouté RECORD=$(echo "$line" | sed 's/^+//' | sed 's/^\([^ ]\+\)\(\s\+\)\(IN\s\+\)\([^ ]\+\)\(\s\+\)/\1.{CURRENT_ZONE}.\2\3\4\5/') echo "update add $RECORD" echo -e "server ${{vars.DNS_SERVER}}\nttl 3600\nupdate add $RECORD\nsend" > temp_add nsupdate -k temp_keyfile temp_add rm temp_add fi fi ;; esac done < zone_diff.txt rm temp_keyfile echo ${{ env.GITHUB_SHA }} > /home/runner/last_run