1
0
mirror of https://github.com/morrownr/8821cu-20210916.git synced 2024-11-30 00:57:57 +00:00
8821cu-20210916/edit-options.sh

63 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/sh
2023-01-22 07:52:24 +00:00
2023-03-05 19:57:17 +00:00
# Purpose: Make it easier to edit the correct driver options file.
2022-11-17 14:26:57 +00:00
#
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"
2023-09-25 15:04:26 +00:00
# SCRIPT_VERSION="20230710"
2023-01-22 07:52:24 +00:00
OPTIONS_FILE="8821cu.conf"
2023-01-26 17:52:27 +00:00
# check to ensure sudo was used to start the script
if [ "$(id -u)" -ne 0 ]; then
2022-11-17 14:26:57 +00:00
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
fi
2023-01-26 17:52:27 +00:00
DEFAULT_EDITOR="$(cat default-editor.txt)"
# try to find the user's default text editor through the EDITORS_SEARCH array
for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do
2023-01-25 10:45:40 +00:00
command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
done
2023-01-26 17:52:27 +00:00
# failure message if no editor was found
if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then
2023-01-27 05:47:52 +00:00
echo "No text editor was found (default: ${DEFAULT_EDITOR})."
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}\""
exit 1
fi
2023-09-25 15:04:26 +00:00
if [ -f "/etc/modprobe.d/${OPTIONS_FILE}" ]; then
${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE}
else
cp -f ${OPTIONS_FILE} /etc/modprobe.d
${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE}
fi
2022-11-17 14:26:57 +00:00
2023-09-25 15:04:26 +00:00
printf "Do you want to apply the new options by rebooting now? (recommended) [Y/n] "
read -r yn
case "$yn" in
[nN]) ;;
*) reboot ;;
esac