Fix static IP not set if IP is already present in any way inside dhcpcd.conf (#4995)

Use grep and regex to find uncommented use of `static ip_address` with IP.
This commit is contained in:
Dan Schaper 2022-10-31 13:23:35 -07:00 committed by GitHub
commit 871067acd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -828,8 +828,11 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
# Configure networking via dhcpcd # Configure networking via dhcpcd
setDHCPCD() { setDHCPCD() {
# Check if the IP is already in the file # Regex for matching a non-commented static ip address setting
if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}[ \t]*$"
# Check if static IP is already set in file
if grep -xq "${regex}" /etc/dhcpcd.conf; then
printf " %b Static IP already configured\\n" "${INFO}" printf " %b Static IP already configured\\n" "${INFO}"
# If it's not, # If it's not,
else else