Skip to content
This repository was archived by the owner on Dec 9, 2019. It is now read-only.

Commit c9d59d4

Browse files
authored
[skip ci] search domain to /etc/resolv.conf
1 parent 00f0f96 commit c9d59d4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

cli/stubs/get-dns-servers

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33
WORKDIR="/opt/valet-linux"
44
DNSFILE="${WORKDIR}/dns-servers"
55
LOGFILE="${WORKDIR}/watch.log"
6-
PIDS=""
6+
RESOLV="/etc/resolv.conf"
7+
8+
function unique {
9+
# Function to remove duplicated lines (even when they are not contiguous)
10+
# cat -n puts line numbers
11+
# sort -uk2 sort and remove duplicates (ignoring line numbers)
12+
# sort -nk1 sort by line number
13+
# cut -f2- remove line numbers
14+
cat -n | sort -uk2 | sort -nk1 | cut -f2-
15+
}
716

817
function updateNameservers() {
918
# Read all of the nameserver files at once, filter lines starting with 'nameserver'
1019
# and exclude the ones containing 127.0.0.1 (localhost)
1120

12-
cat "${FILES[@]}" | grep -i '^nameserver' | grep -v '127.0.0.1' | tee "$DNSFILE" &>/dev/null
21+
cat "${FILES[@]}" | grep -i '^nameserver' | grep -v '127.0.0.' | unique | tee "$DNSFILE" &>/dev/null
22+
23+
# Add "search" and "domain" directives to /etc/resolv.conf
24+
chattr -i "$RESOLV" && \
25+
cat "${FILES[@]}" | grep -e '^search' -e '^domain' | unique | tee "$RESOLV" &>/dev/null && \
26+
echo '127.0.0.1' >> "$RESOLV" && \
27+
chattr +i "$RESOLV"
1328
}
1429

1530
function watchFiles() {
@@ -37,7 +52,6 @@ function main() {
3752

3853
for FILE in "${FILES[@]}"; do
3954
watchFiles "$FILE" &
40-
PIDS="$PIDS $!"
4155
done
4256

4357
# Find nameserver files in the /run/resolvconf/interface folder (as they do not have a standard name)
@@ -56,4 +70,4 @@ if [[ ! $(pgrep -f 'inotifywait -q -m -e modify') ]]; then
5670
main
5771
fi
5872

59-
exit 0
73+
exit 0

0 commit comments

Comments
 (0)