From f4932174adecf2ff2ffaf3018a02452329a9fad6 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 7 Nov 2005 00:27:07 +0000 Subject: [PATCH] add new hotplug scripts SVN-Revision: 2361 --- openwrt/package/base-files/Makefile | 13 +--- .../base-files/default/etc/functions.sh | 15 ++-- .../etc/hotplug.d/net/01-wds} | 3 +- .../default/etc/hotplug.d/usb/01-mount | 49 +++++++++++++ .../package/base-files/default/sbin/hotplug | 11 +++ .../package/base-files/default/sbin/ifdown | 10 ++- .../default/usr/share/udhcpc/default.script | 73 +++++++++++-------- .../package/base-files/ipkg/hotplug.control | 4 - openwrt/package/busybox/Makefile | 1 - openwrt/package/ntpclient/Makefile | 6 +- .../package/ntpclient/files/ntpclient.init | 11 ++- openwrt/package/ppp/Makefile | 4 +- openwrt/package/ppp/files/etc/ppp/ip-down | 2 + openwrt/package/ppp/files/etc/ppp/ip-up | 2 + openwrt/package/ppp/files/ifup.pppoe | 7 +- openwrt/package/pptp/Makefile | 2 +- openwrt/package/pptp/files/ifup.pptp | 8 +- .../linux/imagebuilder/lists/default.brcm-2.4 | 1 - .../linux/imagebuilder/lists/micro.brcm-2.4 | 1 - .../linux/imagebuilder/lists/pptp.brcm-2.4 | 1 - 20 files changed, 151 insertions(+), 73 deletions(-) rename openwrt/package/base-files/{files/hotplug => default/etc/hotplug.d/net/01-wds} (86%) mode change 100755 => 100644 create mode 100644 openwrt/package/base-files/default/etc/hotplug.d/usb/01-mount create mode 100644 openwrt/package/base-files/default/sbin/hotplug delete mode 100644 openwrt/package/base-files/ipkg/hotplug.control create mode 100644 openwrt/package/ppp/files/etc/ppp/ip-down create mode 100644 openwrt/package/ppp/files/etc/ppp/ip-up diff --git a/openwrt/package/base-files/Makefile b/openwrt/package/base-files/Makefile index 9a79d21c14..8beff8c3da 100644 --- a/openwrt/package/base-files/Makefile +++ b/openwrt/package/base-files/Makefile @@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=base-files -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_BUILD_DIR:=$(BUILD_DIR)/base-files include $(TOPDIR)/package/rules.mk @@ -11,9 +11,6 @@ include $(TOPDIR)/package/rules.mk IDIR_BASE:=$(PKG_BUILD_DIR)/base-files IPKG_BASE:=$(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_RELEASE)_$(ARCH).ipk -IDIR_HOTPLUG:=$(PKG_BUILD_DIR)/hotplug -IPKG_HOTPLUG:=$(PACKAGE_DIR)/hotplug_$(PKG_RELEASE)_$(ARCH).ipk - LIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version} IDIR_LIBC:=$(PKG_BUILD_DIR)/uclibc IPKG_LIBC:=$(PACKAGE_DIR)/uclibc_$(LIBC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk @@ -22,7 +19,7 @@ GCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version} IDIR_GCC:=$(PKG_BUILD_DIR)/libgcc IPKG_GCC:=$(PACKAGE_DIR)/libgcc_$(GCC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk -PACKAGES:=$(IPKG_BASE) $(IPKG_LIBC) $(IPKG_GCC) $(IPKG_HOTPLUG) +PACKAGES:=$(IPKG_BASE) $(IPKG_LIBC) $(IPKG_GCC) $(PKG_BUILD_DIR)/.prepared: mkdir -p $(PKG_BUILD_DIR) $(PACKAGE_DIR) @@ -69,12 +66,6 @@ $(IPKG_GCC): -$(STRIP) $(IDIR_GCC)/lib/* $(IPKG_BUILD) $(IDIR_GCC) $(PACKAGE_DIR) -$(IPKG_HOTPLUG): - $(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_HOTPLUG) ipkg/hotplug.control $(PKG_RELEASE) $(ARCH) - mkdir -p $(IDIR_HOTPLUG)/sbin - install -m0755 files/hotplug $(IDIR_HOTPLUG)/sbin - $(IPKG_BUILD) $(IDIR_HOTPLUG) $(PACKAGE_DIR) - package-clean: rm -f $(PACKAGES) clean: package-clean diff --git a/openwrt/package/base-files/default/etc/functions.sh b/openwrt/package/base-files/default/etc/functions.sh index 2bf4a8d998..c1828d5448 100755 --- a/openwrt/package/base-files/default/etc/functions.sh +++ b/openwrt/package/base-files/default/etc/functions.sh @@ -49,12 +49,14 @@ do_ifup() { $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up ${gateway:+$DEBUG route add default gw $gateway} - [ -f /etc/resolv.conf ] && return - - debug "# --- creating /etc/resolv.conf ---" - for dns in $(nvram get ${2}_dns); do - echo "nameserver $dns" >> /etc/resolv.conf - done + [ -f /etc/resolv.conf ] || { + debug "# --- creating /etc/resolv.conf ---" + for dns in $(nvram get ${2}_dns); do + echo "nameserver $dns" >> /etc/resolv.conf + done + } + + env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" & ;; dhcp) DHCP_IP=$(nvram get ${2}_ipaddr) @@ -72,6 +74,7 @@ do_ifup() { sleep 1 kill -9 $oldpid } + # hotplug events are handled by /usr/share/udhcpc/default.script ;; none|"") ;; diff --git a/openwrt/package/base-files/files/hotplug b/openwrt/package/base-files/default/etc/hotplug.d/net/01-wds old mode 100755 new mode 100644 similarity index 86% rename from openwrt/package/base-files/files/hotplug rename to openwrt/package/base-files/default/etc/hotplug.d/net/01-wds index 74134e848a..38bd69667f --- a/openwrt/package/base-files/files/hotplug +++ b/openwrt/package/base-files/default/etc/hotplug.d/net/01-wds @@ -1,6 +1,5 @@ -#!/bin/ash -# $Id$ [ "${INTERFACE%%[0-9]*}" = "wds" ] && { ifconfig $INTERFACE 0.0.0.0 up /usr/sbin/brctl addif br0 $INTERFACE } + diff --git a/openwrt/package/base-files/default/etc/hotplug.d/usb/01-mount b/openwrt/package/base-files/default/etc/hotplug.d/usb/01-mount new file mode 100644 index 0000000000..c28ada204e --- /dev/null +++ b/openwrt/package/base-files/default/etc/hotplug.d/usb/01-mount @@ -0,0 +1,49 @@ +mount_storage() { + cd /dev/discs + for dev in disc*; do + [ -f /tmp/.${dev}_id ] || { + echo ${INTERFACE}${PRODUCT} > /tmp/.${dev}_id + mount | grep /mnt/${dev} || ( + [ -d /mnt/. ] || { + mkdir -p /tmp/mnt + ln -s /tmp/mnt / + } + cd $dev + for part in part*; do + path=/mnt/${dev}_${part##*part} + mkdir -p ${path} + mount ${part} ${path} + done + ) + } + done +} + +umount_storage() { + for tmp in /tmp/.*_id; do + id=$(cat $tmp 2>&-) + [ "${INTERFACE}${PRODUCT}" = "$id" ] && { + rm -f $tmp + disc=${tmp##*disc} + disc=${disc%%_id} + for disc in /mnt/disc${disc}*; do + umount -f $disc || umount -l $disc + done + } + done +} + +[ -f /proc/bus/usb/devices ] || mount -t usbfs none /proc/bus/usb + +case "$ACTION" in + add) + case "${INTERFACE%%/*}" in + 8) mount_storage ;; + esac + ;; + remove) + case "${INTERFACE%%/*}" in + 8) umount_storage ;; + esac + ;; +esac diff --git a/openwrt/package/base-files/default/sbin/hotplug b/openwrt/package/base-files/default/sbin/hotplug new file mode 100644 index 0000000000..57ee969cf7 --- /dev/null +++ b/openwrt/package/base-files/default/sbin/hotplug @@ -0,0 +1,11 @@ +#!/bin/sh +PATH=/bin:/sbin:/usr/bin:/usr/sbin +LOGNAME=root +USER=root +export PATH LOGNAME USER + +[ \! -z "$1" -a -d /etc/hotplug.d/$1 ] && { + for script in $(ls /etc/hotplug.d/$1/* 2>&-); do ( + [ -f $script ] && . $script + ); done +} diff --git a/openwrt/package/base-files/default/sbin/ifdown b/openwrt/package/base-files/default/sbin/ifdown index 617ac3ce85..4c24fc7d6f 100755 --- a/openwrt/package/base-files/default/sbin/ifdown +++ b/openwrt/package/base-files/default/sbin/ifdown @@ -1,11 +1,17 @@ -#!/bin/ash +#!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh + type=$1 debug "### ifdown $type ###" + if=$(nvram get ${type}_ifname) proto=$(nvram get ${type}_proto) if_valid $if && $DEBUG ifconfig $if down kill $(cat /var/run/${if}.pid 2>&-) 2>&- -[ "$if" = "ppp0" ] && killall pppd killall ifup.$proto >&- 2>&- +case "$proto" in + pptp|pppoe) killall pppd >&- 2>&- ;; + static) env -i ACTION="ifdown" INTERFACE="$if" PROTO=static /sbin/hotplug "iface" ;; +esac + diff --git a/openwrt/package/base-files/default/usr/share/udhcpc/default.script b/openwrt/package/base-files/default/usr/share/udhcpc/default.script index 0c08985e71..9fac6286c9 100755 --- a/openwrt/package/base-files/default/usr/share/udhcpc/default.script +++ b/openwrt/package/base-files/default/usr/share/udhcpc/default.script @@ -1,42 +1,51 @@ #!/bin/sh -# udhcpc script edited by Tim Riker -# (slightly modified for OpenWrt) - [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1 RESOLV_CONF="/tmp/resolv.conf" -case "$1" in - deconfig) - ifconfig $interface 0.0.0.0 - ;; - - renew|bound) - ifconfig $interface $ip \ - netmask ${subnet:-255.255.255.0} \ - broadcast ${broadcast:-+} - - if [ -n "$router" ] ; then - echo "deleting routers" - while route del default gw 0.0.0.0 dev $interface ; do - : - done - - for i in $router ; do - route add default gw $i dev $interface - done - fi - - echo -n > $RESOLV_CONF - ${domain:+echo search $domain} >> $RESOLV_CONF - for i in $dns ; do - echo adding dns $i - echo nameserver $i >> $RESOLV_CONF +hotplug_event() { + nvram show 2>&- | grep _proto=dhcp | { + while :; do + read FOO + [ -z "$FOO" ] && break + FOO="${FOO%%_*}" + [ "$(nvram get ${FOO}_ifname)" = "${interface}" ] || continue + env -i ACTION="$1" INTERFACE="${FOO}" PROTO=dhcp /sbin/hotplug iface + done + } +} +case "$1" in + deconfig) + ifconfig $interface 0.0.0.0 + hotplug_event ifdown + ;; + renew|bound) + ifconfig $interface $ip \ + netmask ${subnet:-255.255.255.0} \ + broadcast ${broadcast:-+} + + if [ -n "$router" ] ; then + echo "deleting routers" + while route del default gw 0.0.0.0 dev $interface ; do :; done + + for i in $router ; do + route add default gw $i dev $interface + done + fi + + echo -n > $RESOLV_CONF + ${domain:+echo search $domain} >> $RESOLV_CONF + for i in $dns ; do + echo adding dns $i + echo nameserver $i >> $RESOLV_CONF + done + + hotplug_event ifup + # user rules [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user - - done - ;; + ;; esac + exit 0 diff --git a/openwrt/package/base-files/ipkg/hotplug.control b/openwrt/package/base-files/ipkg/hotplug.control deleted file mode 100644 index 5266e85d61..0000000000 --- a/openwrt/package/base-files/ipkg/hotplug.control +++ /dev/null @@ -1,4 +0,0 @@ -Package: hotplug -Priority: optional -Section: net -Description: Hotplug script for WDS diff --git a/openwrt/package/busybox/Makefile b/openwrt/package/busybox/Makefile index 1b11c87b27..336e1a01ea 100644 --- a/openwrt/package/busybox/Makefile +++ b/openwrt/package/busybox/Makefile @@ -39,5 +39,4 @@ $(IPKG_BUSYBOX): $(MAKE) CC=$(TARGET_CC) CROSS="$(TARGET_CROSS)" PREFIX="$(IDIR_BUSYBOX)" \ EXTRA_CFLAGS="$(TARGET_CFLAGS)" -C $(PKG_BUILD_DIR) install $(STRIP) $(IDIR_BUSYBOX)/bin/busybox - -chmod a+x $(IDIR_BUSYBOX)/usr/share/udhcpc/default.script $(IPKG_BUILD) $(IDIR_BUSYBOX) $(PACKAGE_DIR) diff --git a/openwrt/package/ntpclient/Makefile b/openwrt/package/ntpclient/Makefile index 679e5fca59..31fe551947 100644 --- a/openwrt/package/ntpclient/Makefile +++ b/openwrt/package/ntpclient/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ntpclient PKG_VERSION:=2003_194 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_MD5SUM:=94e84d5c6023c5e1f3890b28d0a08c92 PKG_SOURCE_URL:=http://doolittle.faludi.com/ntpclient @@ -26,8 +26,8 @@ $(PKG_BUILD_DIR)/.built: touch $@ $(IPKG_NTPCLIENT): - install -d -m0755 $(IDIR_NTPCLIENT)/etc/init.d - install -m0755 ./files/ntpclient.init $(IDIR_NTPCLIENT)/etc/init.d/S60ntpclient + install -d -m0755 $(IDIR_NTPCLIENT)/etc/hotplug.d/iface + install -m0755 ./files/ntpclient.init $(IDIR_NTPCLIENT)/etc/hotplug.d/iface/10-ntpclient install -d -m0755 $(IDIR_NTPCLIENT)/usr/sbin install -m0755 $(PKG_BUILD_DIR)/ntpclient $(IDIR_NTPCLIENT)/usr/sbin/ $(RSTRIP) $(IDIR_NTPCLIENT) diff --git a/openwrt/package/ntpclient/files/ntpclient.init b/openwrt/package/ntpclient/files/ntpclient.init index 923022bfcc..2ad4beb773 100644 --- a/openwrt/package/ntpclient/files/ntpclient.init +++ b/openwrt/package/ntpclient/files/ntpclient.init @@ -1,2 +1,11 @@ #!/bin/sh -/usr/sbin/ntpclient -c 1 -s -h pool.ntp.org & +server=$(nvram get ntp_server) +case "$ACTION" in + ifup) + ps x | grep '[n]tpclient' >&- || { + route -n 2>&- | grep '0.0.0.0' >&- && /usr/sbin/ntpclient -c 1 -s -h ${server:-pool.ntp.org} & + } + ;; + ifdown) + route -n 2>&- | grep '0.0.0.0' >&- || killall ntpclient 2>&- >&- ;; +esac diff --git a/openwrt/package/ppp/Makefile b/openwrt/package/ppp/Makefile index 0fed25c91e..4b31760bcb 100644 --- a/openwrt/package/ppp/Makefile +++ b/openwrt/package/ppp/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ppp PKG_VERSION:=2.4.3 -PKG_RELEASE:=6 +PKG_RELEASE:=7 PKG_MD5SUM:=848f6c3cafeb6074ffeb293c3af79b7c PKG_SOURCE_URL:=ftp://ftp.samba.org/pub/ppp/ @@ -80,6 +80,8 @@ $(IPKG_PPP): ln -sf /tmp/resolv.conf $(IDIR_PPP)/etc/ppp/resolv.conf install -m0600 ./files/etc/ppp/chap-secrets $(IDIR_PPP)/etc/ppp/ install -m0644 ./files/etc/ppp/options $(IDIR_PPP)/etc/ppp/ + install -m0755 ./files/etc/ppp/ip-up $(IDIR_PPP)/etc/ppp/ + install -m0755 ./files/etc/ppp/ip-down $(IDIR_PPP)/etc/ppp/ install -d -m0755 $(IDIR_PPP)/etc/ppp/peers install -m0644 ./files/etc/ppp/peers/sample $(IDIR_PPP)/etc/ppp/peers/ install -d -m0755 $(IDIR_PPP)/usr/sbin diff --git a/openwrt/package/ppp/files/etc/ppp/ip-down b/openwrt/package/ppp/files/etc/ppp/ip-down new file mode 100644 index 0000000000..044759fbf1 --- /dev/null +++ b/openwrt/package/ppp/files/etc/ppp/ip-down @@ -0,0 +1,2 @@ +#!/bin/sh +[ -z "$6" ] || env -i ACTION="ifdown" INTERFACE="$6" PROTO=ppp /sbin/hotplug "iface" diff --git a/openwrt/package/ppp/files/etc/ppp/ip-up b/openwrt/package/ppp/files/etc/ppp/ip-up new file mode 100644 index 0000000000..c67a3d03c5 --- /dev/null +++ b/openwrt/package/ppp/files/etc/ppp/ip-up @@ -0,0 +1,2 @@ +#!/bin/sh +[ -z "$6" ] || env -i ACTION="ifup" INTERFACE="$6" PROTO=ppp /sbin/hotplug "iface" diff --git a/openwrt/package/ppp/files/ifup.pppoe b/openwrt/package/ppp/files/ifup.pppoe index fcf06aeed0..80d44783b6 100644 --- a/openwrt/package/ppp/files/ifup.pppoe +++ b/openwrt/package/ppp/files/ifup.pppoe @@ -22,7 +22,6 @@ while :; do IDLETIME=${IDLETIME:+lcp-echo-failure $IDLETIME} MTU=$(nvram get ppp_mtu) MTU=${MTU:-1492} - MTU=${MTU:+ mtu $MTU mru $MTU} ifconfig $IFNAME up /usr/sbin/pppd nodetach \ @@ -31,10 +30,12 @@ while :; do usepeerdns \ defaultroute \ replacedefaultroute \ - linkname $type \ + ipparam "$type" \ + linkname "$type" \ user "$USERNAME" \ password "$PASSWORD" \ - $MTU \ + mtu $MTU \ + mru $MTU \ $IDLETIME \ $REDIAL \ nic-$IFNAME diff --git a/openwrt/package/pptp/Makefile b/openwrt/package/pptp/Makefile index 3334f23114..870341c87d 100644 --- a/openwrt/package/pptp/Makefile +++ b/openwrt/package/pptp/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=pptp PKG_VERSION:=1.6.0 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_MD5SUM:=9a706327fb9827541d7c86d48ceb9631 PKG_SOURCE_URL:=@SF/pptpclient diff --git a/openwrt/package/pptp/files/ifup.pptp b/openwrt/package/pptp/files/ifup.pptp index 15178fe302..acaeabd971 100644 --- a/openwrt/package/pptp/files/ifup.pptp +++ b/openwrt/package/pptp/files/ifup.pptp @@ -22,7 +22,7 @@ while :; do IDLETIME=$(nvram get ppp_idletime) IDLETIME=${IDLETIME:+lcp-echo-failure $IDLETIME} MTU=$(nvram get ppp_mtu) - MTU=${MTU:+ mtu $MTU mru $MTU} + MTU=${MTU:-1452} do_ifup $PPTP_PROTO $type @@ -38,10 +38,12 @@ while :; do usepeerdns \ defaultroute \ replacedefaultroute \ - linkname $type \ + linkname "$type" \ + ipparam "$type" \ user "$USERNAME" \ password "$PASSWORD" \ - $MTU \ + mtu $MTU \ + mru $MTU \ $IDLETIME \ $REDIAL done & diff --git a/openwrt/target/linux/imagebuilder/lists/default.brcm-2.4 b/openwrt/target/linux/imagebuilder/lists/default.brcm-2.4 index 52e01cf477..132ff48222 100644 --- a/openwrt/target/linux/imagebuilder/lists/default.brcm-2.4 +++ b/openwrt/target/linux/imagebuilder/lists/default.brcm-2.4 @@ -5,7 +5,6 @@ busybox dnsmasq dropbear haserl -hotplug ipkg iptables kmod-brcm-et diff --git a/openwrt/target/linux/imagebuilder/lists/micro.brcm-2.4 b/openwrt/target/linux/imagebuilder/lists/micro.brcm-2.4 index 86e47d53ab..078884312e 100644 --- a/openwrt/target/linux/imagebuilder/lists/micro.brcm-2.4 +++ b/openwrt/target/linux/imagebuilder/lists/micro.brcm-2.4 @@ -4,7 +4,6 @@ bridge busybox dnsmasq dropbear -hotplug ipkg iptables kmod-brcm-et diff --git a/openwrt/target/linux/imagebuilder/lists/pptp.brcm-2.4 b/openwrt/target/linux/imagebuilder/lists/pptp.brcm-2.4 index 4bcef47198..6da50bc60a 100644 --- a/openwrt/target/linux/imagebuilder/lists/pptp.brcm-2.4 +++ b/openwrt/target/linux/imagebuilder/lists/pptp.brcm-2.4 @@ -5,7 +5,6 @@ busybox dnsmasq dropbear haserl -hotplug ipkg iptables kmod-brcm-et -- 2.30.2