-
Notifications
You must be signed in to change notification settings - Fork 48
Added DNS support #51
base: devel
Are you sure you want to change the base?
Conversation
sourceroot/bin/dhcp-query
Outdated
for i in $dns ; do | ||
echo nameserver $i >> /etc/resolv.conf | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable globbing with set -f
; haven't checked whether you could inject wildcards *
via DHCP, but there's no need to take that risk
set -f
if [ -n "${dns}" ]; then
printf 'nameserver %s\n' ${dns} >> /etc/resolv.conf
fi
set +f
printf
implicitly loops over all items in $dns
EDIT: check non-empty dns beforehand, printf might write an empty nameserver
line otherwise.
sourceroot/bin/dhcp-query
Outdated
;; | ||
|
||
echo -n > /etc/resolv.conf | ||
[ -n "$domain" ] && echo search $domain >> /etc/resolv.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use quoting to be safe:
[ -z "${domain}" ] || printf 'search %s\n' "${domain}" >> /etc/resolv.conf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be even futher reduced to [ "${domain}" ] && printf 'search %s\n' "${domain}" >> /etc/resolv.conf
, but I somewhat prefer full if
statements.
sourceroot/bin/dhcp-query
Outdated
echo -n > /etc/resolv.conf | ||
[ -n "$domain" ] && echo search $domain >> /etc/resolv.conf | ||
for i in $dns ; do | ||
echo nameserver $i >> /etc/resolv.conf | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire section could be written as a group writing to /etc/resolv.conf
{
[ -z "${domain}" ] || printf 'search %s\n' "${domain}"
set -f
printf 'nameserver %s\n' ${dns} >> /etc/resolv.conf
set +f
} > /etc/resolv.conf
Your approach bypasses the mechanism that Thus, it might be better to add |
@dywisor thanks! I agree, it would be better to just have |
I have started again based on feedback, and if you want to take a look, I pushed it to: dns-3 for now. |
@dywisor @slashbeast OK, I pushed to https://github.com/unqueued/better-initramfs/tree/dns Now, not just is dns accepted from the dhcp server, but the dns servers can be overriden with I can rebase it also since it looks like it's a bit behind. |
If you have another branch (dns instead of dns-feature) can you update this pull request or otherwise load the dns-feature with the changes you'd like to be merged? |
@slashbeast Ok, it has been four years, but I reviewed everything and updated it. When |
If this is getting overly complicated, I could just have it so that all of the network settings are overriden when |
@slashbeast I trimmed it down quite a bit, if you want it. I'm currently using it because I want to have the option of 1) using curl to invoke ntfy.sh to alert me when one of my machines boots, and 2) minimal upnp client, which is really helpful if you are behind NAT. Upnp is simple enough to just need bash and curl. |
I can think of a few ways to have done this. Is this way keeping in line with how it should be done?