morrownr / 8821cu-20210916

Linux Driver for USB WiFi Adapters that are based on the RTL8811CU, RTL8821CU, RTL8821CUH and RTL8731AU Chipsets - v5.12.0.4
Other
582 stars 127 forks source link

Should not assume use of nano as editor #54

Closed colincdean closed 1 year ago

colincdean commented 1 year ago

Both install-driver.sh and edit-options.sh hard-wire use of nano as editor for /etc/modprobe.d/8821cu.conf.

On Debian-based systems at least, it would be preferable to honor the user's choice of editor, by invoking sensible-editor if found, or editor if not, instead of nano. If not familiar with this idea, see sensible-editor(1) and update-alternatives(1) man pages.

I'm not a nano user (preferring emacs or vi), and other Linux tools (such as crontab) will let me use what I want.

To avoid code duplication, maybe install-driver.sh should employ edit-options.sh?

alkisg commented 1 year ago

I can easily rewrite the script to be sh-compatible. If you want that, ping me.

morrownr commented 1 year ago

I can easily rewrite the script to be sh-compatible. If you want that, ping me.

That is probably the best idea. I'm pretty sure at one time it was sh-compatible and I simply did not pay attention. Would you also be so kind as to point me in the direction of how to ensure I stay sh-compatible going forward?

Nick

alkisg commented 1 year ago

Change the shebang to #!/bin/sh, then run:

$ shellcheck install-driver.sh

In install-driver.sh line 41:
DEFAULT_EDITOR="$(<default-editor.txt)"
                ^--------------------^ SC3034 (warning): In POSIX sh, $(<file) to read files is undefined.

In install-driver.sh line 42:
EDITORS_SEARCH=("${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" "vi")
               ^-- SC3030 (warning): In POSIX sh, arrays are undefined.

In install-driver.sh line 45:
if [[ $EUID -ne 0 ]]
   ^---------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.
      ^---^ SC3028 (warning): In POSIX sh, EUID is undefined.

In install-driver.sh line 102:
for editor in ${EDITORS_SEARCH[@]}
              ^------------------^ SC2068 (error): Double quote array expansions to avoid re-splitting elements.
              ^------------------^ SC3054 (warning): In POSIX sh, array references are undefined.

In install-driver.sh line 168:
echo ": "${gcc_ver}
         ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
echo ": ""${gcc_ver}"

In install-driver.sh line 174:
    echo ": "${dkms_ver}
                 ^---------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    echo ": ""${dkms_ver}"

In install-driver.sh line 181:
    echo ": "${sb_state}
                 ^---------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    echo ": ""${sb_state}"

In install-driver.sh line 198:
if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]
   ^-- SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 201:
    rm -f ${MODDESTDIR}${MODULE_NAME}.ko
              ^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    rm -f "${MODDESTDIR}"${MODULE_NAME}.ko

In install-driver.sh line 202:
    /sbin/depmod -a ${KVER}
                        ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    /sbin/depmod -a "${KVER}"

In install-driver.sh line 212:
if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]
   ^-- SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 215:
    rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko
              ^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    rm -f "${MODDESTDIR}"rtl${MODULE_NAME}.ko

In install-driver.sh line 216:
    /sbin/depmod -a ${KVER}
                        ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    /sbin/depmod -a "${KVER}"

In install-driver.sh line 228:
if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]]
   ^-- SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 231:
    rm -f /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
                               ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    rm -f /usr/lib/modules/"${KVER}"/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz

In install-driver.sh line 232:
    /sbin/depmod -a ${KVER}
                        ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    /sbin/depmod -a "${KVER}"

In install-driver.sh line 265:
    make -j$(nproc)
               ^------^ SC2046 (warning): Quote this to prevent word splitting.

In install-driver.sh line 268:
    if [[ "$RESULT" != "0" ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 285:
    if [[ "$RESULT" = "0" ]]
           ^-------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 309:
    if [[ "$RESULT" != "0" ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 311:
        if [[ "$RESULT" = "3" ]]
                   ^-------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 337:
    if [[ "$RESULT" != "0" ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 352:
    if [[ "$RESULT" != "0" ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 376:
    read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
             ^-- SC3045 (warning): In POSIX sh, read -p is undefined.

In install-driver.sh line 378:
    if [[ $REPLY =~ ^[Yy]$ ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

In install-driver.sh line 383:
    read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
             ^-- SC3045 (warning): In POSIX sh, read -p is undefined.

In install-driver.sh line 385:
    if [[ $REPLY =~ ^[Yy]$ ]]
           ^--------------------^ SC3010 (warning): In POSIX sh, [[ ]] is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC2068 -- Double quote array expansions to ...
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
  https://www.shellcheck.net/wiki/SC3010 -- In POSIX sh, [[ ]] is undefined.

P.S. if you use vscode and have shellcheck installed, it automatically marks all these warnings with curly underline.

morrownr commented 1 year ago

Let the debashing begin!

@alkisg

Thanks. I'm working in it.

@M0les

We are probably making your day. Merge a great and get it debashed.

Jibun-no-Kage commented 1 year ago

Oh, lets get crazy.... Use Python! A suggestion only, don't have a strong opinion on which shell or script interpreter used. Ah, well Python is compiled actually.

morrownr commented 1 year ago

Oh, lets get crazy

Let a guy play around a little. I have already eliminated the bashisms that I had put in the script. Now I'm sitting here looking at the ones Miles added...

There has got to be a sh-compatible way to do the editor stuff but it escapes me what it is right now.

M0les commented 1 year ago

Yeah, I left-out the "Is it Bash or not?" stuff because:

  1. It's separate to the topic this issue was started with (#54) and should have its own issue... so I raised issue #57 (Hope that's OK)
  2. It'd be better in the long run to just convert to a non-Bash form if we want to support running in shells other than Bash (As @morrownr and @alkisg point out).

For the record, I'm developing on Fedora37, which links /bin/sh to Bash. I've installed Dash as my "not-Bash" shell (and I suspect this is the default /bin/sh for Debian/Ubuntu et. al.). So that's what I'm targeting.

I also like the use of ShellCheck static analysis too.

And [[ is Bash's more forgiving inbuilt alternative to the inbuilt [ command, which inlines the [ program, which is a version of test.

Every Bash-ishm has a Bourne equivalent, but they usually use more punctuation and/or steps.