libreelec-conf/set-resolv-conf.sh

21 lines
532 B
Bash
Executable File

#!/usr/bin/env bash
# TODO review entirely:
# * use DNS variable to set the first nameserver line
# * add an "ExecStop" to service, and a script to remove that first line
# count lines in resolv.conf
lines=$(cat /run/libreelec/resolv.conf | wc -l)
# count number of 'nameserver' entries
count=$(grep -c 'nameserver' /run/libreelec/resolv.conf)
# move last entry to top
i=$((0))
while [ $((count)) -gt 1 ]; do
sed -i -n "$((lines - i - 1)){h;n;G};p" /run/libreelec/resolv.conf
count=$((count - 1))
i=$((i + 1))
done
exit 0