diff --git a/packages/network/connman/package.mk b/packages/network/connman/package.mk index 88fa636bd2..1c82fdb1cb 100644 --- a/packages/network/connman/package.mk +++ b/packages/network/connman/package.mk @@ -92,6 +92,7 @@ post_makeinstall_target() { mkdir -p $INSTALL/usr/bin cp -P client/connmanctl $INSTALL/usr/bin + cp -P $PKG_DIR/scripts/cm-online $INSTALL/usr/bin mkdir -p $INSTALL/etc ln -sf /var/cache/resolv.conf $INSTALL/etc/resolv.conf diff --git a/packages/network/connman/scripts/cm-online b/packages/network/connman/scripts/cm-online new file mode 100755 index 0000000000..7af1b49d70 --- /dev/null +++ b/packages/network/connman/scripts/cm-online @@ -0,0 +1,59 @@ +#!/bin/sh +################################################################################ +# This file is part of OpenELEC - http://www.openelec.tv +# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) +# +# This Program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This Program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenELEC.tv; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA. +# http://www.gnu.org/copyleft/gpl.html +################################################################################ + +# Wait for the network to come up and exit after timeout or if network is online +# +# Usage: +# cm-online [--timeout=n] [--verbose] +# --timeout : timeout in sec. (default 30) +# --verbose : print status on exit +# +# Exit status: +# (0) Network online +# (1) Network not online + +TIMEOUT=30 + +for arg in $@; do + case $arg in + --timeout=*) + TIMEOUT="${arg#*=}" + ;; + --verbose) + VERBOSE=yes + ;; + esac +done + +LOOP_COUNT=$((TIMEOUT * 4)) + +for i in $(seq 1 $LOOP_COUNT) ; do + STATUS=$(ifconfig | sed -e '/inet addr:/!d' -e '/127.0.0.1/d' |wc -l) + if [ "$STATUS" -gt 0 ]; then + [ "$VERBOSE" = yes ] && echo "Network is online" + exit 0 + fi + usleep 250000 +done + +[ "$VERBOSE" = yes ] && echo "Network is down" + +exit 1 diff --git a/packages/network/connman/system.d/network-online.service b/packages/network/connman/system.d/network-online.service new file mode 100644 index 0000000000..4f9f9e016d --- /dev/null +++ b/packages/network/connman/system.d/network-online.service @@ -0,0 +1,13 @@ +[Unit] +Description=Connection Manager Wait Online +Requisite=connman.service +After=connman.service + +[Service] +Type=oneshot +ExecStartPre=/bin/sh -c 'echo "waiting on Network to come online ..." +ExecStart=/usr/bin/cm-online --timeout=30 +StandardOutput=tty + +[Install] +WantedBy=multi-user.target