blob: e9aaa66cb719017290d5df7cc5f9d961018932fb [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
Patrick Williams45852732022-04-02 08:58:32 -05002#
3# SPDX-License-Identifier: MIT
4#
5
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006### 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
18LOAD_MODULE=modprobe
19[ -f /proc/modules ] || exit 0
Andrew Geisslerc926e172021-05-07 16:11:35 -050020[ -d /lib/modules/`uname -r` ] || exit 0
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021
Andrew Geissler09209ee2020-12-13 08:44:15 -060022# Test if modules.dep exists and has a size greater than zero
23if [ ! -s /lib/modules/`uname -r`/modules.dep ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 [ "$VERBOSE" != no ] && echo "Calculating module dependencies ..."
Andrew Geisslerd1e89492021-02-12 15:35:20 -060025 depmod -a
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026fi
27
Andrew Geissler09209ee2020-12-13 08:44:15 -060028[ -f /etc/modules ] || [ -d /etc/modules-load.d ] || exit 0
29[ -e /sbin/modprobe ] || LOAD_MODULE=insmod
30
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031loaded_modules=" "
32
33process_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
54for f in /etc/modules-load.d/*.conf; do
55 process_file $f
56done
57[ "$VERBOSE" != no ] && echo
58
59exit 0