mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-27 05:06:39 +00:00
Add experimental support for /etc/network/interfaces
This commit is contained in:
parent
fb6cf25241
commit
15c07e362e
@ -1,12 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
DH_CONF="/var/cache/dhclient.conf"
|
DH_CONF="/var/cache/dhclient.conf"
|
||||||
|
WATCH_CONF="/data/etc/watch.conf"
|
||||||
|
|
||||||
SYS_STATIC_CONF="/etc/static_ip.conf"
|
SYS_STATIC_CONF="/etc/static_ip.conf"
|
||||||
BOOT_STATIC_CONF="/boot/static_ip.conf"
|
BOOT_STATIC_CONF="/boot/static_ip.conf"
|
||||||
STATIC_CONF="/data/etc/static_ip.conf"
|
STATIC_CONF="/data/etc/static_ip.conf"
|
||||||
WATCH_CONF="/data/etc/watch.conf"
|
|
||||||
|
|
||||||
LINK_NEGO_TIMEOUT=10
|
SYS_INTERFACES_CONF="/etc/network/interfaces"
|
||||||
|
BOOT_INTERFACES_CONF="/boot/network/interfaces"
|
||||||
|
INTERFACES_CONF="/data/etc/network/interfaces"
|
||||||
|
|
||||||
|
|
||||||
test -n "${OS_VERSION}" || source /etc/init.d/base
|
test -n "${OS_VERSION}" || source /etc/init.d/base
|
||||||
@ -16,6 +19,8 @@ source ${WATCH_CONF}
|
|||||||
prepare_conf ${STATIC_CONF} ${SYS_STATIC_CONF} ${BOOT_STATIC_CONF}
|
prepare_conf ${STATIC_CONF} ${SYS_STATIC_CONF} ${BOOT_STATIC_CONF}
|
||||||
test -r ${STATIC_CONF} && source ${STATIC_CONF}
|
test -r ${STATIC_CONF} && source ${STATIC_CONF}
|
||||||
|
|
||||||
|
prepare_conf ${INTERFACES_CONF} ${SYS_INTERFACES_CONF} ${BOOT_INTERFACES_CONF}
|
||||||
|
|
||||||
mkdir -p /var/lib/dhcp
|
mkdir -p /var/lib/dhcp
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +62,11 @@ watch_ip() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start_lo() {
|
start_lo() {
|
||||||
|
if [[ -r ${INTERFACES_CONF} ]] && grep -q "^iface lo" ${INTERFACES_CONF}; then
|
||||||
|
ifup lo 2>&1 | logger -t network
|
||||||
|
else
|
||||||
ifconfig lo up
|
ifconfig lo up
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start_wlan() {
|
start_wlan() {
|
||||||
@ -76,6 +85,10 @@ start_wlan() {
|
|||||||
ip link set mtu ${mtu} dev ${OS_WLAN}
|
ip link set mtu ${mtu} dev ${OS_WLAN}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -r ${INTERFACES_CONF} ]] && grep -q "^iface ${OS_WLAN}" ${INTERFACES_CONF}; then
|
||||||
|
ifup ${OS_WLAN} 2>&1 | logger -t network
|
||||||
|
test ${PIPESTATUS[0]} == 0 && msg_done || msg_fail
|
||||||
|
else
|
||||||
if [[ -n "${STATIC_IP}" ]]; then
|
if [[ -n "${STATIC_IP}" ]]; then
|
||||||
msg_done ${STATIC_IP}
|
msg_done ${STATIC_IP}
|
||||||
ifconfig ${OS_WLAN} ${STATIC_IP} up
|
ifconfig ${OS_WLAN} ${STATIC_IP} up
|
||||||
@ -84,6 +97,7 @@ start_wlan() {
|
|||||||
msg_done dhcp
|
msg_done dhcp
|
||||||
dhclient -cf "${DH_CONF}" ${OS_WLAN}
|
dhclient -cf "${DH_CONF}" ${OS_WLAN}
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${IP_WATCH}" == "true" ]] && ip addr show dev ${OS_WLAN} | grep inet &>/dev/null; then
|
if [[ "${IP_WATCH}" == "true" ]] && ip addr show dev ${OS_WLAN} | grep inet &>/dev/null; then
|
||||||
watch_ip ${OS_WLAN} &
|
watch_ip ${OS_WLAN} &
|
||||||
@ -121,12 +135,11 @@ start_eth() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
# wait for link
|
# wait for link
|
||||||
test "${LINK_WATCH}" == "true" || LINK_NEGO_TIMEOUT=5
|
|
||||||
count=0
|
count=0
|
||||||
while [[ "$(cat /sys/class/net/${OS_ETH}/carrier 2>&1)" != "1" ]]; do
|
while [[ "$(cat /sys/class/net/${OS_ETH}/carrier 2>&1)" != "1" ]]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
count=$((${count} + 1))
|
count=$((${count} + 1))
|
||||||
if [[ ${count} -ge ${LINK_NEGO_TIMEOUT} ]]; then
|
if [[ ${count} -ge 1 ]]; then
|
||||||
msg_done "no link"
|
msg_done "no link"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -136,6 +149,10 @@ start_eth() {
|
|||||||
ip link set mtu ${mtu} dev ${OS_ETH}
|
ip link set mtu ${mtu} dev ${OS_ETH}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -r ${INTERFACES_CONF} ]] && grep -q "^iface ${OS_ETH}" ${INTERFACES_CONF}; then
|
||||||
|
ifup ${OS_ETH} 2>&1 | logger -t network
|
||||||
|
test ${PIPESTATUS[0]} == 0 && msg_done || msg_fail
|
||||||
|
else
|
||||||
if [[ -n "${STATIC_IP}" ]]; then
|
if [[ -n "${STATIC_IP}" ]]; then
|
||||||
msg_done ${STATIC_IP}
|
msg_done ${STATIC_IP}
|
||||||
ifconfig ${OS_ETH} ${STATIC_IP} up
|
ifconfig ${OS_ETH} ${STATIC_IP} up
|
||||||
@ -144,6 +161,7 @@ start_eth() {
|
|||||||
msg_done dhcp
|
msg_done dhcp
|
||||||
dhclient -cf "${DH_CONF}" ${OS_ETH}
|
dhclient -cf "${DH_CONF}" ${OS_ETH}
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${LINK_WATCH}" == "true" ]]; then
|
if [[ "${LINK_WATCH}" == "true" ]]; then
|
||||||
watch_eth &
|
watch_eth &
|
||||||
@ -163,16 +181,11 @@ start() {
|
|||||||
test "${OS_NETWORKLESS}" == "true" && return 0
|
test "${OS_NETWORKLESS}" == "true" && return 0
|
||||||
|
|
||||||
ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
|
ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
|
||||||
test -n "${ssid}" && start_wlan && wlan_ok="ok"
|
test -n "${OS_WLAN}" -a -n "${ssid}" && start_wlan && wlan_ok="ok"
|
||||||
|
|
||||||
test -r /data/etc/ppp/modem && ifconfig | grep ${OS_PPP} &>/dev/null && ppp_ok="ok"
|
test -n "${OS_PPP}" -a -r /data/etc/ppp/modem && ifconfig | grep ${OS_PPP} &>/dev/null && ppp_ok="ok"
|
||||||
|
|
||||||
# if wifi or ppp link ok, start eth in background
|
test -n "${OS_ETH}" && start_eth && eth_ok="ok"
|
||||||
if [[ "${wlan_ok}" == "ok" ]] || [[ "${ppp_ok}" == "ok" ]]; then
|
|
||||||
start_eth &>/dev/null &
|
|
||||||
else
|
|
||||||
start_eth && eth_ok="ok"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${eth_ok}" != "ok" ]] && [[ "${wlan_ok}" != "ok" ]] && [[ "${ppp_ok}" != "ok" ]]; then
|
if [[ "${eth_ok}" != "ok" ]] && [[ "${wlan_ok}" != "ok" ]] && [[ "${ppp_ok}" != "ok" ]]; then
|
||||||
if [[ "${LINK_WATCH}" == "true" ]]; then
|
if [[ "${LINK_WATCH}" == "true" ]]; then
|
||||||
@ -185,6 +198,15 @@ start() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -r ${INTERFACES_CONF} ]]; then
|
||||||
|
# ifup doesn't set the DNS server, so we have to set it manually
|
||||||
|
STATIC_DNS=$(cat /etc/network/interfaces | grep dns-nameserver | tr -s ' ' | cut -d ' ' -f 3 | head -n 11)
|
||||||
|
if [[ -n "${STATIC_DNS}" ]]; then
|
||||||
|
msg_begin "Setting static DNS server to ${STATIC_DNS}"
|
||||||
|
echo "nameserver ${STATIC_DNS}" > /etc/resolv.conf
|
||||||
|
test $? == 0 && msg_done || msg_fail
|
||||||
|
fi
|
||||||
|
else
|
||||||
if [[ -n "${STATIC_GW}" ]]; then
|
if [[ -n "${STATIC_GW}" ]]; then
|
||||||
msg_begin "Setting static gateway to ${STATIC_GW}"
|
msg_begin "Setting static gateway to ${STATIC_GW}"
|
||||||
ip route add default via ${STATIC_GW}
|
ip route add default via ${STATIC_GW}
|
||||||
@ -196,12 +218,14 @@ start() {
|
|||||||
echo "nameserver ${STATIC_DNS}" > /etc/resolv.conf
|
echo "nameserver ${STATIC_DNS}" > /etc/resolv.conf
|
||||||
test $? == 0 && msg_done || msg_fail
|
test $? == 0 && msg_done || msg_fail
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
msg_begin "Stopping network"
|
msg_begin "Stopping network"
|
||||||
killall dhclient &>/dev/null
|
ifdown -a 2>&1 | logger -t network
|
||||||
ps | grep S40network | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
|
ps | grep S40network | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
|
||||||
|
killall dhclient &>/dev/null
|
||||||
msg_done
|
msg_done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user