-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add ShellCheck and shfmt shell code quality analysis #2712
Conversation
platform/kindle/koreader.sh
Outdated
eips_print_bottom_centered "Starting KOReader . . ." 1 | ||
fi | ||
|
||
# we keep maximum 500K worth of crash log | ||
cat crash.log 2> /dev/null | tail -c 500000 > crash.log.new | ||
< crash.log tail -c 500000 > crash.log.new |
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.
This will print out a misleading error message if crash.log does not exist. How about we change it to the following?
if [ -e crash.log ]; then
tail -c 500000 crash.log > crash.log.new
mv -f crash.log.new crash.log
fi
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.
Yes, I think that's much clearer and therefore better. Besides, as you pointed out the next line otherwise errors as well.
$ mv -f crash.log.new crash.log
mv: cannot stat 'crash.log.new': No such file or directory
Nice! I saw this project the other day and was planning to add it to the travis CI. Thanks for doing this. |
A related and potentially also interesting script is checkbashisms. It doesn't overlap completely with ShellCheck (which bases its recommendations on the shebang at the top of the file) because it points out that |
fc8dea0
to
3a63da0
Compare
.ci/script.sh
Outdated
source "${CI_DIR}/common.sh" | ||
|
||
travis_retry make fetchthirdparty | ||
make all | ||
make testfront | ||
luajit $(which luacheck) --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins | ||
luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins | ||
find . -type f -name '*.sh' -not -path "./base/*" -not -path "./luajit-rocks/*" -print0 | xargs --null shellcheck |
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.
Would it be better to stick this directly after make fetchthirdparty
? I think there's no functional reason for this to go all the way at the end and it'd error a lot quicker.
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 was thinking about the same thing! Yes, makes total sense to not fun tests if static analysis is not even passing.
The stupid fail has nothing to do with this (Travis ran for 1+ hour? Didn't even know that was possible…). It's ready for a final review. I've already had a pass with the shellscript analysis at the end. |
source "${CI_DIR}/common.sh" | ||
|
||
travis_retry make fetchthirdparty | ||
find . -type f -name '*.sh' -not -path "./base/*" -not -path "./luajit-rocks/*" -print0 | xargs --null shellcheck |
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.
It occurs to me that it might be better to grep for a few relevant shebangs as well. See, e.g., here which I came across while searching if there was a precompiled updated shellcheck.
echo 'Running shellcheck'
git grep -l '^#!/usr/bin/env bash' | xargs shellcheck
echo 'Running shfmt'
git grep -l '^#!/usr/bin/env bash' | xargs shfmt -i 2 -w
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'm specifically thinking of kodev. But the find command is also important, because missing shebangs were a problem in some of the files.
Looks good to me 👍 But let's give it couple more days for testing since it touches many critical code path. |
@@ -115,11 +118,11 @@ set_cre_prop() | |||
# Check that the config exists... | |||
if [ -f "${cre_config}" ] ; then | |||
# dos2unix | |||
sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}" | |||
sed -e "s/$(printf '\r')$//g" -i "${cre_config}" |
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.
Need to check how this actually behaves on devices
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.
Yeah, that was okay the way it is and my change was mistaken because I forgot to escape '\r' properly. In this case it's easier to just disable the shellcheck warning (plus then no checking on device is required).
@@ -125,7 +129,7 @@ export STARDICT_DATA_DIR="data/dict" | |||
export EXT_FONT_DIR="/mnt/us/fonts" | |||
|
|||
# Only setup IPTables on evices where it makes sense to (FW 5.x & K4) | |||
if [ "${INIT_TYPE}" == "upstart" -o "$(uname -r)" == "2.6.31-rt11-lab126" ] ; then | |||
if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ] ; then |
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.
Need to check
fi | ||
fi | ||
|
||
# check if kpvbooklet was launched for more than once, if not we will disable pillow | ||
# there's no pillow if we stopped the framework, and it's only there on systems with upstart anyway | ||
if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "upstart" ] ; then | ||
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ] ; then |
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.
Same as before
count=$(lipc-get-prop -eiq com.github.koreader.kpvbooklet.timer count) | ||
if [ "$count" == "" -o "$count" == "0" ] ; then | ||
if [ "$count" = "" ] || [ "$count" = "0" ] ; then |
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.
And again
@@ -218,12 +224,12 @@ if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "upstart" ] ; then | |||
PILLOW_SOFT_DISABLED="yes" | |||
fi | |||
# NOTE: We don't need to sleep at all if we've already SIGSTOPped awesome ;) | |||
if [ "${NO_SLEEP}" == "no" -a "${AWESOME_STOPPED}" == "no" ] ; then | |||
if [ "${NO_SLEEP}" = "no" ] && [ "${AWESOME_STOPPED}" = "no" ] ; then |
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.
And again
@@ -232,21 +238,23 @@ if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "upstart" ] ; then | |||
fi | |||
|
|||
# stop cvm (sysv & framework up only) | |||
if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "sysv" ] ; then | |||
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ] ; then |
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.
And again
@@ -280,7 +288,7 @@ if grep ${KOREADER_DIR}/fonts/linkfonts /proc/mounts > /dev/null 2>&1 ; then | |||
fi | |||
|
|||
# Resume cvm (only if we stopped it) | |||
if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "sysv" ] ; then | |||
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ] ; then |
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.
And again
It's been changed to universal POSIX rather than a Bashism. But yes I can't
check Kindle.
…On Apr 7, 2017 19:18, "NiLuJe" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In platform/kindle/extensions/koreader/bin/koreader-ext.sh
<#2712 (comment)>:
> @@ -115,11 +118,11 @@ set_cre_prop()
# Check that the config exists...
if [ -f "${cre_config}" ] ; then
# dos2unix
- sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}"
+ sed -e "s/$(printf '\r')$//g" -i "${cre_config}"
Need to check how this actually behaves on devices
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2712 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMYBU7zONfm3RGLL0rzUtEKnAZCOtszks5rtm_rgaJpZM4Mw5lx>
.
|
cd / && env -u LD_LIBRARY_PATH /etc/init.d/framework start | ||
else | ||
cd / && env -u LD_LIBRARY_PATH start lab126_gui | ||
fi | ||
fi | ||
|
||
# Display chrome bar if need be (upstart & framework up only) | ||
if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "upstart" ] ; then | ||
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ] ; then |
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.
And again
@@ -325,16 +333,15 @@ if [ "${STOP_FRAMEWORK}" == "no" -a "${INIT_TYPE}" == "upstart" ] ; then | |||
fi | |||
fi | |||
|
|||
if [ "${INIT_TYPE}" == "upstart" -o "$(uname -r)" == "2.6.31-rt11-lab126" ] ; then | |||
if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ] ; then |
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.
And again
platform/kobo/disable-wifi.sh
Outdated
@@ -9,9 +9,9 @@ ifconfig eth0 down | |||
|
|||
# Some sleep in between may avoid system getting hung | |||
# (we test if a module is actually loaded to avoid unneeded sleeps) | |||
if lsmod | grep -q $WIFI_MODULE ; then | |||
if lsmod | grep -q "$WIFI_MODULE" ; then |
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'd probably prefer quotes AND curly braces, but that's just me ;).
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 can change it, but note that unquoted vars are basically always problematic whereas a lack of curly braces is only problematic in the case of $array[key]
(should be ${array[key]}
).
But more to the point, are you aware of a tool that would auto-check for that if we did that?
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.
Actually I think I prefer without curly braces because they're visual noise, although I don't feel very strongly about it. :-P
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.
NiLuJe said he prefer both ;) I think it's better to keep it consistent to have the braces everywhere.
platform/kobo/disable-wifi.sh
Outdated
usleep 200000 | ||
rmmod -r $WIFI_MODULE | ||
rmmod -r "$WIFI_MODULE" |
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.
Same as just before
platform/ubuntu-touch/koreader.sh
Outdated
fi | ||
|
||
# we're always starting from our working directory | ||
cd $KOREADER_DIR | ||
cd "$KOREADER_DIR" || exit |
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.
And again
platform/ubuntu-touch/koreader.sh
Outdated
@@ -22,7 +22,7 @@ export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:$LD_LIBRARY_PATH | |||
export TESSDATA_PREFIX="data" | |||
|
|||
# export external font directory | |||
export EXT_FONT_DIR="~/fonts" | |||
export EXT_FONT_DIR="$HOME/fonts" |
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.
And again
Did a quick eyeballing, most of it looks okay, I mentioned a few personal formatting pet peeves, and there are a couple of things I'm not quite sure about and would like to check on actual devices, because I've been bitten by crappy busybox behavior before, and that's the reason some of those tests were written that way.. ;). EDIT: I'm referring to the -a/-o switch. I actually vastly prefer the other syntax, so I definitely remember having to resort to that to fix some weird issues somewhere at some point... |
It's not a matter of preference. The behavior of The basic idea is that writing scripts that'll run on sh from 20 years ago will work on everything, most important alternative shells like Dash and zsh, but also including @#$@#$ DIAF BusyBox. (Seriously, why is it used so much when the basic GNU utils are so minuscule by modern standards?) Besides that there are some things that are just always bad. (like |
Btw, we could also enforce a specific style (4 spaces, tabs, line length) with an only slightly more complicated application of this principle: [ "$(cat enable-wifi.sh )" != "$(shfmt enable-wifi.sh)" ] && shfmt ./enable-wifi.sh | diff enable-wifi.sh - But that's not for this PR, if only because that'd drown the actual code quality issues at play here. |
Okay, just the $PREFIX issue left. |
* add a bunch of curly braces * change back Kindle BusyBox sed statement * kobo/koreader.sh: remove useless $PREFIX
make all | ||
make testfront | ||
luajit $(which luacheck) --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins | ||
luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins |
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.
Actually now that I think about it is there a reason to stick this after make all? Shouldn't this also go directly after make fetchparty
?
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.
Yes
c3207cf
to
1ce2850
Compare
* Caching Luarocks should shave a minute off install process
This should fix #2740. |
Would you do the honors? :-) |
Bravely merging to get it into the next nightly. |
platform/kobo/koreader.sh
Outdated
# shellcheck disable=SC2094 | ||
case "$PRODUCT" in "dragon" | "dahlia" ) cat /sys/class/graphics/fb0/rotate > /sys/class/graphics/fb0/rotate ;; esac | ||
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate" |
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 original commit has case "$PRODUCT" in "dragon" | "dahlia" )
, do we not care about that anymore?
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.
Correct, I believe this more likely to be future-proof unless a third deviant behavior is added to the mix. On those two this line results in the desired orientation (because they give you the opposite of what you want) while on other devices it's just harmless repetition.
No description provided.