DDNS w/ Linode v4 [SOLVED]

Are there any scripts for the built in DDNS that work with Linode v4? The new Linode API doesn't work with API tokens in the URL parameters, instead it must be sent via header. Are there any build in services that do this? Maybe an example I can use to adapt my own for Linode v4?

There are scripts out there kicked off with a cron entry, but I am looking for a way to use the built in DDNS system if possible. Cleaner.

After some digging around it looks like there's a Digital Ocean v2 script on OpenWRT's github. It uses headers to authenticate in the same way Linode does. Now I will need to figure out where that script even goes. I'll post back here in case anyone else uses Linode/OpenWRT/DDNS as well.

LINK: https://github.com/openwrt/packages/blob/master/net/ddns-scripts/files/usr/lib/ddns/update_digitalocean_com_v2.sh

Here's the code updated for Linode v4. It appears to be working correctly on my side. Let me know if anything could be done better or if anything was missed. If you know how to get this added to OpenWRT, or at least their github, let me know. I'm not a developer, idk.


# Script for sending user defined updates using the Linode v4 API
# 2015 Artem Yakimenko <code at temik dot me>
# 2021 George Giannou <giannoug at gmail dot com>
# 2024 bluonek  <https://forum.openwrt.org>

# Options passed from /etc/config/ddns:
# domain - Linode domain id (e.g. 1325552)
# password - Linode personal access token (API key)
# param_opt - Linode API record ID of the A/AAAA record (e.g. 21694203)

# Use the following command to find your Linode API domain ID (replace TOKEN with your own):
# curl -X GET -H 'Content-Type: application/json' \
# 	-H "Authorization: Bearer TOKEN" \
# 	"https://api.linode.com/v4/domains"

# Then use the following command to find your Linode API resource ID (replace TOKEN with your own, and DOMAIN with the domain ID from the previous command):
# curl -X GET -H 'Content-Type: application/json' \
# 	-H "Authorization: Bearer TOKEN" \
# 	"https://api.linode.com/v4/domains/DOMAIN/records"

. /usr/share/libubox/jshn.sh

[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing domain name as 'Domain'"
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing personal access token as 'Password'"
[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing API domain resource ID as 'Optional Parameter'"

# Construct JSON payload
json_add_string target "$__IP"

__STATUS=$(curl -Ss -X PUT "https://api.linode.com/v4/domains/${domain}/records/${param_opt}" \
	-H "Authorization: Bearer ${password}" \
	-H "Content-Type: application/json" \
	-d "$(json_dump)" \
	-w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)

if [ $? -ne 0 ]; then
	write_log 14 "Curl failed: $(cat $ERRFILE)"
	return 1
elif [ -z $__STATUS ] || [ $__STATUS != 200 ]; then
	write_log 14 "Curl failed: $__STATUS \nlinode.com answered: $(cat $DATFILE)"
	return 1


config ddns 'global'
    option ddns_dateformat '%F %R'
    option ddns_loglines '250'
    option ddns_rundir '/var/run/ddns'
    option ddns_logdir '/var/log/ddns'

config service 'your_domain_com'
    option lookup_host 'your.domain.com'
    option domain '1325552'
    option password 'your_token_goes_here'
    option param_opt '21694203'
    option update_script '/usr/lib/ddns/update_linode_com_v4.sh'
    option interface 'wan'
    option ip_source 'network'
    option ip_network 'wan'
    option use_https '1'
    option use_syslog '1'
    option cacert '/etc/ssl/certs'
    option use_ipv6 '0'
    option check_interval '1'
    option check_unit 'hours'
    option enabled '1'