heads icon indicating copy to clipboard operation
heads copied to clipboard

WIP: Shellcheck script files in initrd

Open Thrilleratplay opened this issue 5 years ago • 5 comments

  • [X] Shell scripts without a file extension in /initrd renamed with .sh for consistency and simplifying shellcheck glob search.
  • [X] Any #!/bin/ash shebangs are changed to #!/bin/sh as shellcheck does not have ash support.
  • [ ] Rewrite commands to be generic POSIX shell If possible, add shelllcheck exception where it is not.
  • [ ] Use relative source paths to validate imported variables and functions.
  • [ ] Manually test changes

Resolve shellcheck errors:

To investigate:

  • [ ] /initrd/sbin/config-dhcp.sh - variables not defined, does not seem to be functional.

Thrilleratplay avatar Oct 20 '20 16:10 Thrilleratplay

@Thrilleratplay Waoooow!!!! Awesome initiative!!!!

tlaurion avatar Oct 20 '20 21:10 tlaurion

* `/initrd/sbin/config-dhcp.sh` - variables not defined, does not seem to be functional.

Is called from https://github.com/osresearch/heads/blob/624faa1a9d9c7794927757ff49fbb567d6d031fb/config/busybox.config#L954 while I implemented DHCP configuration here.

tlaurion avatar Oct 25 '20 05:10 tlaurion

@tlaurion Thank you for pointing out where it is referenced. I am going to make changes to /sbin/config-dhcp.sh separately and should read up on how busybox interacts with DHCP scripts. Likely for now, I will just make an exception for the undeclared variables that are used in the script.

Thrilleratplay avatar Oct 26 '20 23:10 Thrilleratplay

Closing this in favor of #872

Thrilleratplay avatar Oct 29 '20 19:10 Thrilleratplay

This is preferred approach over #872 (now closed).

The logic behind this is that bash is not fully supported under busybox, even as of today, where having scripts declaring bash interpreter vs ash will be misleading.

What changed (I think) since thn is that ASH is supported from shellcheck. This is actually DASH compliant, and we could get around shellcheck error SC2187 by doing either:

#!/bin/ash
# shellcheck shell=dash

As reported there, having shellcheck check for dash vs ash will report errors saying that echo -e is not supported under dash (which shellcheck supports). We will have to mute those errors as well, since we use echo -e under Heads.

So the workaround would be something in the lines of (until either busybox is fully supporting bash or shellcheck is fully supporting ash):

#!/bin/ash
# shellcheck shell=ash #we foce support for ash even if shellcheck complains it only supports dash
# shellcheck disable=SC3036 #echo -e is supported under ash but not dash

As you see, nothing perfect again.

The desired path is actually to have posix compliant scripts (where shellcheck currently complains for coding standards, but the scripts are compliant as of now).

Discussion happening over #885. Cross-linking from there to here.

tlaurion avatar Jul 29 '22 17:07 tlaurion