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 [2019/03/27 19:42] – ↷ Page name changed from docs:guide-user:base-system:hotplug_lede to docs:guide-user:base-system:hotplug tmomas | docs:guide-user:base-system:hotplug [2024/08/23 10:27] – Add ser2net example oliv3r | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Hotplug ====== | ====== Hotplug ====== | ||
| - | + | Procd (the init system and process management daemon) executes scripts located in ''/ | |
| - | Procd (the init system and process management daemon) executes scripts located in ''/ | + | |
| It can be very useful with PPPoE connection or in an unstable network, or to use hardware buttons. | It can be very useful with PPPoE connection or in an unstable network, or to use hardware buttons. | ||
| Line 7: | Line 6: | ||
| ===== How it works ===== | ===== How it works ===== | ||
| + | In the ''/ | ||
| - | In the ''/ | + | When the trigger event fires, Procd will execute all scripts in that trigger's directory, in alphabetical order. |
| + | Which is why most scripts in there use a numeric prefix. | ||
| - | When the trigger event fires, Procd will execute all scripts in that trigger' | + | ^ Directory |
| + | | **block** | ||
| + | | **button** | ||
| + | | **dhcp** | ||
| + | | **dsl** | ||
| + | | **firewall** | ||
| + | | **iface** | ||
| + | | **neigh** | ||
| + | | **net** | ||
| + | | **ntp** | ||
| + | | **tftp** | ||
| + | | **tty** | ||
| + | | **usb** | ||
| + | | **usbmisc** | ||
| - | * **block** folder is for block device events (block device connected/ | + | See also: |
| - | * **iface** folder is for interface events (when a interface like LAN or WAN is connected/disconnected) | + | * [[https:// |
| - | * **net** folder is for :?: (probably | + | * [[https:// |
| - | * **ntp** folder is for time sync events (time step, time server stratum change) | + | * [[docs: |
| - | * **button** folder is for buttons (not created by default, see [[docs: | + | |
| - | * **usb** folder is for usb devices like 3g-modem and tty* | + | |
| - | There may (should) be others, for other types of triggers. By looking at the source [[https:// | + | ===== Usage / Troubleshooting |
| + | Simply place your script(s) into the right hotplug.d directory, if there is none just create the right one. | ||
| - | ===== Usage ===== | + | Procd exposes a wealth of info when executes |
| - | Simply place your script(s) into the right hotplug.d | + | |
| - | ===== Information provided | + | If you want to see what environmental variables |
| - | Procd exposes a wealth of info when executes your scripts in hotplug.d, usually as environmental variables. | + | |
| - | If you want to see what environmental variables it is providing, make a script that contains this line: | ||
| <code bash> | <code bash> | ||
| - | env > /tmp/envs_log.log | + | cat << " |
| + | logger -t hotplug $(env) | ||
| + | EOF | ||
| </ | </ | ||
| - | and place it in the folder you want to use, then trigger the event connected to that folder, and then you can see what envs were passed by reading the '' | + | Then trigger the event connected to that directory, and then you can see what envs were passed by reading the output: |
| + | |||
| + | <code bash> | ||
| + | logread -e hotplug | ||
| + | </code> | ||
| + | |||
| + | ===== Event classes | ||
| + | ==== 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` | | ||
| - | ==== The block folder | + | ==== block ==== |
| - | For scripts in **block** | + | For scripts in **block** |
| ^ Variable name ^ Description ^ | ^ Variable name ^ Description ^ | ||
| - | | ACTION | Either | + | | ACTION | For normal device (e.g: sda) it is either |
| | DEVICENAME | seems same as DEVNAME below | | | DEVICENAME | seems same as DEVNAME below | | ||
| | DEVNAME | Device or partition name (if I connect a drive I get a hotplug call with " | | DEVNAME | Device or partition name (if I connect a drive I get a hotplug call with " | ||
| Line 48: | Line 79: | ||
| | SUBSYSTEM | seems this is only " | | SUBSYSTEM | seems this is only " | ||
| - | ==== The iface folder | + | ==== dsl ==== |
| + | For scripts in **dsl** directory, these are the (relevant) environment variables | ||
| - | There are three main environment variables that are passed to each **iface** hotplug script: | ||
| ^ Variable name ^ Description ^ | ^ Variable name ^ Description ^ | ||
| - | | ACTION | + | | DSL_NOTIFICATION_TYPE |
| - | | INTERFACE | + | | DSL_LINE_NUMBER |
| - | | DEVICE | Physical device name which interface went up or down (e.g. "eth0.1" or " | + | |
| - | ==== The ntp folder | + | When DSL_NOTIFICATION_TYPE is '' |
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | DSL_XTU_STATUS | '' | ||
| + | | DSL_TC_LAYER_STATUS | '' | ||
| + | | DSL_EFM_TC_CONFIG_US | '' | ||
| + | | DSL_EFM_TC_CONFIG_DS | '' | ||
| + | |||
| + | When DSL_NOTIFICATION_TYPE is '' | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | DSL_INTERFACE_STATUS | '' | ||
| + | | DSL_BONDING_STATUS | '' | ||
| + | |||
| + | When DSL_NOTIFICATION_TYPE is '' | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | DSL_DATARATE_US_BC0 | Upstream data rate in bit/s for Channel 0 | | ||
| + | | DSL_DATARATE_US_BC1 | Upstream data rate in bit/s for Channel 1 * | | ||
| + | |||
| + | When DSL_NOTIFICATION_TYPE is '' | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | DSL_DATARATE_DS_BC0 | Downstream data rate in bit/s for Channel 0 | | ||
| + | | DSL_DATARATE_DS_BC1 | Downstream data rate in bit/s for Channel 1 * | | ||
| + | |||
| + | NOTE: environment variables marked with an * are only available when channel bonding support is compiled in. | ||
| + | |||
| + | ==== iface ==== | ||
| + | For scripts in **iface** directory, these are the (relevant) environmental variables | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | ACTION | '' | ||
| + | | INTERFACE | Name of the logical interface which went up or down (e.g. '' | ||
| + | | DEVICE | Name of the physical device which went up or down (e.g. '' | ||
| + | |||
| + | The meaning of most actions should be straightforward, | ||
| + | ^ Value ^ Description ^ | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | When ACTION is '' | ||
| + | |||
| + | ^ Variable name ^ Description ^ | ||
| + | | IFUPDATE_ADDRESSES | '' | ||
| + | | IFUPDATE_ROUTES | '' | ||
| + | | IFUPDATE_PREFIXES | '' | ||
| + | | IFUPDATE_DATA | '' | ||
| + | |||
| + | ==== ntp ==== | ||
| + | Variables based on busybox ntpd: | ||
| ^ Variable name ^ description ^ | ^ Variable name ^ description ^ | ||
| | ACTION | step, stratum, unsync or periodic | | | ACTION | step, stratum, unsync or periodic | | ||
| | freq_drift_ppm | ntp variables | | | freq_drift_ppm | ntp variables | | ||
| - | | offset | ntp variables | + | | offset | Time adjustment done | |
| - | | stratum | ntp variables | + | | stratum | Quality (nr of servers to atomic clock) |
| | poll_interval | ntp variables | | | poll_interval | ntp variables | | ||
| - | Even without NTP sync, you will receive a periodic hotplug event, with stratum=16, about every 11 minutes out of the box. | + | Even without NTP sync, you will receive a "periodic" |
| - | ==== The usb folder | + | ==== tty ==== |
| ^ Variable name ^ description ^ | ^ Variable name ^ description ^ | ||
| - | | ACTION | add, remove as above | | + | | ACTION | add, remove, bind, unbind |
| - | | DEVNAME | eg, "bus/ | + | | DEVICENAME | eg " |
| - | | DEVPATH | 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 ==== | ||
| + | ^ Variable name ^ description ^ | ||
| + | | ACTION | add, remove, bind, unbind as above | | ||
| | 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 ===== | ||
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | [ " | + | [ "${ACTION}" = "ifup" |
| - | logger -t button-hotplug Device: $DEVICE / Action: $ACTION | + | logger -t hotplug |
| } | } | ||
| EOF | EOF | ||
| Line 93: | Line 196: | ||
| Every time an interface goes up then the if/fi statement will be executed. | Every time an interface goes up then the if/fi statement will be executed. | ||
| - | === Restart wlan on USB WiFi hotplug | + | ==== Symlink instead of rename a device |
| + | An other script to create a symlink instead of renaming the device. | ||
| - | Niii has posted this quick example for a USB WiFi device | + | <code bash> |
| + | cat << " | ||
| + | CP210_PRODID=' | ||
| + | SYMLINK=" | ||
| - | To determine RTL8188SU_PRODID variable: | + | set -eu |
| - | <code bash># lsusb -v | + | |
| - | idVendor | + | |
| - | idProduct | + | |
| - | bcdDevice | + | |
| - | </ | + | |
| - | <code bash> | + | if [ "${DEVTYPE: |
| - | cat << | + | [ " |
| - | BINARY="/sbin/wifi up" | + | if [ " |
| - | RTL8188SU_PRODID="bda/8171/200" | + | if [ -L "/dev/${SYMLINK}" |
| + | logger -t hotplug | ||
| + | exit 0 | ||
| + | fi | ||
| - | if [ "${PRODUCT}" | + | DEVICE_NAME="$(find /sys${DEVPATH:-} -maxdepth 1 -type d -iname ' |
| - | if [ " | + | if [ -z "${DEVICE_NAME}" ]; then |
| - | ${BINARY} | + | logger -t hotplug ' |
| - | fi | + | exit 0 |
| + | fi | ||
| + | |||
| + | logger -t hotplug " | ||
| + | ln -s "/ | ||
| + | logger -t hotplug " | ||
| + | fi | ||
| + | |||
| + | |||
| + | if [ " | ||
| + | rm "/dev/${SYMLINK}" | ||
| + | logger -t hotplug " | ||
| + | fi | ||
| fi | fi | ||
| EOF | EOF | ||
| </ | </ | ||
| - | === Symlink | + | ==== Start ser2net |
| + | Similarly, it is also possible to start `ser2net` to make the serial port remotely available | ||
| - | 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=" | + | SER2NET_PID='/ |
| + | SER2NET_PORT=18888 | ||
| + | SER2NET_OPTS=' | ||
| - | if [ " | + | set -eu |
| - | then if [ " | + | |
| - | then | + | |
| - | | + | |
| - | if [ -z ${DEVICE_NAME} ]; | + | |
| - | then logger -t Hotplug Warning DEVICE_NAME is empty | + | |
| - | exit | + | |
| - | fi | + | |
| - | | + | |
| - | ln -s / | + | |
| - | | + | |
| - | fi | + | |
| - | fi | + | |
| - | if [ " | + | if [ " |
| - | then if [ " | + | [ " |
| - | | + | if [ " |
| - | rm /dev/${SYMLINK} | + | if [ -s "${SER2NET_PID}" ]; then |
| - | | + | logger -t hotplug " |
| - | | + | exit 0 |
| + | fi | ||
| + | DEVICE_NAME=" | ||
| + | if [ -z " | ||
| + | logger -t hotplug ' | ||
| + | exit 0 | ||
| + | fi | ||
| + | logger -t hotplug " | ||
| + | ser2net -C " | ||
| + | logger -t hotplug " | ||
| + | fi | ||
| + | |||
| + | if [ " | ||
| + | logger -t hotplug " | ||
| + | kill -3 "$(cat " | ||
| + | if [ ! -s " | ||
| + | logger -t hotplug ' | ||
| + | exit 0 | ||
| + | fi | ||
| + | fi | ||
| fi | fi | ||
| EOF | EOF | ||
| </ | </ | ||
| - | + | ==== Script that detects | |
| - | === Script that detects | + | |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| BT_PRODID=" | BT_PRODID=" | ||
| - | BT_PRODID_HOT=`echo $PRODUCT | + | BT_PRODID_HOT="${PRODUCT::6}" |
| - | #logger -t HOTPLUG | + | #logger -t hotplug |
| - | if [ " | + | if [ "${BT_PRODID_HOT}" = "${BT_PRODID}" ]; then |
| - | if [ " | + | if [ "${ACTION}" = " |
| - | logger -t HOTPLUG | + | logger -t hotplug |
| - | if [ " | + | if [ "${BSBTID_NEW}" = "${BSBTID_OLD}" ]; then |
| - | logger -t HOTPLUG | + | logger -t hotplug |
| else | else | ||
| - | logger -t HOTPLUG | + | logger -t hotplug |
| fi | fi | ||
| fi | fi | ||
| - | if [ " | + | if [ "${ACTION}" = " |
| - | logger -t HOTPLUG | + | logger -t hotplug |
| fi | fi | ||
| else | else | ||
| - | logger -t HOTPLUG | + | logger -t hotplug |
| fi | fi | ||
| EOF | EOF | ||
| </ | </ | ||
| - | === Auto start mjpg-streamer when an usb camera is plugged in. === | + | ==== Auto start mjpg-streamer when an usb camera is plugged in ==== |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | case " | + | case "${ACTION}" in |
| add) | add) | ||
| # start process | # start process | ||
| - | | + | |
| ;; | ;; | ||
| remove) | remove) | ||
| # stop process | # stop process | ||
| - | | + | |
| ;; | ;; | ||
| esac | esac | ||
| Line 193: | Line 316: | ||
| </ | </ | ||
| - | === Custom automount script for xfs === | + | ==== Custom automount script for XFS ==== |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| # if a new block device is connected | # if a new block device is connected | ||
| - | if [ " | + | if [ "${ACTION}" = " |
| # getting device UUID | # getting device UUID | ||
| - | detected_uuid=$( xfs_admin -u / | + | detected_uuid="$(xfs_admin -u /dev/${DEVICENAME} | awk ' |
| # deciding mountpoint for known UUID | # deciding mountpoint for known UUID | ||
| mountpoint="" | mountpoint="" | ||
| - | case " | + | case "${detected_uuid}" in |
| - | 6a5d7c5c-c9d0-41cc-8f19-78d97f839c05) | + | 6a5d7c5c-c9d0-41cc-8f19-78d97f839c05) |
| mountpoint="/ | mountpoint="/ | ||
| ;; | ;; | ||
| - | | + | |
| mountpoint="/ | mountpoint="/ | ||
| ;; | ;; | ||
| - | esac | + | |
| - | # if we have a known UUID we have a mountpoint so we can mount it | + | |
| - | | + | if [ "${mountpoint}" != "" |
| - | | + | mount /dev/${DEVICENAME} ${mountpoint} |
| - | | + | fi |
| fi | fi | ||
| # unmounting happens automatically at device disconnection anyway so no logic for that | # unmounting happens automatically at device disconnection anyway so no logic for that | ||
| Line 220: | Line 343: | ||
| </ | </ | ||
| - | ===== Coldplug ===== | + | ==== Coldplug ==== |
| + | You may have noticed that the udev and eudev were removed in the openwrt 18.0.* release. Don't worry, because you still can make things work. | ||
| + | You can use hotplug scripts as coldplug. | ||
| + | Pay attention to the ACTION environment variable, at boot ' | ||
| + | So, just add this option to hotplug and run accordingly. | ||
| - | If you had notice the udev and eudev were removed in the openwrt 18.0.* release, don't be afraid because you still can make the things works.\\ | + | In my case I used this: |
| - | **Using hotplug scripts as coldplug**\\ | + | |
| - | You just need to pay atention at the ACTION env var, at the boot are executed ' | + | |
| - | So, just add this option to hotplug run accordinly. | + | |
| <code bash> | <code bash> | ||
| + | mkdir -p / | ||
| cat << " | cat << " | ||
| # Description: | # Description: | ||
| - | if [ " | + | if [ "${ACTION}" = "bind" |
| case " | case " | ||
| 1bc7*) # Telit HE910 3g modules product id prefix | 1bc7*) # Telit HE910 3g modules product id prefix | ||
| - | DEVICE_NAME=$(ls / | + | DEVICE_NAME="$(ls /sys/${DEVPATH} | grep tty)" |
| - | DEVICE_TTY=$(ls / | + | DEVICE_TTY="$(ls /sys/${DEVPATH}/tty/)" |
| # Module Telit HE910-* connected to minipciexpress slot MAIN | # Module Telit HE910-* connected to minipciexpress slot MAIN | ||
| - | if [ ${DEVICENAME} = '1-1.3:1.0' | + | if [ "${DEVICENAME}" |
| - | ln -s / | + | ln -s /dev/${DEVICE_TTY} / |
| - | logger -t Hotplug | + | logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to / |
| - | elif [ ${DEVICENAME} = '1-1.3:1.6' | + | elif [ "${DEVICENAME}" |
| - | ln -s / | + | ln -s /dev/${DEVICE_TTY} / |
| - | logger -t Hotplug | + | logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to / |
| # Module Telit HE910-* connected to minipciexpress slot SECONDARY | # Module Telit HE910-* connected to minipciexpress slot SECONDARY | ||
| - | elif [ ${DEVICENAME} = '1-1.2:1.0' | + | elif [ "${DEVICENAME}" |
| - | ln -s / | + | ln -s /dev/${DEVICE_TTY} / |
| - | logger -t Hotplug | + | logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to / |
| - | elif [ ${DEVICENAME} = '1-1.2:1.6' | + | elif [ "${DEVICENAME}" |
| - | ln -s / | + | ln -s /dev/${DEVICE_TTY} / |
| - | logger -t Hotplug | + | logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to / |
| fi | fi | ||
| ;; | ;; | ||
| Line 254: | Line 379: | ||
| fi | fi | ||
| # Action to remove the symlinks | # Action to remove the symlinks | ||
| - | if [ " | + | if [ "${ACTION}" = "remove" |
| case " | case " | ||
| 1bc7*) | 1bc7*) | ||
| # Module Telit HE910-* connected to minipciexpress slot MAIN | # Module Telit HE910-* connected to minipciexpress slot MAIN | ||
| - | if [ ${DEVICENAME} = '1-1.3:1.0' | + | if [ "${DEVICENAME}" |
| rm / | rm / | ||
| - | logger -t Hotplug | + | logger -t hotplug "Symlink / |
| - | elif [ ${DEVICENAME} = '1-1.3:1.6' | + | elif [ "${DEVICENAME}" |
| rm / | rm / | ||
| - | logger -t Hotplug | + | logger -t hotplug "Symlink / |
| # Module Telit HE910-* connected to minipciexpress slot SECONDARY | # Module Telit HE910-* connected to minipciexpress slot SECONDARY | ||
| - | elif [ ${DEVICENAME} = '1-1.2:1.0' | + | elif [ "${DEVICENAME}" |
| rm / | rm / | ||
| - | logger -t Hotplug | + | logger -t hotplug "Symlink / |
| - | elif [ ${DEVICENAME} = '1-1.2:1.6' | + | elif [ "${DEVICENAME}" |
| rm / | rm / | ||
| - | logger -t Hotplug | + | logger -t hotplug "Symlink / |
| fi | fi | ||
| ;; | ;; | ||
| Line 278: | Line 403: | ||
| </ | </ | ||
| + | ==== Log DSL status changes ==== | ||
| + | If you have a DSL modem you can add logging of DSL status changes and connection data rates. | ||
| + | |||
| + | This can be helpful if your DSL connection is affected by Seamless Rate Adaptation (SRA) or | ||
| + | Dynamic Line Management (DLM) events; for SRA events data rate changes will be logged, while | ||
| + | for DLM events connection status changes will be logged as the modem is forced to retrain and then the new | ||
| + | data rates will be logged. | ||
| + | |||
| + | <code bash> | ||
| + | cat << " | ||
| + | case " | ||
| + | (DSL_INTERFACE_STATUS) | ||
| + | logger -p daemon.notice -t dsl-notify " | ||
| + | (DSL_DATARATE_STATUS_US) | ||
| + | logger -p daemon.notice -t dsl-notify "DSL upstream actual data rate: ${DSL_DATARATE_US_BC0}" | ||
| + | (DSL_DATARATE_STATUS_DS) | ||
| + | logger -p daemon.notice -t dsl-notify "DSL downstream actual data rate: ${DSL_DATARATE_DS_BC0}" | ||
| + | esac | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | This script assumes that channel bonding is not compiled in to the DSL support. | ||
| + | |||
| + | ==== Utilize wireless USB adapter ==== | ||
| + | Restart Wi-Fi when plugging in a wireless USB adapter. | ||
| + | |||
| + | <code bash> | ||
| + | mkdir -p / | ||
| + | cat << " | ||
| + | if [ " | ||
| + | && [ " | ||
| + | then wifi | ||
| + | fi | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | The above code matches the following device. | ||
| + | |||
| + | <code bash> | ||
| + | # lsusb -v | ||
| + | idVendor 0x0bda Realtek Semiconductor Corp. | ||
| + | idProduct 0x8171 RTL8188SU 802.11n WLAN Adapter | ||
| + | bcdDevice 2.00 | ||
| + | </ | ||
| + | |||
| + | ==== Get specific IP address ==== | ||
| + | Assuming your ISP provides a dynamic IP address. | ||
| + | Reconnect until you get the one matching a specific regexp. | ||
| + | Delay for 10 seconds between reconnects. | ||
| + | Set up [[docs: | ||
| + | |||
| + | <code bash> | ||
| + | mkdir -p / | ||
| + | cat << " | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_find_wan WAN_IF | ||
| + | network_get_ipaddr WAN_ADDR " | ||
| + | if [ " | ||
| + | then exit 0 | ||
| + | fi | ||
| + | case ${WAN_ADDR} in | ||
| + | (??.???.*) exit 0 ;; | ||
| + | esac | ||
| + | sleep 10 | ||
| + | ifup ${INTERFACE} | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | ==== Rename interfaces by MAC address ==== | ||
| + | Assuming pre-configured upstream interfaces '' | ||
| + | Set up persistent interface names by MAC address. | ||
| + | |||
| + | <code bash> | ||
| + | cat << " | ||
| + | dev_rename() { | ||
| + | local DEV_CONF=" | ||
| + | local DEV_MAC DEV_NAME DEV_ONAME | ||
| + | config_get DEV_MAC " | ||
| + | config_get DEV_NAME " | ||
| + | DEV_ONAME=" | ||
| + | $(find / | ||
| + | | sed -e " | ||
| + | | awk -F '/' | ||
| + | if [ -n " | ||
| + | && [ " | ||
| + | then ip link set " | ||
| + | fi | ||
| + | } | ||
| + | . / | ||
| + | config_load network | ||
| + | config_foreach dev_rename device | ||
| + | EOF | ||
| + | |||
| + | while read -r DEV_NAME DEV_MAC | ||
| + | do | ||
| + | uci set network.${DEV_NAME}.device=" | ||
| + | uci set network.${DEV_NAME}6.device=" | ||
| + | uci -q delete network.${DEV_NAME}_dev | ||
| + | uci set network.${DEV_NAME}_dev=" | ||
| + | uci set network.${DEV_NAME}_dev.mac=" | ||
| + | uci set network.${DEV_NAME}_dev.name=" | ||
| + | done << EOI | ||
| + | wana 11: | ||
| + | wanb aa: | ||
| + | EOI | ||
| + | uci commit network | ||
| + | service network restart | ||
| + | </ | ||
| + | |||
| + | ==== 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:// | ||