package/ifupdown-scripts: new package
authorYann E. MORIN <yann.morin.1998@free.fr>
Sun, 2 Jul 2017 14:35:50 +0000 (16:35 +0200)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tue, 4 Jul 2017 21:38:18 +0000 (23:38 +0200)
The ifupdown scripts can be used independently of the init system, be it
sysv, busybox or systemd; they could even be used when there is no init
system (i.e. the user is providing his own).

Currently, those ifupdown scripts are bundled in the skeleton.

But we soon will have a skeleton specific to systemd, so we would be
missing those scripts (when systemd-networkd is not enabled).

So, move those scripts to their own package.

To keep the current behaviour (before it is changed in future commits),
we make that package default to y, but depend on the default skeleton.

Instead of being a target-finalize hook, the scripts are installed as
any other package are, with a package install-target command.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Arnout Vandecappelle <arnout@mind.be>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Maxime Hadjinlian <maxime.hadjinlian@gmail.com>
Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
[Thomas: drop empty IFUPDOWN_SCRIPTS_SOURCE]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
19 files changed:
package/Config.in
package/ifupdown-scripts/Config.in [new file with mode: 0644]
package/ifupdown-scripts/S40network [new file with mode: 0755]
package/ifupdown-scripts/ifupdown-scripts.mk [new file with mode: 0644]
package/ifupdown-scripts/network.service [new file with mode: 0644]
package/ifupdown-scripts/network/if-down.d/.empty [new file with mode: 0644]
package/ifupdown-scripts/network/if-post-down.d/.empty [new file with mode: 0644]
package/ifupdown-scripts/network/if-pre-up.d/wait_iface [new file with mode: 0755]
package/ifupdown-scripts/network/if-up.d/.empty [new file with mode: 0644]
package/ifupdown-scripts/nfs_check [new file with mode: 0755]
package/initscripts/init.d/S40network [deleted file]
package/skeleton/nfs_check [deleted file]
package/skeleton/skeleton.mk
package/systemd/network.service [deleted file]
package/systemd/systemd.mk
system/skeleton/etc/network/if-down.d/.empty [deleted file]
system/skeleton/etc/network/if-post-down.d/.empty [deleted file]
system/skeleton/etc/network/if-pre-up.d/wait_iface [deleted file]
system/skeleton/etc/network/if-up.d/.empty [deleted file]

index 36747a2492c87819210c753637e00c7da4ae84c6..46c78a0121cbbe311e813c20417a2ca2d687922e 100644 (file)
@@ -1603,6 +1603,7 @@ menu "Networking applications"
        source "package/ifplugd/Config.in"
        source "package/iftop/Config.in"
        source "package/ifupdown/Config.in"
+       source "package/ifupdown-scripts/Config.in"
        source "package/igd2-for-linux/Config.in"
        source "package/igh-ethercat/Config.in"
        source "package/igmpproxy/Config.in"
diff --git a/package/ifupdown-scripts/Config.in b/package/ifupdown-scripts/Config.in
new file mode 100644 (file)
index 0000000..7086253
--- /dev/null
@@ -0,0 +1,8 @@
+config BR2_PACKAGE_IFUPDOWN_SCRIPTS
+       bool
+       depends on BR2_ROOTFS_SKELETON_DEFAULT
+       depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+       default y
+       help
+         Set of scripts used by ifupdown (either the standalone one, or the
+         busybox one) to bring network up, or tear it down.
diff --git a/package/ifupdown-scripts/S40network b/package/ifupdown-scripts/S40network
new file mode 100755 (executable)
index 0000000..642c501
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Start the network....
+#
+
+# Debian ifupdown needs the /run/network lock directory
+mkdir -p /run/network
+
+case "$1" in
+  start)
+       printf "Starting network: "
+       /sbin/ifup -a
+       [ $? = 0 ] && echo "OK" || echo "FAIL"
+       ;;
+  stop)
+       printf "Stopping network: "
+       /sbin/ifdown -a
+       [ $? = 0 ] && echo "OK" || echo "FAIL"
+       ;;
+  restart|reload)
+       "$0" stop
+       "$0" start
+       ;;
+  *)
+       echo "Usage: $0 {start|stop|restart}"
+       exit 1
+esac
+
+exit $?
+
diff --git a/package/ifupdown-scripts/ifupdown-scripts.mk b/package/ifupdown-scripts/ifupdown-scripts.mk
new file mode 100644 (file)
index 0000000..317c8f4
--- /dev/null
@@ -0,0 +1,55 @@
+################################################################################
+#
+# ifupdown-scripts
+#
+################################################################################
+
+define IFUPDOWN_SCRIPTS_LOCALHOST
+       ( \
+               echo "# interface file auto-generated by buildroot"; \
+               echo ; \
+               echo "auto lo"; \
+               echo "iface lo inet loopback"; \
+       ) > $(TARGET_DIR)/etc/network/interfaces
+endef
+
+IFUPDOWN_SCRIPTS_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
+
+ifneq ($(IFUPDOWN_SCRIPTS_DHCP_IFACE),)
+define IFUPDOWN_SCRIPTS_DHCP
+       ( \
+               echo ; \
+               echo "auto $(IFUPDOWN_SCRIPTS_DHCP_IFACE)"; \
+               echo "iface $(IFUPDOWN_SCRIPTS_DHCP_IFACE) inet dhcp"; \
+               echo "  pre-up /etc/network/nfs_check"; \
+               echo "  wait-delay 15"; \
+       ) >> $(TARGET_DIR)/etc/network/interfaces
+       $(INSTALL) -m 0755 -D $(IFUPDOWN_SCRIPTS_PKGDIR)/nfs_check \
+               $(TARGET_DIR)/etc/network/nfs_check
+endef
+endif
+
+define IFUPDOWN_SCRIPTS_INSTALL_TARGET_CMDS
+       mkdir -p $(TARGET_DIR)/etc/network
+       cp -a $(IFUPDOWN_SCRIPTS_PKGDIR)/network/* $(TARGET_DIR)/etc/network
+       $(IFUPDOWN_SCRIPTS_LOCALHOST)
+       $(IFUPDOWN_SCRIPTS_DHCP)
+endef
+
+define IFUPDOWN_SCRIPTS_INSTALL_INIT_SYSV
+       $(INSTALL) -D -m 0755 $(IFUPDOWN_SCRIPTS_PKGDIR)/S40network \
+               $(TARGET_DIR)/etc/init.d/S40network
+endef
+
+# ifupdown-scripts can not be selected when systemd-networkd is
+# enabled, so if we are enabled with systemd, we must install our
+# own service file.
+define IFUPDOWN_SCRIPTS_INSTALL_INIT_SYSTEMD
+       $(INSTALL) -D -m 644 $(IFUPDOWN_SCRIPTS_PKGDIR)/network.service \
+               $(TARGET_DIR)/etc/systemd/system/network.service
+       mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+       ln -fs ../network.service \
+               $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/network.service
+endef
+
+$(eval $(generic-package))
diff --git a/package/ifupdown-scripts/network.service b/package/ifupdown-scripts/network.service
new file mode 100644 (file)
index 0000000..0d77bb8
--- /dev/null
@@ -0,0 +1,21 @@
+[Unit]
+Description=Network Connectivity
+Wants=network.target
+Before=network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+
+# lo is brought up earlier, which will cause the upcoming "ifup -a" to fail
+# with exit code 1, due to an "ip: RTNETLINK answers: File exists" error during
+# its "ip addr add ..." command, subsequently causing this unit to fail even
+# though it is a benign error. Flushing the lo address with the command below
+# before ifup prevents this failure.
+ExecStart=/sbin/ip addr flush dev lo
+
+ExecStart=/sbin/ifup -a
+ExecStop=/sbin/ifdown -a
+
+[Install]
+WantedBy=multi-user.target
diff --git a/package/ifupdown-scripts/network/if-down.d/.empty b/package/ifupdown-scripts/network/if-down.d/.empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/package/ifupdown-scripts/network/if-post-down.d/.empty b/package/ifupdown-scripts/network/if-post-down.d/.empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/package/ifupdown-scripts/network/if-pre-up.d/wait_iface b/package/ifupdown-scripts/network/if-pre-up.d/wait_iface
new file mode 100755 (executable)
index 0000000..ebccff2
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# In case we have a slow-to-appear interface (e.g. eth-over-USB),
+# and we need to configure it, wait until it appears, but not too
+# long either. IF_WAIT_DELAY is in seconds.
+
+if [ "${IF_WAIT_DELAY}" -a ! -e "/sys/class/net/${IFACE}" ]; then
+    printf "Waiting for interface %s to appear" "${IFACE}"
+    while [ ${IF_WAIT_DELAY} -gt 0 ]; do
+        if [ -e "/sys/class/net/${IFACE}" ]; then
+            printf "\n"
+            exit 0
+        fi
+        sleep 1
+        printf "."
+        : $((IF_WAIT_DELAY -= 1))
+    done
+    printf " timeout!\n"
+    exit 1
+fi
+
diff --git a/package/ifupdown-scripts/network/if-up.d/.empty b/package/ifupdown-scripts/network/if-up.d/.empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/package/ifupdown-scripts/nfs_check b/package/ifupdown-scripts/nfs_check
new file mode 100755 (executable)
index 0000000..dfa0cbf
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# This allows NFS booting to work while also being able to configure
+# the network interface via DHCP when not NFS booting.  Otherwise, a
+# NFS booted system will likely hang during DHCP configuration.
+
+# Attempting to configure the network interface used for NFS will
+# initially bring that network down.  Since the root filesystem is
+# accessed over this network, the system hangs.
+
+# This script is run by ifup and will attempt to detect if a NFS root
+# mount uses the interface to be configured (IFACE), and if so does
+# not configure it.  This should allow the same build to be disk/flash
+# booted or NFS booted.
+
+nfsip=`sed -n '/^[^ ]*:.* \/ nfs.*[ ,]addr=\([0-9.]\+\).*/s//\1/p' /proc/mounts`
+if [ -n "$nfsip" ] && ip route get to "$nfsip" | grep -q "dev $IFACE"; then
+       echo Skipping $IFACE, used for NFS from $nfsip
+       exit 1
+fi
diff --git a/package/initscripts/init.d/S40network b/package/initscripts/init.d/S40network
deleted file mode 100755 (executable)
index 642c501..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-#
-# Start the network....
-#
-
-# Debian ifupdown needs the /run/network lock directory
-mkdir -p /run/network
-
-case "$1" in
-  start)
-       printf "Starting network: "
-       /sbin/ifup -a
-       [ $? = 0 ] && echo "OK" || echo "FAIL"
-       ;;
-  stop)
-       printf "Stopping network: "
-       /sbin/ifdown -a
-       [ $? = 0 ] && echo "OK" || echo "FAIL"
-       ;;
-  restart|reload)
-       "$0" stop
-       "$0" start
-       ;;
-  *)
-       echo "Usage: $0 {start|stop|restart}"
-       exit 1
-esac
-
-exit $?
-
diff --git a/package/skeleton/nfs_check b/package/skeleton/nfs_check
deleted file mode 100755 (executable)
index dfa0cbf..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-# This allows NFS booting to work while also being able to configure
-# the network interface via DHCP when not NFS booting.  Otherwise, a
-# NFS booted system will likely hang during DHCP configuration.
-
-# Attempting to configure the network interface used for NFS will
-# initially bring that network down.  Since the root filesystem is
-# accessed over this network, the system hangs.
-
-# This script is run by ifup and will attempt to detect if a NFS root
-# mount uses the interface to be configured (IFACE), and if so does
-# not configure it.  This should allow the same build to be disk/flash
-# booted or NFS booted.
-
-nfsip=`sed -n '/^[^ ]*:.* \/ nfs.*[ ,]addr=\([0-9.]\+\).*/s//\1/p' /proc/mounts`
-if [ -n "$nfsip" ] && ip route get to "$nfsip" | grep -q "dev $IFACE"; then
-       echo Skipping $IFACE, used for NFS from $nfsip
-       exit 1
-fi
index 1321eb62cdae2eaf2ea5b608098fa8a0a01a573a..a310a314a57f964018cf360ceeaddc68a838f9d1 100644 (file)
@@ -145,39 +145,6 @@ endef
 TARGET_FINALIZE_HOOKS += SKELETON_SET_ISSUE
 endif
 
-define SKELETON_SET_NETWORK_LOCALHOST
-       ( \
-               echo "# interface file auto-generated by buildroot"; \
-               echo ; \
-               echo "auto lo"; \
-               echo "iface lo inet loopback"; \
-       ) > $(TARGET_DIR)/etc/network/interfaces
-endef
-
-SKELETON_NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
-
-ifneq ($(SKELETON_NETWORK_DHCP_IFACE),)
-define SKELETON_SET_NETWORK_DHCP
-       ( \
-               echo ; \
-               echo "auto $(SKELETON_NETWORK_DHCP_IFACE)"; \
-               echo "iface $(SKELETON_NETWORK_DHCP_IFACE) inet dhcp"; \
-               echo "  pre-up /etc/network/nfs_check"; \
-               echo "  wait-delay 15"; \
-       ) >> $(TARGET_DIR)/etc/network/interfaces
-       $(INSTALL) -m 0755 -D $(SKELETON_PKGDIR)/nfs_check \
-               $(TARGET_DIR)/etc/network/nfs_check
-endef
-endif
-
-define SKELETON_SET_NETWORK
-       mkdir -p $(TARGET_DIR)/etc/network/
-       $(SKELETON_SET_NETWORK_LOCALHOST)
-       $(SKELETON_SET_NETWORK_DHCP)
-endef
-
-TARGET_FINALIZE_HOOKS += SKELETON_SET_NETWORK
-
 ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y)
 ifeq ($(SKELETON_TARGET_GENERIC_ROOT_PASSWD),)
 SKELETON_ROOT_PASSWORD =
diff --git a/package/systemd/network.service b/package/systemd/network.service
deleted file mode 100644 (file)
index 0d77bb8..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-[Unit]
-Description=Network Connectivity
-Wants=network.target
-Before=network.target
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-
-# lo is brought up earlier, which will cause the upcoming "ifup -a" to fail
-# with exit code 1, due to an "ip: RTNETLINK answers: File exists" error during
-# its "ip addr add ..." command, subsequently causing this unit to fail even
-# though it is a benign error. Flushing the lo address with the command below
-# before ifup prevents this failure.
-ExecStart=/sbin/ip addr flush dev lo
-
-ExecStart=/sbin/ifup -a
-ExecStop=/sbin/ifdown -a
-
-[Install]
-WantedBy=multi-user.target
index f7894b28b42a514f574d815099785136dab6dcfb..94b8b9656749fe65218502b466e7f54b8e47259a 100644 (file)
@@ -303,13 +303,6 @@ endef
 endif
 else
 SYSTEMD_CONF_OPTS += --disable-networkd
-define SYSTEMD_INSTALL_SERVICE_NETWORK
-       $(INSTALL) -D -m 644 package/systemd/network.service \
-               $(TARGET_DIR)/etc/systemd/system/network.service
-       mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-       ln -fs ../network.service \
-               $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/network.service
-endef
 endif
 
 ifeq ($(BR2_PACKAGE_SYSTEMD_RESOLVED),y)
@@ -401,7 +394,6 @@ endif
 define SYSTEMD_INSTALL_INIT_SYSTEMD
        $(SYSTEMD_DISABLE_SERVICE_TTY1)
        $(SYSTEMD_INSTALL_SERVICE_TTY)
-       $(SYSTEMD_INSTALL_SERVICE_NETWORK)
        $(SYSTEMD_INSTALL_SERVICE_TIMESYNC)
        $(SYSTEMD_INSTALL_NETWORK_CONFS)
 endef
diff --git a/system/skeleton/etc/network/if-down.d/.empty b/system/skeleton/etc/network/if-down.d/.empty
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/system/skeleton/etc/network/if-post-down.d/.empty b/system/skeleton/etc/network/if-post-down.d/.empty
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/system/skeleton/etc/network/if-pre-up.d/wait_iface b/system/skeleton/etc/network/if-pre-up.d/wait_iface
deleted file mode 100755 (executable)
index ebccff2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-# In case we have a slow-to-appear interface (e.g. eth-over-USB),
-# and we need to configure it, wait until it appears, but not too
-# long either. IF_WAIT_DELAY is in seconds.
-
-if [ "${IF_WAIT_DELAY}" -a ! -e "/sys/class/net/${IFACE}" ]; then
-    printf "Waiting for interface %s to appear" "${IFACE}"
-    while [ ${IF_WAIT_DELAY} -gt 0 ]; do
-        if [ -e "/sys/class/net/${IFACE}" ]; then
-            printf "\n"
-            exit 0
-        fi
-        sleep 1
-        printf "."
-        : $((IF_WAIT_DELAY -= 1))
-    done
-    printf " timeout!\n"
-    exit 1
-fi
-
diff --git a/system/skeleton/etc/network/if-up.d/.empty b/system/skeleton/etc/network/if-up.d/.empty
deleted file mode 100644 (file)
index e69de29..0000000