Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | ### BEGIN INIT INFO |
| 7 | # Provides: module-init-tools |
| 8 | # Required-Start: |
| 9 | # Required-Stop: |
| 10 | # Should-Start: checkroot |
| 11 | # Should-stop: |
| 12 | # Default-Start: S |
| 13 | # Default-Stop: |
| 14 | # Short-Description: Process /etc/modules. |
| 15 | # Description: Load the modules listed in /etc/modules. |
| 16 | ### END INIT INFO |
| 17 | |
| 18 | LOAD_MODULE=modprobe |
| 19 | [ -f /proc/modules ] || exit 0 |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 20 | [ -d /lib/modules/`uname -r` ] || exit 0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 22 | # Test if modules.dep exists and has a size greater than zero |
| 23 | if [ ! -s /lib/modules/`uname -r`/modules.dep ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | [ "$VERBOSE" != no ] && echo "Calculating module dependencies ..." |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 25 | depmod -a |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | fi |
| 27 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 28 | [ -f /etc/modules ] || [ -d /etc/modules-load.d ] || exit 0 |
| 29 | [ -e /sbin/modprobe ] || LOAD_MODULE=insmod |
| 30 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | loaded_modules=" " |
| 32 | |
| 33 | process_file() { |
| 34 | file=$1 |
| 35 | |
| 36 | (cat $file; echo; ) | |
| 37 | while read module args |
| 38 | do |
| 39 | case "$module" in |
| 40 | \#*|"") continue ;; |
| 41 | esac |
| 42 | [ -n "$(echo $loaded_modules | grep " $module ")" ] && continue |
| 43 | [ "$VERBOSE" != no ] && echo -n "$module " |
| 44 | eval "$LOAD_MODULE $module $args >/dev/null 2>&1" |
| 45 | loaded_modules="${loaded_modules}${module} " |
| 46 | done |
| 47 | } |
| 48 | |
| 49 | [ "$VERBOSE" != no ] && echo -n "Loading modules: " |
| 50 | [ -f /etc/modules ] && process_file /etc/modules |
| 51 | |
| 52 | [ -d /etc/modules-load.d ] || exit 0 |
| 53 | |
| 54 | for f in /etc/modules-load.d/*.conf; do |
| 55 | process_file $f |
| 56 | done |
| 57 | [ "$VERBOSE" != no ] && echo |
| 58 | |
| 59 | exit 0 |