-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchkmod
More file actions
executable file
·45 lines (42 loc) · 828 Bytes
/
chkmod
File metadata and controls
executable file
·45 lines (42 loc) · 828 Bytes
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
#!/bin/bash
if [[ "$(which modprobe)" ]]; then
load="modprobe"
unload="modprobe -r"
else
load="insmod"
unload="rmmod"
fi
case "$1" in
'')
echo 'No module passed to the script.' >&2
exit 2
;;
*)
mod_list="find /lib/modules/$(uname -r)/kernel -type f -printf '%f\n'"
if [[ "$($mod_list | grep "$1" &> /dev/null)" ]]; then
continue
else
echo "$1 isn't installed or isn't a valid module." >&2
exit 1
fi
;;
esac
if lsmod | grep "$1" &> /dev/null; then
echo "$1 is loaded."
read -n 1 -p "Do you want to remove it? [y/N]"
echo
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
$unload $1
else
exit 1
fi
else
echo "$1 is not loaded."
read -n 1 -p "Do you want to load it? [y/N]"
echo
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
$unload $1
else
exit 1
fi
fi