From 8cfb7daa7b0395c5aa19eb3cb2c11bf9b30388bb Mon Sep 17 00:00:00 2001 From: andreasmn Date: Wed, 30 Apr 2014 09:16:56 +0200 Subject: [PATCH] init: optimized wake-on-lan script --- packages/sysutils/busybox/scripts/init | 38 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 42a88ee913..c0b2d12db6 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -80,6 +80,7 @@ case $boot in CIFS=*|SMB=*|ISCSI=*|NBD=*|NFS=*) UPDATE_DISABLED=yes + FLASH_NETBOOT=yes ;; esac ;; @@ -94,9 +95,6 @@ wol_mac=*) wol_mac="${arg#*=}" ;; - wol_ip=*) - wol_ip="${arg#*=}" - ;; wol_wait=*) wol_wait="${arg#*=}" ;; @@ -415,22 +413,40 @@ fi } + wakeonlan() { + if [ "$STORAGE_NETBOOT" = "yes" ]; then + wol_ip=${disk%:*} + wol_ip=${wol_ip#*=} + elif [ "$FLASH_NETBOOT" = "yes" ]; then + wol_ip=${boot%:*} + wol_ip=${wol_ip#*=} + else + return 0 + fi + + if [ -n "$wol_ip" -a -n "$wol_mac" -a -n "$wol_wait" ]; then + progress "Sending Magic Packet (WOL) if needed" + + if ! ping -q -c 2 "$wol_ip" &>/dev/null; then + ether-wake "$wol_mac" + sleep "$wol_wait" + fi + fi + } + mount_flash() { progress "Mounting flash" + wakeonlan + mount_part "$boot" "/flash" "ro,noatime" } - mount_storage() { - if [ -n "$wol_ip" ] && [ -n "$wol_mac" ] && [ -n "$wol_wait" ]; then - if ! (/bin/busybox ping -q -c 2 "$wol_ip" > /dev/null 2>&1); then - /bin/busybox ether-wake "$wol_mac" - /bin/busybox sleep "$wol_wait" - fi - fi - + mount_storage() { progress "Mounting storage" + wakeonlan + if [ -n "$disk" ]; then if [ -n "$OVERLAY" ]; then OVERLAY_DIR=`cat /sys/class/net/eth0/address | tr -d :`