From f93f325ec96b2b76d92b19be71857e761d83620c Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Fri, 10 Mar 2017 09:22:09 +0200 Subject: qdbd: Add network configuration script The script is called to reset the host-device network interface before starting qdbd. qdbd will call it to configure the network when it is told by the host what network to use. Due to dependency to systemd-networkd in the script and the overall system, working with SysV init is fiction, so remove that configuration. Change-Id: I86f8348e57077c8718cedf68af82796adef65f07 Reviewed-by: Samuli Piippo --- recipes-qt/b2qt-addons/qdbd.bb | 12 +-- recipes-qt/b2qt-addons/qdbd/b2qt-gadget-network.sh | 103 +++++++++++++++++++++ recipes-qt/b2qt-addons/qdbd/qdbd-init.sh | 2 + 3 files changed, 111 insertions(+), 6 deletions(-) create mode 100755 recipes-qt/b2qt-addons/qdbd/b2qt-gadget-network.sh diff --git a/recipes-qt/b2qt-addons/qdbd.bb b/recipes-qt/b2qt-addons/qdbd.bb index 154369b..925b41c 100644 --- a/recipes-qt/b2qt-addons/qdbd.bb +++ b/recipes-qt/b2qt-addons/qdbd.bb @@ -32,9 +32,11 @@ SECTION = "devel" LICENSE = "The-Qt-Company-DCLA-2.1" LIC_FILES_CHKSUM = "file://qdbd/main.cpp;md5=37093977d3f09e6366def8955c8c71e6;beginline=1;endline=18" +inherit distro_features_check inherit qmake5 SRC_URI = "git://codereview.qt-project.org/tqtc-boot2qt/qdb;branch=${BRANCH};protocol=ssh \ + file://b2qt-gadget-network.sh \ file://defaults \ file://qdbd.service \ file://qdbd-init.sh \ @@ -44,6 +46,7 @@ SRCREV = "c3f54cedb1fc2805eb21b2499514284941445e85" BRANCH = "5.8" PV = "1.0.0+git${SRCPV}" +REQUIRED_DISTRO_FEATURES = "systemd" DEPENDS = "qtbase" RRECOMMENDS_${PN} += "kernel-module-usb-f-fs kernel-module-usb-f-rndis" @@ -52,9 +55,9 @@ S = "${WORKDIR}/git" EXTRA_QMAKEVARS_PRE = "CONFIG+=daemon_only" do_install_append() { + install -m 0755 ${WORKDIR}/b2qt-gadget-network.sh ${D}${bindir}/ + install -m 0755 ${WORKDIR}/qdbd-init.sh ${D}${bindir}/ - install -m 0755 -d ${D}${sysconfdir}/init.d - ln -s ${bindir}/qdbd-init.sh ${D}${sysconfdir}/init.d/ install -m 0755 -d ${D}${systemd_unitdir}/system install -m 0644 ${WORKDIR}/qdbd.service ${D}${systemd_unitdir}/system/ @@ -63,11 +66,8 @@ do_install_append() { install -m 0644 ${WORKDIR}/defaults ${D}${sysconfdir}/default/qdbd } -INITSCRIPT_NAME = "qdbd-init.sh" -INITSCRIPT_PARAMS = "defaults 96" - SYSTEMD_SERVICE_${PN} = "qdbd.service" # adbd is started by default instead of qdbd SYSTEMD_AUTO_ENABLE = "disable" -inherit update-rc.d systemd +inherit systemd diff --git a/recipes-qt/b2qt-addons/qdbd/b2qt-gadget-network.sh b/recipes-qt/b2qt-addons/qdbd/b2qt-gadget-network.sh new file mode 100755 index 0000000..3161db7 --- /dev/null +++ b/recipes-qt/b2qt-addons/qdbd/b2qt-gadget-network.sh @@ -0,0 +1,103 @@ +#!/bin/sh +############################################################################ +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the Boot to Qt meta layer. +## +## $QT_BEGIN_LICENSE:GPL$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 or (at your option) any later version +## approved by the KDE Free Qt Foundation. The licenses are as published by +## the Free Software Foundation and appearing in the file LICENSE.GPL3 +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################ + +set -e + +NETWORK_UNIT=/usr/lib/systemd/network/usb-rndis.network + +usage() { + echo "Usage: $(basename $0) --reset" + echo " $(basename $0) --set " + echo + echo "Network is given as the device IPv4 address followed by the prefix length." + echo "For example \"192.168.0.1/24\"." + exit 1 +} + +while test -n "$1"; do + case "$1" in + "help" | "--help" | "-h") + usage + exit 0 + ;; + "--reset") + if [ -n "$COMMAND" ]; then + usage + exit 1 + fi + COMMAND="reset" + ;; + "--set") + if [ -n "$COMMAND" ]; then + usage + exit 1 + fi + COMMAND="set" + shift + NETWORK=$1 + ;; + esac + shift +done + +if [ -z "$COMMAND" ]; then + usage + exit 1 +fi + +case "$COMMAND" in + "set") + cat < $NETWORK_UNIT +# This file is automatically written by b2qt-gadget-network.sh +[Match] +Type=gadget + +[Network] +Address=${NETWORK} +DHCPServer=yes + +[DHCPServer] +EmitDNS=no +EmitRouter=no +EOF + ;; + "reset") + cat < $NETWORK_UNIT +# This file is automatically written by b2qt-gadget-network.sh +[Match] +Type=gadget + +[Network] +DHCPServer=no +EOF + ;; +esac + +systemctl restart systemd-networkd diff --git a/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh b/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh index 446ea3f..10151c9 100755 --- a/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh +++ b/recipes-qt/b2qt-addons/qdbd/qdbd-init.sh @@ -61,6 +61,7 @@ function disable_gadget() { case "$1" in start) + b2qt-gadget-network.sh --reset modprobe libcomposite # Gadget configuration mkdir -p $GADGET_CONFIG @@ -104,6 +105,7 @@ stop) restart) disable_gadget start-stop-daemon --stop --quiet --exec $DAEMON + b2qt-gadget-network.sh --reset sleep 1 shift start-stop-daemon --start --quiet --exec $DAEMON -- $@ & -- cgit v1.2.3-54-g00ecf