-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathunblacklist
executable file
·92 lines (84 loc) · 2 KB
/
unblacklist
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
82
83
84
85
86
87
88
89
90
91
92
#! /bin/sh
# Copyright (c) 2021-2024 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
ME="${0##*/}"
if [ -e /etc/initrd-release ]; then
[ "$RD_DEBUG" != "yes" ] || \
echo "$ME: called in initramfs for \"$@\" - ignoring" >&2
exit 0
fi
# Never unblacklist non-interactively
if ! tty -s <&0; then
exit 0
fi
if [ $UID -ne 0 ]; then
echo "$ME: you must be root to run this program" >&2
exit 1
fi
if [ $# -ne 1 ]; then
echo "Usage: $ME module" >&2
exit 1
fi
MODULE=$1
if [ -z "$MODULE" ] || \
[ ! -f /lib/modprobe.d/60-blacklist_fs-"$MODULE".conf -a \
! -f /usr/lib/modprobe.d/60-blacklist_fs-"$MODULE".conf ]; then
echo "$ME: Invalid or unknown module \"$MODULE\"" >&2
exit 1
fi
CONF=/etc/modprobe.d/60-blacklist_fs-"$MODULE".conf
if [ -L "$CONF" ]; then
if [ x"$(readlink -f "$CONF")" = x/dev/null ]; then
# already linked to /dev/null
exit 0
else
echo "$ME: $CONF is in unexpected state, exiting" >&2
exit 1
fi
elif [ -f "$CONF" ]; then
if ! grep -E -q "^[ ]*blacklist[ ]+$MODULE" "$CONF"; then
# not blacklisted
exit 0
fi
if ! grep -E -q '^# __THIS FILE MAY BE MODIFIED__' "$CONF"; then
echo "$ME: $CONF exists, cannot modify it" >&2
exit 1
fi
elif [ -e "$CONF" ]; then
echo "$ME: $CONF is in unexpected state, exiting" >&2
exit 1
fi
echo "$ME: loading $MODULE file system module" >&2
_a=
while [ -z "$_a" ]; do
echo -n "$ME: Do you want to un-blacklist $MODULE permanently (<y>es/<n>o/n<e>ver)? " >&2
read _a
case $_a in
y|yes) _a=yes;;
n|no) _a=no;;
e|never) _a=never;;
*) _a=;;
esac
done
case $_a in
no)
echo "$ME: not un-blacklisting $MODULE" >&2
exit 0
;;
never)
echo "$ME: creating $CONF" >&2
rm -f "$CONF"
cat >$CONF <<EOF
# created by $0 (user wants to never unblacklist this module)
blacklist $MODULE
EOF
exit 0
;;
esac
if ln -sf /dev/null "$CONF"; then
echo "$ME: $MODULE un-blacklisted by creating $CONF" >&2
exit 0
else
echo "$ME: Failed to create $CONF" >&2
exit 1
fi