From e5c1d422470d26c4968b390f7beef489b8b41629 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Sun, 15 Jan 2023 13:15:28 +1100 Subject: [PATCH 1/2] Test for ${EDITOR} or fall-back to nano for text file editing --- README.md | 2 +- docs/Concurrent_Mode.md | 2 +- edit-options.sh | 15 ++++++++++++++- install-driver.sh | 18 +++++++++++------- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ae2796b..9cc6722 100644 --- a/README.md +++ b/README.md @@ -546,7 +546,7 @@ dtoverlay=disable-wifi #### Step 1: Edit wpa_supplicant.conf ``` -sudo nano /etc/wpa_supplicant/wpa_supplicant.conf +sudo ${EDITOR} /etc/wpa_supplicant/wpa_supplicant.conf ``` #### Step 2: Delete the relevant WiFi network block (including the 'network=' and opening/closing braces. diff --git a/docs/Concurrent_Mode.md b/docs/Concurrent_Mode.md index 1e976f8..14f7c35 100644 --- a/docs/Concurrent_Mode.md +++ b/docs/Concurrent_Mode.md @@ -29,7 +29,7 @@ How do I Enable Concurrent Mode? Edit the `Makefile` with a text editor: ``` -nano Makefile +${EDITOR} Makefile ``` Change the following line: diff --git a/edit-options.sh b/edit-options.sh index 968baf0..5ad79da 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -20,7 +20,20 @@ then exit 1 fi -nano /etc/modprobe.d/${OPTIONS_FILE} +# Check if ${EDITOR} is an executable or try to default to nano or finally complain if it's not installed. +if ! [ -x "${EDITOR}" ] +then + EDITOR="$(which nano 2>/dev/null)" + if ! [ -x "${EDITOR}" ] + then + echo "No text editor found (default: nano)." + echo "Please install one and set the EDITOR variable to point to it." + echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 + fi +fi + +${EDITOR} /etc/modprobe.d/${OPTIONS_FILE} read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r echo # move to a new line diff --git a/install-driver.sh b/install-driver.sh index 6499755..425e653 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -87,13 +87,17 @@ then exit 1 fi -# check to ensure nano is installed -if ! command -v nano >/dev/null 2>&1 +# Check if ${EDITOR} is an executable or try to default to nano or finally complain if it's not installed. +if ! [ -x "${EDITOR}" ] then - echo "A required package is not installed." - echo "Please install the following package: nano" - echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" - exit 1 + EDITOR="$(which nano 2>/dev/null)" + if ! [ -x "${EDITOR}" ] + then + echo "No text editor found (default: nano)." + echo "Please install one and set the EDITOR variable to point to it." + echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 + fi fi # support for the NoPrompt option allows non-interactive use of this script @@ -353,7 +357,7 @@ then echo if [[ $REPLY =~ ^[Yy]$ ]] then - nano /etc/modprobe.d/${OPTIONS_FILE} + ${EDITOR} /etc/modprobe.d/${OPTIONS_FILE} fi read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r From 016389da562f180f0df69f947bce0abfc1a1327b Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Tue, 17 Jan 2023 22:51:13 +1100 Subject: [PATCH 2/2] Changed to search through VISUAL -> EDITOR -> nano -> -FAIL- for a text editor --- edit-options.sh | 27 ++++++++++++++++----------- install-driver.sh | 27 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/edit-options.sh b/edit-options.sh index 5ad79da..02a0b2d 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -2,6 +2,7 @@ # OPTIONS_FILE="8821cu.conf" SCRIPT_NAME="edit-options.sh" +DEFAULT_EDITOR="nano" # # Purpose: Make it easier to edit the driver options file. # @@ -20,20 +21,24 @@ then exit 1 fi -# Check if ${EDITOR} is an executable or try to default to nano or finally complain if it's not installed. -if ! [ -x "${EDITOR}" ] +# Try to find the user's default text editor through ${VISUAL}, ${EDITOR} or nano +if command -v "${VISUAL}" >/dev/null 2>&1 then - EDITOR="$(which nano 2>/dev/null)" - if ! [ -x "${EDITOR}" ] - then - echo "No text editor found (default: nano)." - echo "Please install one and set the EDITOR variable to point to it." - echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" - exit 1 - fi + TEXT_EDITOR="${VISUAL}" +elif command -v "${EDITOR}" >/dev/null 2>&1 +then + TEXT_EDITOR="${EDITOR}" +elif command -v "${DEFAULT_EDITOR}" >/dev/null 2>&1 +then + TEXT_EDITOR="${DEFAULT_EDITOR}" +else + echo "No text editor found (default: ${DEFAULT_EDITOR})." + echo "Please install one and set the VISUAL or EDITOR variables to point to it." + echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 fi -${EDITOR} /etc/modprobe.d/${OPTIONS_FILE} +${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r echo # move to a new line diff --git a/install-driver.sh b/install-driver.sh index 425e653..c3a6c37 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -19,6 +19,7 @@ SCRIPT_NAME="install-driver.sh" SCRIPT_VERSION="20230111" MODULE_NAME="8821cu" DRV_VERSION="5.12.0.4" +DEFAULT_EDITOR="nano" KVER="$(uname -r)" KARCH="$(uname -m)" @@ -87,17 +88,21 @@ then exit 1 fi -# Check if ${EDITOR} is an executable or try to default to nano or finally complain if it's not installed. -if ! [ -x "${EDITOR}" ] +# Try to find the user's default text editor through ${VISUAL}, ${EDITOR} or nano +if command -v "${VISUAL}" >/dev/null 2>&1 then - EDITOR="$(which nano 2>/dev/null)" - if ! [ -x "${EDITOR}" ] - then - echo "No text editor found (default: nano)." - echo "Please install one and set the EDITOR variable to point to it." - echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" - exit 1 - fi + TEXT_EDITOR="${VISUAL}" +elif command -v "${EDITOR}" >/dev/null 2>&1 +then + TEXT_EDITOR="${EDITOR}" +elif command -v "${DEFAULT_EDITOR}" >/dev/null 2>&1 +then + TEXT_EDITOR="${DEFAULT_EDITOR}" +else + echo "No text editor found (default: ${DEFAULT_EDITOR})." + echo "Please install one and set the VISUAL or EDITOR variables to point to it." + echo "When you have an editor, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 fi # support for the NoPrompt option allows non-interactive use of this script @@ -357,7 +362,7 @@ then echo if [[ $REPLY =~ ^[Yy]$ ]] then - ${EDITOR} /etc/modprobe.d/${OPTIONS_FILE} + ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} fi read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r