Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/scripts/init/c_registration/15_ssh_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const char* SERVICE_CUSTOM_EVENTS[] = {
#endif
#if defined(_ARRIS_XB6_PRODUCT_REQ_)
"wan-status|/etc/utopia/service.d/service_sshd.sh",
#endif
#if defined(_WNXL11BWL_PRODUCT_REQ_)
"mesh_wan_linkstatus|/etc/utopia/service.d/service_sshd.sh",
#endif
Comment on lines +54 to 56
NULL
};
Expand Down
75 changes: 69 additions & 6 deletions source/scripts/init/service.d/service_sshd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ get_listen_params() {
fi
}

# wait_for_iface_ip <interface>
# Blocks up to 300 seconds (150 x 2s) waiting for an IPv4 address on the
# given interface. Prints the IP to stdout on success; logs an error and
# returns 1 on timeout.
wait_for_iface_ip() {
local IFACE="$1"
local SLEEP_INTERVAL=2
local RETRIES=0
local MAX_RETRIES=150 # 150 x 2s = 300s max wait
while [ $RETRIES -lt $MAX_RETRIES ]; do
sleep $SLEEP_INTERVAL
WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1`
if [ -n "$WAITED_IP" ]; then
echo_t "[utopia] $IFACE got IP $WAITED_IP after $((RETRIES * SLEEP_INTERVAL)) seconds"
echo "$WAITED_IP"
return 0
fi
RETRIES=$((RETRIES + 1))
done
echo_t "[utopia] ERROR: Timed out waiting for IP on $IFACE after $((MAX_RETRIES * SLEEP_INTERVAL)) seconds"
return 1
}

do_start() {
#DIR_NAME=/tmp/home/admin
#if [ ! -d $DIR_NAME ] ; then
Expand Down Expand Up @@ -208,18 +231,45 @@ do_start() {
commandString="$commandString -p [$CM_IPV4]:22"
fi
elif [ "$BOX_TYPE" = "WNXL11BWL" ]; then
CM_IP=`ip -4 addr show dev $CMINTERFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IP ]; then
commandString="$commandString -p [$CM_IP]:22"
fi
echo_t "[utopia] devicemode `deviceinfo.sh -mode`"
echo_t "[utopia] route `route -n`"
echo_t "[utopia] CMINTERFACE $CMINTERFACE "
Comment on lines +234 to +236
Comment on lines +234 to +236

CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IPv6 ]; then
if [ ! -z "$CM_IPv6" ]; then
commandString="$commandString -p [$CM_IPv6]:22"
fi
CM_IPv4=`ip -4 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IPv4 ]; then
if [ ! -z "$CM_IPv4" ]; then
commandString="$commandString -p [$CM_IPv4]:22"
Comment on lines 238 to 244
fi
if [ "$CMINTERFACE" != "wwan0" ]; then
CM_IP=`ip -4 addr show dev $CMINTERFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z "$CM_IP" ]; then
Comment on lines +246 to +248
commandString="$commandString -p [$CM_IP]:22"
else
DEVICE_MODE=`deviceinfo.sh -mode`
if [ "$DEVICE_MODE" = "Extender" ]; then
MESH_WAN_STATUS=`sysevent get mesh_wan_linkstatus`
if [ "$MESH_WAN_STATUS" = "up" ]; then
echo_t "[utopia] $CMINTERFACE has no IP (Extender mode, mesh WAN up), waiting up to 300s"
CM_IP=`wait_for_iface_ip "$CMINTERFACE"`
if [ -n "$CM_IP" ]; then
commandString="$commandString -p [$CM_IP]:22"
else
echo_t "[utopia] ERROR: $CMINTERFACE did not get an IP after 300s, dropbear will start without it"
fi
else
echo_t "[utopia] $CMINTERFACE has no IP and mesh_wan_linkstatus is not up, skipping wait"
fi
else
echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait"
fi
fi
echo_t "[utopia] CM_IP $CM_IP "
fi

echo_t "[utopia] commandString $commandString"
else
CM_IP=""
if ([ "$BOX_TYPE" = "rpi" ] || [ "$BOX_TYPE" = "bpi" ]) ;then
Expand Down Expand Up @@ -452,6 +502,19 @@ case "$1" in
service_stop
service_start
;;
mesh_wan_linkstatus)
if [ "$BOX_TYPE" = "WNXL11BWL" ]; then
echo_t "mesh_wan_linkstatus_value $2"
echo_t "mesh_wan_linkstatus_sysevent `sysevent get mesh_wan_linkstatus`"
if [ "$2" = "up" ]; then
Comment on lines +505 to +509
DEVICE_MODE=`deviceinfo.sh -mode`
if [ "$DEVICE_MODE" = "Extender" ]; then
service_stop
service_start
fi
fi
fi
;;

*)
echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|ssh_server_restart|lan-status|wan-status]" >&2
Expand Down
Loading