Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:base-system:hotplug [2023/10/04 22:53] – [Get specific IP address] split common parts to hotplug extras vgaetera | docs:guide-user:base-system:hotplug [2024/08/23 10:25] – Avoid duplication/duplicate execution oliv3r | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| Which is why most scripts in there use a numeric prefix. | Which is why most scripts in there use a numeric prefix. | ||
| - | ^ Directory ^ Description ^ | + | ^ Directory |
| - | | **block** | Block device events: device connected/ | + | | **block** |
| - | | **button** | Buttons: not created by default, see [[docs: | + | | **button** |
| - | | **dhcp** | DHCP-related events | | + | | **dhcp** |
| - | | **dsl** | DSL modem events | | + | | **dsl** |
| - | | **firewall** | Firewall-related events | | + | | **firewall** |
| - | | **iface** | Interface events: LAN/ | + | | **iface** |
| - | | **neigh** | Neighbor discovery | | + | | **neigh** |
| - | | **net** | Network-related events | | + | | **net** |
| - | | **ntp** | Time sync events: time step, time server stratum change | | + | | **ntp** |
| - | | **tftp** | TFTP-related events | | + | | **tftp** |
| - | | **usb** | USB devices like 3g-modem and tty* | | + | | **tty** |
| + | | **usb** | ||
| + | | **usbmisc** | ||
| See also: | See also: | ||
| Line 49: | Line 51: | ||
| ===== Event classes / Directories ===== | ===== Event classes / Directories ===== | ||
| + | ==== net ==== | ||
| + | For scripts in **net** directory, these are the (relevant) environmental variables | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | ACTION | " | ||
| + | | DEVICENAME | configured interface names (br-lan, wlan0, phy1-ap0 | | ||
| + | | PATH | Full path | | ||
| + | | DEVPATH | full device path (for example "/ | ||
| + | | DEVTYPE | what the DEVICENAME are names of, ie. br-lan, phy1-ap0 | | ||
| + | | INTERFACE | configured interfaces as in DEVTYPE | | ||
| + | | SEQNUM | seqnum (a number) | | ||
| + | | SUBSYSTEM | always = " | ||
| + | | IFINDEX | appears to be related to the configured interfaces. See `ifconfig` | | ||
| + | |||
| ==== block ==== | ==== block ==== | ||
| For scripts in **block** directory, these are the (relevant) environmental variables | For scripts in **block** directory, these are the (relevant) environmental variables | ||
| Line 131: | Line 147: | ||
| Even without NTP sync, you will receive a " | Even without NTP sync, you will receive a " | ||
| + | |||
| + | ==== tty ==== | ||
| + | ^ Variable name ^ description ^ | ||
| + | | ACTION | add, remove, bind, unbind as above | | ||
| + | | DEVICENAME | eg " | ||
| + | | DEVNAME | only for bind/ | ||
| + | | DEVPATH | eg, "/ | ||
| + | | SEQNUM | (action number since boot for this subsystem) eg 335 | | ||
| + | | SUBSYSTEM | Specific type of device, eg, " | ||
| + | | MAJOR | eg 189 | | ||
| + | | MINOR | eg 1 | | ||
| ==== usb ==== | ==== usb ==== | ||
| ^ Variable name ^ description ^ | ^ Variable name ^ description ^ | ||
| - | | ACTION | add, remove | + | | ACTION | add, remove, |
| - | | DEVNAME | eg, " | + | |
| - | | DEVPATH | eg, "/ | + | |
| | DEVICENAME | eg " | | DEVICENAME | eg " | ||
| + | | DEVNAME | eg, " | ||
| | DEVNUM | eg 002 | | | DEVNUM | eg 002 | | ||
| - | | DRIVER | + | | DEVPATH |
| + | | DEVTYPE | eg " | ||
| | TYPE | eg 9/0/1 | | | TYPE | eg 9/0/1 | | ||
| | PRODUCT | the vendor/ | | PRODUCT | the vendor/ | ||
| - | | SEQNUM | ? eg 335 | | + | | SEQNUM | (action number since boot for this subsystem) |
| | BUSNUM | eg 001 | | | BUSNUM | eg 001 | | ||
| | MAJOR | eg 189 | | | MAJOR | eg 189 | | ||
| | MINOR | eg 1 | | | MINOR | eg 1 | | ||
| + | |||
| + | ==== usbmisc ==== | ||
| + | ^ Variable name ^ description | ||
| + | | ACTION | ||
| + | | DEVNAME | ||
| + | | DEVPATH | ||
| + | | DEVICENAME | ||
| + | | SEQNUM | ||
| + | | MAJOR | eg 189 | | ||
| + | | MINOR | eg 1 | | ||
| + | |||
| ===== Examples ===== | ===== Examples ===== | ||
| Line 160: | Line 198: | ||
| ==== Symlink instead of rename a device ==== | ==== Symlink instead of rename a device ==== | ||
| An other script to create a symlink instead of renaming the device. | An other script to create a symlink instead of renaming the device. | ||
| - | I test if DEVICE_NAME is empty because when I plug usb device I retrieve two add event, and the first come before created device, so symlink fails. | ||
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | CP210_PRODID="10c4/ | + | CP210_PRODID='10c4/ |
| SYMLINK=" | SYMLINK=" | ||
| - | if [ " | + | set -eu |
| - | if [ " | + | |
| - | DEVICE_NAME=$(ls / | + | |
| - | if [ -z ${DEVICE_NAME} ]; then | + | |
| - | logger -t hotplug " | + | |
| - | exit 0 | + | |
| - | fi | + | |
| - | logger -t hotplug " | + | |
| - | ln -s / | + | |
| - | logger -t hotplug " | + | |
| - | fi | + | |
| - | fi | + | |
| - | if [ " | + | if [ " |
| - | if [ " | + | [ " |
| - | rm / | + | if [ " |
| - | logger -t hotplug " | + | if [ -L "/ |
| - | fi | + | logger -t hotplug " |
| + | exit 0 | ||
| + | fi | ||
| + | |||
| + | DEVICE_NAME=" | ||
| + | if [ -z " | ||
| + | logger -t hotplug ' | ||
| + | exit 0 | ||
| + | fi | ||
| + | |||
| + | logger -t hotplug " | ||
| + | ln -s "/ | ||
| + | logger -t hotplug " | ||
| + | fi | ||
| + | |||
| + | |||
| + | if [ " | ||
| + | rm "/ | ||
| + | logger -t hotplug " | ||
| + | fi | ||
| fi | fi | ||
| EOF | EOF | ||
| </ | </ | ||
| - | + | ==== Script that detects | |
| - | ==== Script that detects | + | |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| Line 221: | Line 265: | ||
| add) | add) | ||
| # start process | # start process | ||
| - | | + | |
| ;; | ;; | ||
| remove) | remove) | ||
| # stop process | # stop process | ||
| - | | + | |
| ;; | ;; | ||
| esac | esac | ||
| Line 259: | Line 303: | ||
| ==== Coldplug ==== | ==== Coldplug ==== | ||
| - | If you had notice | + | You may have noticed that the udev and eudev were removed in the openwrt 18.0.* release. Don' |
| You can use hotplug scripts as coldplug. | You can use hotplug scripts as coldplug. | ||
| - | Pay attention | + | Pay attention |
| - | So, just add this option to hotplug run accordinly. | + | So, just add this option to hotplug |
| In my case I used this: | In my case I used this: | ||
| Line 373: | Line 418: | ||
| . / | . / | ||
| network_flush_cache | network_flush_cache | ||
| - | network_find_wan | + | network_find_wan |
| - | network_get_ipaddr | + | network_get_ipaddr |
| - | if [ "${NET_IF}" != " | + | if [ "${WAN_IF}" != " |
| then exit 0 | then exit 0 | ||
| fi | fi | ||
| - | case ${NET_ADDR} in | + | case ${WAN_ADDR} in |
| (??.???.*) exit 0 ;; | (??.???.*) exit 0 ;; | ||
| esac | esac | ||
| Line 387: | Line 432: | ||
| ==== Rename interfaces by MAC address ==== | ==== Rename interfaces by MAC address ==== | ||
| - | A simple method to configure persistent interface names by MAC address. | ||
| Assuming pre-configured upstream interfaces '' | Assuming pre-configured upstream interfaces '' | ||
| + | Set up persistent interface names by MAC address. | ||
| <code bash> | <code bash> | ||
| Line 394: | Line 439: | ||
| dev_rename() { | dev_rename() { | ||
| local DEV_CONF=" | local DEV_CONF=" | ||
| - | local DEV_ONAME DEV_NAME | + | local DEV_MAC DEV_NAME |
| - | config_get | + | |
| config_get DEV_MAC " | config_get DEV_MAC " | ||
| + | config_get DEV_NAME " | ||
| DEV_ONAME=" | DEV_ONAME=" | ||
| $(find / | $(find / | ||
| | sed -e " | | sed -e " | ||
| | awk -F '/' | | awk -F '/' | ||
| - | if [ " | + | if [ -n " |
| + | && | ||
| then ip link set " | then ip link set " | ||
| fi | fi | ||
| Line 416: | Line 462: | ||
| uci -q delete network.${DEV_NAME}_dev | uci -q delete network.${DEV_NAME}_dev | ||
| uci set network.${DEV_NAME}_dev=" | uci set network.${DEV_NAME}_dev=" | ||
| - | uci set network.${DEV_NAME}_dev.name=" | ||
| uci set network.${DEV_NAME}_dev.mac=" | uci set network.${DEV_NAME}_dev.mac=" | ||
| + | uci set network.${DEV_NAME}_dev.name=" | ||
| done << EOI | done << EOI | ||
| wana 11: | wana 11: | ||
| Line 423: | Line 469: | ||
| EOI | EOI | ||
| uci commit network | uci commit network | ||
| - | / | + | service |
| </ | </ | ||
| + | ==== Create deterministic/ | ||
| + | Resulting links will be placed in / | ||
| + | with a name structure closely resembling links created by udev, but not fully exact. | ||
| + | |||
| + | <code bash> | ||
| + | set -o pipefail | ||
| + | [ " | ||
| + | [ " | ||
| + | [ -n " | ||
| + | |||
| + | if [ " | ||
| + | subsystem=" | ||
| + | |||
| + | [ " | ||
| + | |||
| + | replace_whitespace=" | ||
| + | manufacturer=" | ||
| + | product=" | ||
| + | serial=" | ||
| + | interface=" | ||
| + | port=" | ||
| + | |||
| + | replace_chars=" | ||
| + | id_link=$(echo " | ||
| + | path_link=$(echo " | ||
| + | |||
| + | mkdir -p / | ||
| + | ln -sf "/ | ||
| + | ln -sf "/ | ||
| + | elif [ " | ||
| + | for link in $(find /dev/serial -type l); do | ||
| + | [ -L ${link} -a " | ||
| + | done | ||
| + | fi | ||
| + | </ | ||
| + | [[https:// | ||