reresolve-dns.sh: Add support for wireguard-tools on Mac OS X (interface utunX), debugging, bash 3.2, and improved logging for cron jobs#28
Open
diraneyya wants to merge 5 commits intoWireGuard:masterfrom
Conversation
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]>
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]>
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 I have fixed the issue by polyfilling the |
utunX), bash 3.2, and better logging for cron jobs
utunX), bash 3.2, and better logging for cron jobsutunX), bash 3.2, and better logging for cron jobs
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]>
utunX), bash 3.2, and better logging for cron jobsutunX), debugging, bash 3.2, and improved logging for cron jobs
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Mac OS X and while using
wg-quickit is possible that the config base filename bewg1.confwhile the actual interface name is something likeutun4. In this case, this improvement allows us to enter something like:(on Mac OS X, when installing wireguard-tools using homebrew, elevated privileges are needed when running
wg)