connman: add cm-online script to wait on network, add network check servicefile

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2013-08-16 21:27:18 +02:00
parent bf20f799d4
commit 6934001ed7
3 changed files with 73 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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