Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement Request for Static IP Configuration File Parsing #243

Open
NightowlKr opened this issue Jan 3, 2025 · 1 comment
Open

Improvement Request for Static IP Configuration File Parsing #243

NightowlKr opened this issue Jan 3, 2025 · 1 comment

Comments

@NightowlKr
Copy link

Issue:
script file"/etc/init.d/S30eth" fails to handle comments in "/boot/eth.nodhcp"

Suggested fix:
Add a filter to ignore comments in the /boot/eth.nodhcp file, using:

cat /boot/eth.nodhcp | grep -v '^#' | while read inet gw

Proposed code file "/etc/init.d/S30eth" change:

start() {
    printf "start ethernet: "
    if [ -e /boot/eth.nodhcp ]
    then
        [ -e /boot/eth.nodhcp ] &&
            cat /boot/eth.nodhcp | grep -v '^#'  | while read inet gw
            do
                addr=${inet%/*}
                netid=${inet#*/}
                [ -z $gw ] &&
                gw=$( echo $addr| ( IFS='.' read a b c d; echo $((
                    (((((($a<<8)+$b)<<8)+$c)<<8)+$d)
                        & (((1<<$netid)-1)<<(32-$netid))
                    ))
                )) &&
                gw=$(($gw>>24&0xff)).$(($gw>>16&0xff)).$(($gw>>8&0xff)).$((1+( $gw>>0&0xff )))

                arping -Dqc2 -Ieth0 $addr || continue
                ip a add $inet brd + dev eth0
                ip r add default via $gw dev eth0
                cat > /etc/resolve.conf << EOF
nameserver $gw
nameserver 8.8.8.8
nameserver 114.114.114.114
EOF
                break
            done &&
            ip a show dev eth0|grep inet || (
                udhcpc -i eth0 -t 3 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &>/dev/null
                ip a show dev eth0|grep inet
            ) || (
                # failed to apply dynamic addr, need a available static addr to visit the LAN
                inet=$RESERVE_INET
                addr=${inet%/*}
                ip a add $inet brd + dev eth0
            ) || exit 1
    else
        (udhcpc -i eth0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid) &
    fi

    echo "OK"
}
@archont94
Copy link

I think it would be even better to add yq binary and read configs from YAML files.

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

No branches or pull requests

2 participants