Skip to content

Commit

Permalink
added proper networkless support
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Aug 28, 2016
1 parent 70730ff commit ce5d1b2
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 65 deletions.
36 changes: 11 additions & 25 deletions board/common/overlay/etc/init.d/S01mountall
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
;;

Expand Down
14 changes: 8 additions & 6 deletions board/common/overlay/etc/init.d/S35wifi
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions board/common/overlay/etc/init.d/S36ppp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
68 changes: 39 additions & 29 deletions board/common/overlay/etc/init.d/S40network
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -141,35 +144,36 @@ 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
}

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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions board/common/overlay/etc/init.d/S41netwatch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions board/common/overlay/etc/init.d/S50date
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions board/common/overlay/etc/init.d/S60sshd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions board/common/overlay/etc/init.d/S61proftpd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions board/common/overlay/etc/init.d/S62smb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions board/common/overlay/etc/init.d/S99showinfo
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
;;
Expand Down
29 changes: 29 additions & 0 deletions board/common/overlay/etc/init.d/conf
Original file line number Diff line number Diff line change
@@ -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
}

Loading

0 comments on commit ce5d1b2

Please sign in to comment.