-
Notifications
You must be signed in to change notification settings - Fork 0
/
modman
executable file
·81 lines (67 loc) · 2.67 KB
/
modman
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
help() {
echo -e "
help -- Shows this
list -- Output a list of loadable modules for the running kernel
mist -- Output a list of loadable modules, sans modules already loaded
ls [pattern] -- Alias for './modman list | grep \$@'
ms [pattern] -- Alias for './modman mist | grep \$@'
[module name] -- Shows module parameters for the named module (if it exists and is not built-in)
If possible, params will be taken from /sys/module to print the current value
"
exit
}
list() {
find /lib/modules/`uname -r` -type f | grep ko | sed 's/.*\/\(.*\)\.ko/\1/g' | sort
}
mist() {
find /lib/modules/`uname -r` -type f | grep ko | sed 's/.*\/\(.*\)\.ko/\1/g' | sort | \
grep -v "$(lsmod | tail -n +2 | sed 's/\ .*//g')"
}
lsgrep() {
[ "${ret}" == "ls" ] &&
list | grep "${ter}" ||
mist | grep "${ter}"
}
hmm() {
[ -z "${ret}" ] && help
LOADED="/sys/module/${ret}/parameters"
MODDIR="/lib/modules/`uname -r`"
if [[ -e "${LOADED}" ]] ; then
! [[ -r "${LOADED}"/* ]] && sudo tail -n +1 "${LOADED}"/* || tail -n +1 "${LOADED}"/*
fi
! [[ -e "${LOADED}" ]] && [[ -n $(grep -o "\/${ret}\.ko" "${MODDIR}"/modules.builtin) ]] &&
echo "The module is built in but has no parameters to set"
[[ -n $(find "${MODDIR}" -type f -name "${ret}") ]] &&
modinfo "${ret}" | grep 'parm:' || echo "It seems I was unable to find the specified module" ; help
}
# This also works, but modules.order does not contain out-of-tree modules
# sed 's/^.*\///g' /lib/modules/`uname -r`/modules.order | sort | awk '{ORS=NR % 2? "\t": "\n"; print}'
# What the above does:
# Uses sed on the running kernel's 'modules.order' file to remove .ko from the module names
# Ssort it by name with sort
# Uses awk to print it in two columns separated by a tab. ORS -> field separator ; NR -> total number of inputs
# awk '{ORS=NR % 2? "\t": "\n"; print}' | 2 is the number of 'columns' ; \t is what separates each ; \n is newline
# This works as well but I can't figure out how to make the tabs align; the output is ugly
# find /lib/modules/`uname -r` -type f | grep ko | sed 's/.*\/\(.*\)\.ko/\1/g' | sort | paste - -
# What the above does:
# Uses find with the option of only looking for files on the running kernel's module directory
# Greps for any file with 'ko' in it so that only modules are shown
# Sed is used to remove '.ko' from the module names and remove the directories from the output (it's possible to config grep to not show directories too)
# Sort puts the modules in alphabetical order
# Paste, with '- -', shows the output in two columns, and by default is separated by a TAB
export ret="${1}"
export ter="${2}"
case ${ret} in
'ls'*|'ms'*)
lsgrep
;;
'list')
list
;;
'mist')
mist
;;
*)
hmm
esac