New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor fixes to pass shellcheck #14996
base: main
Are you sure you want to change the base?
Conversation
@@ -5,8 +5,8 @@ CFG=$1 | |||
[ -n "$CFG" ] || CFG=/etc/board.json | |||
|
|||
[ -d "/etc/board.d/" -a ! -s "$CFG" ] && { | |||
for a in $(ls /etc/board.d/*); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with this change, is there any reason why someone would want to do ls <some glob>
? Probably this is done because ls
guarantees that they are sorted which makes sense in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.S. it does seem like echo /etc/board.d/*
is sorted, but the ls
man page explicitly mentions that the output would be sorted by default. I'm not sure if we can rely on it for glob.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message for when this was introduced didn't shed any light on this. I think @rany2 almost certainly has the right of it though. $(ls /etc/board.d/*)
is used since it gives the files in sorted order. A favorite approach is to name the scripts 0-first-script.sh
, 1-second-script.sh
, 2-third-script.sh
, etc in order to ensure ordering of the scripts. Same idea as patch filenames starting with 3 digits. As a result this first line is almost certainly wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @rany2 almost certainly has the situation correct, which means a fix is needed.
@@ -1,3 +1,3 @@ | |||
#!/bin/sh | |||
|
|||
/sbin/jffs2reset $@ | |||
/sbin/jffs2reset "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First commit looks simple and reasonable. The subject line (first line used by shortlog) should be prefixed with "base-files:".
for a in $(ls /etc/board.d/*); do | ||
[ -s $a ] || continue; | ||
for a in /etc/board.d/*; do | ||
[ -s "$a" ] || continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it is unlikely for files in /etc/board.d/
to have spaces in their filenames, this is quite appropriate.
@@ -5,8 +5,8 @@ CFG=$1 | |||
[ -n "$CFG" ] || CFG=/etc/board.json | |||
|
|||
[ -d "/etc/board.d/" -a ! -s "$CFG" ] && { | |||
for a in $(ls /etc/board.d/*); do | |||
[ -s $a ] || continue; | |||
for a in /etc/board.d/*; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be awfully tempted to substitute find /etc/board.d -maxdepth 1 -print | sort | while read a; do
as this avoids having the shell scan the directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which would not yield equivalent results though, as it returns /etc/board.d
at depth 0 as well, so it should probably be -mindepth 1 -maxdepth 1
.
While generally preferring find
for finding operations, the line gets pretty unhandy here and would also depend on different flavors of find
and sort
(BusyBox, findutils, coreutils) installed on the target. (though they all should behave the same in this case). I'd therefore slightly prefer the shorter glob version here.
@@ -5,8 +5,8 @@ CFG=$1 | |||
[ -n "$CFG" ] || CFG=/etc/board.json | |||
|
|||
[ -d "/etc/board.d/" -a ! -s "$CFG" ] && { | |||
for a in $(ls /etc/board.d/*); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message for when this was introduced didn't shed any light on this. I think @rany2 almost certainly has the right of it though. $(ls /etc/board.d/*)
is used since it gives the files in sorted order. A favorite approach is to name the scripts 0-first-script.sh
, 1-second-script.sh
, 2-third-script.sh
, etc in order to ensure ordering of the scripts. Same idea as patch filenames starting with 3 digits. As a result this first line is almost certainly wrong.
The actual "issue" is not "not passing shellcheck". The tool just detects potential issues like unintended behavior. And the solution is not |
Ok I'll rephrase the commits then. What about the file loop? I've understood that we want the files to be sorted while the glob in fact doesn't guarantee that, but the alternative then is to let the line unchanged or to use find. |
Before this change, the firstboot script was not passing shellcheck test as it invoked jffs2reset without quotes, leading to potential re-splitting. Signed-off-by: Matteo Iervasi <matteo.iervasi@edalab.it>
Before this change, the board_detect script was parsing the output of ls to get files in /etc/board.d. The correct method is to use globs. Signed-off-by: Matteo Iervasi <matteo.iervasi@edalab.it>
These are just two minor patches to the following two scripts that comes with the
base-files
package to solve errors given by the ShellCheck utility:/bin/board_detect
/sbin/firstboot
The first script contained parsing of the
ls
command which is not recommended:While the second script contained potential re-splitting: