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