1#!/bin/sh 2# 3# SPDX-License-Identifier: MIT 4# 5 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 18LOAD_MODULE=modprobe 19[ -f /proc/modules ] || exit 0 20[ -d /lib/modules/`uname -r` ] || exit 0 21 22# Test if modules.dep exists and has a size greater than zero 23if [ ! -s /lib/modules/`uname -r`/modules.dep ]; then 24 [ "$VERBOSE" != no ] && echo "Calculating module dependencies ..." 25 depmod -a 26fi 27 28[ -f /etc/modules ] || [ -d /etc/modules-load.d ] || exit 0 29[ -e /sbin/modprobe ] || LOAD_MODULE=insmod 30 31loaded_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 60