Mathijs Futselaar - Sr. (Web)Developer

Blog

Sometimes I have things to say, here you'll find a list of all my thoughts I wanted to share with you.

Simple "dynamic dns" script for your cloudflare hosted domains

If you are looking for a simple script that would update a cloudflare dns entry for you like a DDNS service provider, search no longer.

#!/bin/bash

token="<your cloudflare api token>"
zone_id="<the zone id>"
dns_record_id4="<dns record id for ipv4>"
dns_record_id6="<dns record id for ipv6>"
ipv4=$(curl -s https://api.ipify.org)
ipv6=$(curl -s https://api6.ipify.org)

curl https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_record_id4 \
    -X PUT \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $token" \
    -d '{
          "name": "homesweethome.mydomain.com",
          "ttl": 3600,
          "type": "A",
          "content": "'"$ipv4"'"
        }'

curl https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_record_id6 \
    -X PUT \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $token" \
    -d '{
          "name": "homesweethome.mydomain.com",
          "ttl": 3600,
          "type": "AAAA",
          "content": "'"$ipv6"'"
        }'

To acquire the zone and dns record ids, you can run the following commands:

curl https://api.cloudflare.com/client/v4/zones -H "Authorization: Bearer <your cloudflare api token> | jq"

This will give you a nicely formatted list of all the DNS zones the api key has access to. Once you figured out which ID belongs to the domain you need to update, you can run the following command to obtain the record ids:

curl https://api.cloudflare.com/client/v4/zones/<zone_id>/dns_records -H "Authorization: Bearer <your cloudflare api token>" | jq

If your isp does not provide you with an ipv4 or ipv6 address, or if you don't want to use either of them, you can remove all the version references.

Put this in your crontab, system boot scripts or NetworkManager's dispatch directory to automate updating your records.

Add comment »
Date:
Reading time: 1 min
Date:
Reading time: 1 min

Emulate f.lux behaviour with gammastep

Recently I made the concious decision to move from Windows to Linux permanently, after running it in a dual boot system for years. I might explain why in a future post, but for now I just want to share something simple that I made.

One of the tools in Windows that I would always install first was f.lux. It theoretically works on Linux, but as the developer said on the Github repository, it is barely maintained and you should use something else instead.

I ended up using gammastep, since this is a lightweight service that works on Wayland and changes the temperature gradually (this was a big requirement for me). The only f.lux feature it was missing (and one I use a lot) was to "temporarily disable" it.

Continue reading and/or comment »
Date:
Reading time: 1 min