Using sed editor to edit TOML

i need to reinstall openwrt and this time, instead of using dnsmasq/stubby to get dnssec, i'm switching to dnscrypt-proxy2. i've looked at openwrt's dnscrypt-proxy2 documentation and it shows an example text:
sed -i "32 s/./server_names = ['google', 'cloudflare']/" /etc/dnscrypt-proxy2/.toml

so my deductive reasoning says i can do the following in order to edit the other entries for dnscrypt-proxy2 in its toml:
sed -i "32 s/./server_names = ['scaleway-ams']/" /etc/dnscrypt-proxy2/.toml
sed -i "70 s/./doh_servers = false" /etc/dnscrypt-proxy2/.toml
sed -i "79 s/./require_dnssec = true" /etc/dnscrypt-proxy2/.toml

did i do those above 3 lines correctly?
also, i'm now at line 201...how do i tell sed to remove the # so that line is enabled? example, i need the line in the toml to read cert_ignore_timestamp = true

lastly, am i able to paste this above code into the "Script to run on first boot (uci-defaults)" field of the firmware-selector tool when i've built the firmware to include the dnscrypt-proxy2 package so that when i go to install openwrt to my box it will be set up?

thanks

references:
https:// openwrt.org/docs/guide-user/services/dns/dnscrypt_dnsmasq_dnscrypt-proxy2
https:// github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml
https:// firmware-selector.openwrt.org/
(sorry, added a space in each link so it wouldn't add the website previews)

Without going into the substance of what you want to do, I'll just address the question related to the use of sed.
sed may be touchy, so I'd recommend you to test each command in isolation. For example:
echo test | sed "s/.*/server_names = ['scaleway-ams', 'scaleway-fr']/"
This should produce this output:
server_names = ['scaleway-ams', 'scaleway-fr']

More detailed explanation. Maybe you have figured all of this out on you own but just in case.

sed -i modifies files in-place. Meaning that it edits an existing file rather than taking an input and writing output into specified file.

The number following the 'sed -i' command is the line number. So first thing, double check that it matches the intended line in each file you are telling sed to modify. Just to make sure that you are aware of this, /etc/dnscrypt-proxy2/*.toml matches all files in that directory with the .toml extension.

The s command in sed means substitute text. The general syntax is s/<pattern>/<replacement_string>/

The .* pattern means match any and all text in the pattern space. In this instance this will match the entire line.

1 Like

this is immensely helpful, thank you antonk...i think it might be better if i just do the tweaks manually using vi post install vs trying to automate

really good news is that i figured out that if i only copy in the exact text from openwrt's documentation page for dnscrypt-proxy2, into the firmware selector tool, that code works perfectly...all around everything worked out and i'll stay away from sed for now

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.