2022-11-17 14:26:57 +00:00
|
|
|
#!/bin/bash
|
2023-01-22 07:52:24 +00:00
|
|
|
|
2022-11-17 14:26:57 +00:00
|
|
|
# Purpose: Make it easier to edit the driver options file.
|
|
|
|
#
|
2023-01-22 07:52:24 +00:00
|
|
|
# Flexible editor support.
|
|
|
|
#
|
2022-11-17 14:26:57 +00:00
|
|
|
# To make this file executable:
|
|
|
|
#
|
|
|
|
# $ chmod +x edit-options.sh
|
|
|
|
#
|
|
|
|
# To execute this file:
|
|
|
|
#
|
|
|
|
# $ sudo ./edit-options.sh
|
|
|
|
#
|
2023-01-22 07:52:24 +00:00
|
|
|
# Copyright(c) 2023 Nick Morrow
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of version 2 of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
SCRIPT_NAME="edit-options.sh"
|
|
|
|
SCRIPT_VERSION="20230120"
|
|
|
|
OPTIONS_FILE="8821cu.conf"
|
2023-01-25 10:45:40 +00:00
|
|
|
DEFAULT_EDITOR="$(cat default-editor.txt)"
|
2023-01-22 07:52:24 +00:00
|
|
|
|
2022-11-17 14:26:57 +00:00
|
|
|
if [[ $EUID -ne 0 ]]
|
|
|
|
then
|
|
|
|
echo "You must run this script with superuser (root) privileges."
|
|
|
|
echo "Try: \"sudo ./${SCRIPT_NAME}\""
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-01-24 10:59:56 +00:00
|
|
|
# Try to find the user's default text editor through the EDITORS_SEARCH array
|
2023-01-25 10:45:40 +00:00
|
|
|
for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi;
|
2023-01-24 10:59:56 +00:00
|
|
|
do
|
2023-01-25 10:45:40 +00:00
|
|
|
command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
|
2023-01-24 10:59:56 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Fail if no editor was found
|
|
|
|
if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1
|
2023-01-17 11:51:13 +00:00
|
|
|
then
|
|
|
|
echo "No text editor found (default: ${DEFAULT_EDITOR})."
|
2023-01-24 10:59:56 +00:00
|
|
|
echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor."
|
2023-01-22 07:52:24 +00:00
|
|
|
echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\""
|
2023-01-17 11:51:13 +00:00
|
|
|
exit 1
|
2023-01-15 02:15:28 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-17 11:51:13 +00:00
|
|
|
${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE}
|
2022-11-17 14:26:57 +00:00
|
|
|
|
|
|
|
read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r
|
|
|
|
echo # move to a new line
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
reboot
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|