mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 14:16:31 +00:00
added proper networkless support
This commit is contained in:
parent
70730ff498
commit
ce5d1b27b3
@ -1,37 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
sys_conf="/etc/os.conf"
|
||||
boot_conf="/boot/os.conf"
|
||||
conf="/data/etc/os.conf"
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
|
||||
mount_fs() {
|
||||
msg_begin "Mounting filesystems"
|
||||
/bin/mount -a
|
||||
test $? == 0 && msg_done || msg_fail
|
||||
}
|
||||
|
||||
if ! [ -f $conf ]; then
|
||||
if [ -f $boot_conf ]; then
|
||||
cp $boot_conf $conf
|
||||
elif [ -f $sys_conf ]; then
|
||||
cp $sys_conf $conf
|
||||
fi
|
||||
fi
|
||||
remount_rw() {
|
||||
msg_begin "Remounting boot partition read-write"
|
||||
mount -o remount,rw /boot
|
||||
test $? == 0 && msg_done || msg_fail
|
||||
|
||||
if [ -f $conf ]; then
|
||||
source $conf
|
||||
fi
|
||||
|
||||
if [ "$os_debug" == "true" ]; then
|
||||
msg_begin "Remounting boot partition read-write"
|
||||
mount -o remount,rw /boot
|
||||
test $? == 0 && msg_done || msg_fail
|
||||
|
||||
msg_begin "Remounting root partition read-write"
|
||||
mount -o remount,rw /
|
||||
test $? == 0 && msg_done || msg_fail
|
||||
fi
|
||||
msg_begin "Remounting root partition read-write"
|
||||
mount -o remount,rw /
|
||||
test $? == 0 && msg_done || msg_fail
|
||||
}
|
||||
|
||||
mk_tty_login() {
|
||||
@ -42,6 +26,8 @@ mk_tty_login() {
|
||||
case "$1" in
|
||||
start)
|
||||
mount_fs
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
test "$os_debug" == "true" && remount_rw
|
||||
mk_tty_login
|
||||
;;
|
||||
|
||||
|
@ -6,7 +6,6 @@ conf="/data/etc/wpa_supplicant.conf"
|
||||
|
||||
log="/var/log/wpa_supplicant.log"
|
||||
prog="/usr/sbin/wpa_supplicant"
|
||||
iface=wlan0
|
||||
driver=wext
|
||||
|
||||
sys_watch_conf="/etc/watch.conf"
|
||||
@ -40,9 +39,12 @@ ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
|
||||
test -n "$ssid" || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
test "$os_networkless" == "true" && exit 0
|
||||
|
||||
connected() {
|
||||
ip link show dev $iface 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1
|
||||
ip link show dev $os_wlan 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1
|
||||
}
|
||||
|
||||
watch() {
|
||||
@ -68,7 +70,7 @@ start() {
|
||||
|
||||
# wait up to 5 seconds for interface
|
||||
count=0
|
||||
while ! ifconfig $iface >/dev/null 2>&1; do
|
||||
while ! ifconfig $os_wlan >/dev/null 2>&1; do
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge 5 ]; then
|
||||
@ -77,10 +79,10 @@ start() {
|
||||
fi
|
||||
done
|
||||
|
||||
module=$(basename $(readlink /sys/class/net/$iface/device/driver/module 2>/dev/null) 2>/dev/null)
|
||||
module=$(basename $(readlink /sys/class/net/$os_wlan/device/driver/module 2>/dev/null) 2>/dev/null)
|
||||
|
||||
iwconfig $iface power off &> /dev/null
|
||||
$prog -i$iface -c$conf -D$driver -B &> $log
|
||||
iwconfig $os_wlan power off &> /dev/null
|
||||
$prog -i$os_wlan -c$conf -D$driver -B &> $log
|
||||
count=0
|
||||
while true; do
|
||||
sleep 1
|
||||
|
@ -5,7 +5,6 @@ boot_conf="/boot/ppp"
|
||||
conf="/data/etc/ppp"
|
||||
|
||||
prog="/usr/sbin/pppd"
|
||||
dev="ppp0"
|
||||
provider="mobile"
|
||||
|
||||
watch_conf="/data/etc/watch.conf"
|
||||
@ -24,9 +23,12 @@ test -e $conf/modem || exit 0
|
||||
test -e $conf/apn || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
test "$os_networkless" == "true" && exit 0
|
||||
|
||||
connected() {
|
||||
ifconfig | grep $dev &>/dev/null 2>&1 && return 0 || return 1
|
||||
ifconfig | grep $os_ppp &>/dev/null 2>&1 && return 0 || return 1
|
||||
}
|
||||
|
||||
watch() {
|
||||
|
@ -11,10 +11,7 @@ link_watch=yes
|
||||
link_watch_timeout=20
|
||||
ip_watch=yes
|
||||
ip_watch_timeout=40
|
||||
|
||||
link_nego_timeout=10
|
||||
eth=eth0
|
||||
wlan=wlan0
|
||||
|
||||
test -r $watch_conf && source $watch_conf
|
||||
|
||||
@ -29,12 +26,13 @@ fi
|
||||
test -r $static_conf && source $static_conf
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
watch_eth() {
|
||||
count=0
|
||||
while true; do
|
||||
sleep 5
|
||||
if [ "$(cat /sys/class/net/$eth/operstate 2>/dev/null)" == "up" ]; then
|
||||
if [ "$(cat /sys/class/net/$os_eth/operstate 2>/dev/null)" == "up" ]; then
|
||||
count=0
|
||||
else
|
||||
if [ $count -lt $link_watch_timeout ]; then
|
||||
@ -73,65 +71,70 @@ start_lo() {
|
||||
|
||||
start_wlan() {
|
||||
msg_begin "Configuring wireless network"
|
||||
if ! ifconfig $wlan &>/dev/null; then
|
||||
if ! ifconfig $os_wlan &>/dev/null; then
|
||||
msg_fail "no device"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$(cat /sys/class/net/$wlan/carrier 2>/dev/null)" != "1" ]; then
|
||||
if [ "$(cat /sys/class/net/$os_wlan/carrier 2>/dev/null)" != "1" ]; then
|
||||
msg_fail "no link"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -n "$mtu" ]; then
|
||||
ip link set mtu $mtu dev $wlan
|
||||
ip link set mtu $mtu dev $os_wlan
|
||||
fi
|
||||
|
||||
if [ -n "$static_ip" ]; then
|
||||
msg_done $static_ip
|
||||
ifconfig $wlan $static_ip up
|
||||
ifconfig $os_wlan $static_ip up
|
||||
static_ip="" # won't be used again
|
||||
else
|
||||
msg_done dhcp
|
||||
dhclient -cf "$dh_conf" $wlan
|
||||
dhclient -cf "$dh_conf" $os_wlan
|
||||
fi
|
||||
|
||||
if [ "$ip_watch" == "yes" ] && ip addr show dev $wlan | grep inet &>/dev/null; then
|
||||
watch_ip $wlan &
|
||||
if [ "$ip_watch" == "yes" ] && ip addr show dev $os_wlan | grep inet &>/dev/null; then
|
||||
watch_ip $os_wlan &
|
||||
fi
|
||||
}
|
||||
|
||||
start_eth() {
|
||||
msg_begin "Configuring wired network"
|
||||
|
||||
# wait up to 3 seconds for driver
|
||||
# wait for driver
|
||||
w=3
|
||||
test "$link_watch" == "yes" || w=1
|
||||
count=0
|
||||
while ! ifconfig $eth >/dev/null 2>&1; do
|
||||
while ! ifconfig $os_eth >/dev/null 2>&1; do
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge 3 ]; then
|
||||
if [ $count -ge $w ]; then
|
||||
msg_done "no device"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# bring it up
|
||||
ifconfig $eth up
|
||||
ifconfig $os_eth up
|
||||
|
||||
# wait up to 3 seconds for operstate
|
||||
# wait for operstate
|
||||
w=3
|
||||
test "$link_watch" == "yes" || w=1
|
||||
count=0
|
||||
while [ "$(cat /sys/class/net/$eth/operstate 2>&1)" == "unknown" ]; do
|
||||
while [ "$(cat /sys/class/net/$os_eth/operstate 2>&1)" == "unknown" ]; do
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge 3 ]; then
|
||||
if [ $count -ge $w ]; then
|
||||
msg_done "no link"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# wait up to $link_nego_timeout seconds for link
|
||||
# wait for link
|
||||
test "$link_watch" == "yes" || link_nego_timeout=3
|
||||
count=0
|
||||
while [ "$(cat /sys/class/net/$eth/carrier 2>&1)" != "1" ]; do
|
||||
while [ "$(cat /sys/class/net/$os_eth/carrier 2>&1)" != "1" ]; do
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge $link_nego_timeout ]; then
|
||||
@ -141,24 +144,24 @@ start_eth() {
|
||||
done
|
||||
|
||||
if [ -n "$mtu" ]; then
|
||||
ip link set mtu $mtu dev $eth
|
||||
ip link set mtu $mtu dev $os_eth
|
||||
fi
|
||||
|
||||
if [ -n "$static_ip" ]; then
|
||||
msg_done $static_ip
|
||||
ifconfig $eth $static_ip up
|
||||
ifconfig $os_eth $static_ip up
|
||||
static_ip="" # won't be used again
|
||||
else
|
||||
msg_done dhcp
|
||||
dhclient -cf "$dh_conf" $eth
|
||||
dhclient -cf "$dh_conf" $os_eth
|
||||
fi
|
||||
|
||||
if [ "$link_watch" == "yes" ]; then
|
||||
watch_eth &
|
||||
fi
|
||||
|
||||
if [ "$ip_watch" == "yes" ] && ip addr show dev $eth | grep inet &>/dev/null; then
|
||||
watch_ip $eth &
|
||||
if [ "$ip_watch" == "yes" ] && ip addr show dev $os_eth | grep inet &>/dev/null; then
|
||||
watch_ip $os_eth &
|
||||
fi
|
||||
}
|
||||
|
||||
@ -166,10 +169,11 @@ start() {
|
||||
hostname=$(hostname)
|
||||
echo "send host-name = \"$hostname\";" > /var/cache/dhclient.conf
|
||||
|
||||
ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
|
||||
|
||||
start_lo
|
||||
|
||||
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)
|
||||
test -n "$ssid" && start_wlan && wlan_ok="ok"
|
||||
|
||||
test -r /data/etc/ppp/modem && ppp_ok="ok" # TODO actually test the ppp link
|
||||
@ -182,8 +186,14 @@ start() {
|
||||
fi
|
||||
|
||||
if [ "$eth_ok" != "ok" ] && [ "$wlan_ok" != "ok" ] && [ "$ppp_ok" != "ok" ]; then
|
||||
logger -t ethernet -s "no network connection available"
|
||||
test "$watch_link" == "yes" && return 1 || return 0
|
||||
if [ "$link_watch" == "yes" ]; then
|
||||
logger -t ethernet -s "no network connection available, rebooting"
|
||||
reboot
|
||||
return 1
|
||||
else
|
||||
logger -t ethernet -s "no network connection available"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$static_gw" ]; then
|
||||
|
@ -10,6 +10,9 @@ test -f $watch_conf && source $watch_conf || exit 0
|
||||
test -z "$netwatch_host" || -z "$netwatch_port" && exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
test "$os_networkless" == "true" && exit 0
|
||||
|
||||
watch() {
|
||||
count=0
|
||||
|
@ -27,6 +27,9 @@ fi
|
||||
test -f $conf || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
has_net_conn || exit 0
|
||||
|
||||
date_timeout=10
|
||||
date_method=http
|
||||
|
@ -5,6 +5,9 @@ conf="/etc/sshd_config"
|
||||
test -f $conf || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
has_net_conn || exit 0
|
||||
|
||||
start() {
|
||||
msg_begin "Starting sshd"
|
||||
|
@ -3,6 +3,9 @@
|
||||
test -f /etc/proftpd.conf || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
has_net_conn || exit 0
|
||||
|
||||
start() {
|
||||
msg_begin "Starting proftpd"
|
||||
|
@ -3,6 +3,9 @@
|
||||
test -f /etc/samba/smb.conf || exit 0
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
has_net_conn || exit 0
|
||||
|
||||
start() {
|
||||
msg_begin "Setting smb admin password"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
test -n "$os_version" || source /etc/init.d/base
|
||||
test -n "$os_debug" || source /etc/init.d/conf
|
||||
|
||||
msg_info() {
|
||||
echo " # $1"
|
||||
@ -24,9 +25,9 @@ show_dns() {
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
show_iface_ip_addr eth0
|
||||
show_iface_ip_addr wlan0
|
||||
show_iface_ip_addr ppp0
|
||||
show_iface_ip_addr $os_eth
|
||||
show_iface_ip_addr $os_wlan
|
||||
show_iface_ip_addr $os_ppp
|
||||
show_gateway
|
||||
show_dns
|
||||
;;
|
||||
|
29
board/common/overlay/etc/init.d/conf
Normal file
29
board/common/overlay/etc/init.d/conf
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
_sys_conf="/etc/os.conf"
|
||||
_boot_conf="/boot/os.conf"
|
||||
_conf="/data/etc/os.conf"
|
||||
|
||||
if ! [ -f $_conf ]; then
|
||||
if [ -f $_boot_conf ]; then
|
||||
cp $_boot_conf $_conf
|
||||
elif [ -f $_sys_conf ]; then
|
||||
cp $_sys_conf $_conf
|
||||
fi
|
||||
fi
|
||||
|
||||
source $_conf
|
||||
|
||||
has_net_conn() {
|
||||
test "$os_networkless" == "true" && return 1
|
||||
|
||||
addr_eth=$(ip addr show dev $os_eth 2>/dev/null | grep inet | tr -s ' ' | sed -r 's/^\s+//' | cut -d ' ' -f 2)
|
||||
addr_wlan=$(ip addr show dev $os_wlan 2>/dev/null | grep inet | tr -s ' ' | sed -r 's/^\s+//' | cut -d ' ' -f 2)
|
||||
|
||||
if [ -n "$addr_eth" ] || [ -n "$addr_wlan" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
os_debug="false"
|
||||
os_prereleases="false"
|
||||
os_tty_login="tty1"
|
||||
os_eth="eth0"
|
||||
os_wlan="wlan0"
|
||||
os_ppp="ppp0"
|
||||
os_networkless="false"
|
||||
|
||||
|
9
board/common/overlay/usr/share/post-upgrade/20160828.sh
Executable file
9
board/common/overlay/usr/share/post-upgrade/20160828.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# more settings have been added to [/data]/etc/os.conf
|
||||
|
||||
echo 'os_networkless="false"' >> /data/etc/os.conf
|
||||
echo 'os_eth="eth0"' >> /data/etc/os.conf
|
||||
echo 'os_wlan="wlan0"' >> /data/etc/os.conf
|
||||
echo 'os_ppp="ppp0"' >> /data/etc/os.conf
|
||||
|
Loading…
x
Reference in New Issue
Block a user