Skip to content

Conversation

@diraneyya
Copy link

On Mac OS X and while using wg-quick it is possible that the config base filename be wg1.conf while the actual interface name is something like utun4. In this case, this improvement allows us to enter something like:

sudo ./reresolve-dns.sh /opt/homebrew/etc/wireguard/wg1.conf utun4

(on Mac OS X, when installing wireguard-tools using homebrew, elevated privileges are needed when running wg)

On Mac OS X and while using `wg-quick` it is possible that the config base filename be `wg1.conf` while the actual interface name is something like `utun4`. In this case, this improvement allows us to enter something like:

```bash
sudo ./reresolve-dns.sh /opt/homebrew/etc/wireguard/wg1.conf utun4
```

(on Mac OS X, when installing wireguard-tools using homebrew, elevated privileges are needed when running `wg`)

Signed-off-by: Orwa Diraneyya <[email protected]>
In this improvement, redirecting output using `>>` results in a more meaningful output

Signed-off-by: Orwa Diraneyya <[email protected]>
@diraneyya
Copy link
Author

In the second commit I added better logging when using a cron job:

*/2 * * * *     sudo $HOME/repos/wireguard/reresolve-dns.sh /opt/homebrew/etc/wireguard/wg1.conf utun4 >> /tmp/wireguard-wg1.log

Since the shebang line refers to bash at /bin/bash and since on most Mac OS X systems this location contains an outdated bash version (3.2), I have added a polyfill for the $EPOCHSECONDS env variable which otherwise would lead to this script failing on early bash versions that do not support it.

I took this path because it is always better to support older bash versions regardless of the choice of interpreter and since it was all that we needed to run the script on bash 3.2

Signed-off-by: Orwa Diraneyya <[email protected]>
@diraneyya
Copy link
Author

I noticed that the script was not doing what it is supposed to do on Mac OS X. After some investigations I realised it was the shebang line which refers to /bin/bash, an outdated interpreter (bash 3.2) on many systems.

I have fixed the issue by polyfilling the EPOCHSECONDS ENV variable. A change of the shebang is recommended but I have not made that change.

@diraneyya diraneyya changed the title allow specifying interface name Add support for wireguard-tools on Mac OS X (interface utunX), bash 3.2, and better logging for cron jobs Oct 26, 2025
@diraneyya diraneyya changed the title Add support for wireguard-tools on Mac OS X (interface utunX), bash 3.2, and better logging for cron jobs reresolve-dns.sh: Add support for wireguard-tools on Mac OS X (interface utunX), bash 3.2, and better logging for cron jobs Oct 26, 2025
It is possible now to retain xtrace output for each exit code using carefully crafted cron job invocation while also attaching useful information

Signed-off-by: Orwa Diraneyya <[email protected]>
Signed-off-by: Orwa Diraneyya <[email protected]>
@diraneyya diraneyya changed the title reresolve-dns.sh: Add support for wireguard-tools on Mac OS X (interface utunX), bash 3.2, and better logging for cron jobs reresolve-dns.sh: Add support for wireguard-tools on Mac OS X (interface utunX), debugging, bash 3.2, and improved logging for cron jobs Oct 27, 2025
@diraneyya
Copy link
Author

Recommended cronjob spec:

 * * * *	SUDO_ASKPASS="$HOME"/.config/askpass sudo -A \
	PATH="$PATH:/opt/homebrew/bin" DEBUG=1 \
	"$HOME"/.config/wireguard/reresolve-dns.sh \
	/opt/homebrew/etc/wireguard/wgX.conf utunX \
	>>/tmp/wireguard.log 2>/tmp/wireguard.debug || \
		cp /tmp/wireguard.debug /tmp/wireguard.debug."$?"

This cron job will:

  • Let you know when the endpoint is updated in a log file
  • Maintain an xtrace log for the last successful invocation
  • Maintain the xtrace log for the last failed invocation, for each error code
  • Attach useful information to xtrace logs including the current date, the user used for the invocation, and the PATH env variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant