|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Enable/disable debug code in DIGImend kernel drivers. |
| 4 | +# Author: Nikolai Kondrashov <spbnick@gmail.com> |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 2 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +# |
| 19 | + |
| 20 | +set -e -u -o pipefail |
| 21 | + |
| 22 | +function usage() { |
| 23 | + local progname=`basename "$0"` |
| 24 | + echo "Usage: $progname STATUS" |
| 25 | + echo "Enable/disable debug code in DIGImend kernel drivers," |
| 26 | + echo "making sure affected modules are loaded." |
| 27 | + echo "" |
| 28 | + echo "Arguments:" |
| 29 | + echo " STATUS 1/on/enable to enable, 0/off/disable to disable" |
| 30 | + echo "" |
| 31 | +} |
| 32 | + |
| 33 | +declare -r CONTROL_FILE="/sys/kernel/debug/dynamic_debug/control" |
| 34 | +declare -r -a MODULE_LIST=("hid_uclogic") |
| 35 | + |
| 36 | +if [ "$#" != 1 ]; then |
| 37 | + echo "Invalid number of arguments" >&2 |
| 38 | + echo "" >&2 |
| 39 | + usage >&2 |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +case "${1,,}" in |
| 44 | + 0|off|disable) |
| 45 | + op="-" |
| 46 | + ;; |
| 47 | + 1|on|enable) |
| 48 | + op="+" |
| 49 | + ;; |
| 50 | + *) |
| 51 | + echo "Unknown status: $1" >&2 |
| 52 | + echo "" >&2 |
| 53 | + usage >&2 |
| 54 | + exit 1 |
| 55 | + ;; |
| 56 | +esac |
| 57 | + |
| 58 | +# Make sure modules are loaded, otherwise enabling will have no effect |
| 59 | +if ! modprobe -a "${MODULE_LIST[@]}"; then |
| 60 | + echo "Failed loading DIGImend modules." >&2 |
| 61 | + echo "Make sure they're installed, and you're root or using sudo." >&2 |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +if ! [ -r "$CONTROL_FILE" -a -w "$CONTROL_FILE" ]; then |
| 66 | + echo "Cannot access control file." >&2 |
| 67 | + echo "Make sure you're root or using sudo." >&2 |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +for MODULE in "${MODULE_LIST[@]}"; do |
| 72 | + echo "module ${MODULE} ${op}pmfl" > "$CONTROL_FILE" |
| 73 | +done |
0 commit comments