From ce5d1b27b3cfb106408a504c26bf75aac879c3d6 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 28 Aug 2016 16:10:12 +0300 Subject: [PATCH] added proper networkless support --- board/common/overlay/etc/init.d/S01mountall | 36 +++------- board/common/overlay/etc/init.d/S35wifi | 14 ++-- board/common/overlay/etc/init.d/S36ppp | 6 +- board/common/overlay/etc/init.d/S40network | 68 +++++++++++-------- board/common/overlay/etc/init.d/S41netwatch | 3 + board/common/overlay/etc/init.d/S50date | 3 + board/common/overlay/etc/init.d/S60sshd | 3 + board/common/overlay/etc/init.d/S61proftpd | 3 + board/common/overlay/etc/init.d/S62smb | 3 + board/common/overlay/etc/init.d/S99showinfo | 7 +- board/common/overlay/etc/init.d/conf | 29 ++++++++ board/common/overlay/etc/os.conf | 4 ++ .../usr/share/post-upgrade/20160828.sh | 9 +++ 13 files changed, 123 insertions(+), 65 deletions(-) create mode 100644 board/common/overlay/etc/init.d/conf create mode 100755 board/common/overlay/usr/share/post-upgrade/20160828.sh diff --git a/board/common/overlay/etc/init.d/S01mountall b/board/common/overlay/etc/init.d/S01mountall index 481c65f5433..71ce7bb0182 100755 --- a/board/common/overlay/etc/init.d/S01mountall +++ b/board/common/overlay/etc/init.d/S01mountall @@ -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 - - 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 +remount_rw() { + 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 } 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 ;; diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 0332ba5b918..259be279628 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -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 diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 041b042b83a..52971f3afc9 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -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() { diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index b19a0df6369..88b9b6dbd39 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -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 diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index 925681a7822..940d5150837 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -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 diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 10e90483c5b..d8231be6a28 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -27,7 +27,10 @@ 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 date_host="google.com" diff --git a/board/common/overlay/etc/init.d/S60sshd b/board/common/overlay/etc/init.d/S60sshd index bc48ccde0b7..f94b4639ce5 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -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" diff --git a/board/common/overlay/etc/init.d/S61proftpd b/board/common/overlay/etc/init.d/S61proftpd index 550f05dcf84..ef358941b2c 100755 --- a/board/common/overlay/etc/init.d/S61proftpd +++ b/board/common/overlay/etc/init.d/S61proftpd @@ -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" diff --git a/board/common/overlay/etc/init.d/S62smb b/board/common/overlay/etc/init.d/S62smb index 379e34c2caf..dfd2ba03240 100755 --- a/board/common/overlay/etc/init.d/S62smb +++ b/board/common/overlay/etc/init.d/S62smb @@ -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" diff --git a/board/common/overlay/etc/init.d/S99showinfo b/board/common/overlay/etc/init.d/S99showinfo index 33642c072d8..1e0b7390d15 100755 --- a/board/common/overlay/etc/init.d/S99showinfo +++ b/board/common/overlay/etc/init.d/S99showinfo @@ -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 ;; diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/conf new file mode 100644 index 00000000000..fd1afc129c3 --- /dev/null +++ b/board/common/overlay/etc/init.d/conf @@ -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 +} + diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index 2cc5d3e21b5..b4e03dce30a 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -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" diff --git a/board/common/overlay/usr/share/post-upgrade/20160828.sh b/board/common/overlay/usr/share/post-upgrade/20160828.sh new file mode 100755 index 00000000000..d140a1a55d9 --- /dev/null +++ b/board/common/overlay/usr/share/post-upgrade/20160828.sh @@ -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 +