Skip to content

Conversation

jesusalc
Copy link

@jesusalc jesusalc commented May 7, 2025

I fixed several bash errors
But I would like discuss and then apply fix for "offline valet problem"
This is the bit the results in removing communication from the outside world.
Does anyone knows more about this piece of code ?
These are my observations

in valet-dns

right after line 63

symlinkResolv

# @WHY ?
# This line under creates an empty file ...why ?
# why:   cat "${FILES[@]}" | grep -v '^nameserver' | grep -v '^#' | unique | tee "$VRESOLV" &>/dev/null
#      = same  grep -v '^nameserver' "${FILES[@]}" | grep -v '^#' | unique | tee "$VRESOLV" &>/dev/null
# And this line then adds 127 alone into the resolv.conf
# why: echo 'nameserver 127.0.0.1' >> "$VRESOLV"
# the result in localhost is to efectively remove all access to the
# outsite world
# I would like to know what is the expectation and why is this like
# this

# I suggest passing local 127 first when creating the resolv.conf
echo 'nameserver 127.0.0.1' > "$VRESOLV"
# Here are appending the gateway given by the network interface
# to keep laptop online
# I don't why we need t remove any comments ?
grep -E '^nameserver|^#' "${FILES[@]}" | unique | tee -a "$VRESOLV" &>/dev/null

Copy link

sonarqubecloud bot commented May 7, 2025

cat "$DNSHEAD" | unique | tee "$DNSFILE" &>/dev/null
cat "${FILES[@]}" | grep -i '^nameserver' | grep -vE '127\.(0\.){2}\d{1,3}' | unique | tee -a "$DNSFILE" &>/dev/null
unique < "$DNSHEAD" | tee "$DNSFILE" &>/dev/null
grep -i '^nameserver' "${FILES[@]}" | grep -vE '127\.(0\.){2}{1,3}' | unique | tee -a "$DNSFILE" &>/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex seems incorrect

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it the \d you are referring to? I cannot remember why I removed. Need to check again


# I suggest passing local 127 first when creating the resolv.conf
echo 'nameserver 127.0.0.1' > "$VRESOLV"
# Here are appending the gateway given by the network interface
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this comments (there are a lot of typos) and explain why are you changing this. I do not understand why we need this...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding has been that we need this line for the resolv DNS to work, it seems that not all Linux are working the same. So, I found other users complain about how "after valet" internet connectivity is gone, I had the same issue. But it was very random. That means that sometimes it will work, and sometimes it will fail. This line seems to fix the issue. That is why I added the comments. Which I don't mind removing. But perhaps some one else can validate this concept ?

@@ -134,7 +149,7 @@ function start {
else
echo -e "Starting Valet DNS Watcher..."
main
sleep 2 && echo $(pgrep -f 'inotifywait -q -m -e modify') > "${WORKDIR}/watch.pid"
sleep 2 && pgrep -f 'inotifywait -q -m -e modify' > "${WORKDIR}/watch.pid"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the echo?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a "useless echo" you don't need "echo" wrap the output of a sub-process only calling grep, was there a special reason for that? From this side of the woods, echo was not needed, unless I am missing something, then I am open to learn about it.

@@ -99,7 +114,7 @@ function watchDirs() {
done

# Watch directories for changes in files
inotifywait -q -m -e modify -e create -e delete --format "%w%f" "${WATCHERS[@]}" | while read change; do
inotifywait -q -m -e modify -e create -e delete --format "%w%f" "${WATCHERS[@]}" | while read -r __change; do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing you are referring to this "change" to "change." From my experience, it is good practice to use "" to indicate that a variable is not going to be used. Normally, in other languages that is the practice. But in Bash many programmers use "" are internal variables, so for non-used then add double "". So the shell check linker can also ignore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants