#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset -o errtrace -o functrace

update_url=https://infomaniak.com/nic/update
subdomains=(finance git home homebox import.finance komga mail matrix mealie navidrome nextcloud nexus odoo overleaf paperless photos pihole tasks torrent wallabag wiki zigbee)
data_file="${HOME}/.dyndns"
file="${HOME}/tmp_data.txt"
for subdomain in "${subdomains[@]}"; do
  sed -e "s/gtache.ch/${subdomain}.gtache.ch/" "${data_file}" >| "${file}"
  curl -4 -d "@${file}" -X POST "${update_url}"
  curl -6 -d "@${file}" -X POST "${update_url}"
done
curl -4 -d "@${data_file}" -X POST "${update_url}"
curl -6 -d "@${data_file}" -X POST "${update_url}"
rm -f "${file}"
