From 78e662efefd1f4af2bdb2a53edecf03b535b997b Mon Sep 17 00:00:00 2001 From: glacambre Date: Sun, 24 Mar 2019 17:29:42 +0100 Subject: [PATCH] Add shellcheck to travis --- .travis.yml | 6 ++++ native/install.sh | 8 +++--- scripts/bodgecss.sh | 2 +- scripts/build.sh | 6 ++-- scripts/git_version.sh | 6 ++-- scripts/make_tutorial.sh | 11 +++++--- scripts/newtab.md.sh | 19 ++++++++----- scripts/wine-pyinstaller.sh | 56 +++++++++++++++++++------------------ 8 files changed, 65 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbd3bda8..935ce42f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,12 @@ cache: directories: - node_modules +script: + - bash -c 'GLOBIGNORE="node_modules" shellcheck **/*.sh' + - npm install + - npm run test + - npm run lint + notifications: webhooks: urls: diff --git a/native/install.sh b/native/install.sh index 8bd9077c..2f60b4de 100755 --- a/native/install.sh +++ b/native/install.sh @@ -3,9 +3,9 @@ set -e echoerr() { - red="\033[31m" - normal="\e[0m" - echo -e "$red$@$normal" >&2 + red="\\033[31m" + normal="\\e[0m" + echo -e "$red$*$normal" >&2 } sedEscape() { @@ -68,7 +68,7 @@ sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file_final")/" "$manifest chmod +x "$native_file" # Requirements for native messenger -python_path=$(which python3) || python_path="" +python_path=$(command -v python3) || python_path="" if [[ -x "$python_path" ]]; then sed -i.bak "1s/.*/#!$(sedEscape /usr/bin/env) $(sedEscape "$python_path")/" "$native_file" mv "$native_file" "$native_file_final" diff --git a/scripts/bodgecss.sh b/scripts/bodgecss.sh index e448c4ea..83ef511c 100755 --- a/scripts/bodgecss.sh +++ b/scripts/bodgecss.sh @@ -6,5 +6,5 @@ imports=$(find src/static/themes -name '*.css'| awk -F"/" '{ printf "@import url for css in build/static/css/*.css; do - printf '%s\n%s\n' "$imports" "$(cat $css)" > $css + printf '%s\n%s\n' "$imports" "$(cat "$css")" > "$css" done diff --git a/scripts/build.sh b/scripts/build.sh index ad739be2..8d5bec58 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -6,18 +6,18 @@ CLEANSLATE="node_modules/cleanslate/docs/files/cleanslate.css" TRIDACTYL_LOGO="src/static/logo/Tridactyl_64px.png" isWindowsMinGW() { - local is_mingw="False" + is_mingw="False" if [ "$(uname | cut -c 1-5)" = "MINGW" ] \ || [ "$(uname | cut -c 1-4)" = "MSYS" ]; then is_mingw="True" fi - echo -n "${is_mingw}" + printf "%s" "${is_mingw}" } if [ "$(isWindowsMinGW)" = "True" ]; then WIN_PYTHON="py -3" - NPM_BIN_DIR="$(cygpath $(npm bin))" + NPM_BIN_DIR="$(cygpath "$(npm bin)")" PATH=$NPM_BIN_DIR:$PATH else PATH="$(npm bin):$PATH" diff --git a/scripts/git_version.sh b/scripts/git_version.sh index 83bda29d..462bd92f 100755 --- a/scripts/git_version.sh +++ b/scripts/git_version.sh @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh gitversion=$(git describe --tags | cut -d"-" -f2-) manversion=$(grep '"version":' ./src/manifest.json | cut -d":" -f2 | tr -d \" | tr -d , | cut -d" " -f2) version=$manversion-$gitversion -sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'$version'/' ./build/background.js -sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'$version'/' ./build/static/newtab.html +sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'"$version"'/' ./build/background.js +sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'"$version"'/' ./build/static/newtab.html rm ./build/background.js.bak rm ./build/static/newtab.html.bak diff --git a/scripts/make_tutorial.sh b/scripts/make_tutorial.sh index 29b14193..5c0e93e5 100755 --- a/scripts/make_tutorial.sh +++ b/scripts/make_tutorial.sh @@ -2,15 +2,18 @@ # Combine tutorial markdown and template -cd src/static/clippy +if ! cd src/static/clippy; then + echo "Failed to cd in src/static/clippy. Aborting." + exit +fi -pages=$(ls *.md) +pages=$(ls ./*.md) dest="../../../generated/static/clippy/" for page in $pages do - fileroot=$(echo $page | cut -d'.' -f-1) + fileroot=$(echo "$page" | cut -d'.' -f-1) sed "/REPLACETHIS/,$ d" tutor.template.html > "$dest$fileroot.html" - "$(npm bin)/marked" $page >> "$dest$fileroot.html" + "$(npm bin)/marked" "$page" >> "$dest$fileroot.html" sed "1,/REPLACETHIS/ d" tutor.template.html >> "$dest$fileroot.html" done diff --git a/scripts/newtab.md.sh b/scripts/newtab.md.sh index 517ae61c..b5de9c40 100755 --- a/scripts/newtab.md.sh +++ b/scripts/newtab.md.sh @@ -2,7 +2,10 @@ # Combine newtab markdown and template -cd src/static +if ! cd src/static ; then + echo "Failed to cd in src/static. Aborting." + exit +fi newtab="../../generated/static/newtab.html" newtabtemp="../../generated/static/newtab.temp.html" @@ -13,17 +16,19 @@ sed "1,/REPLACETHIS/ d" newtab.template.html >> "$newtabtemp" # Why think when you can pattern match? -sed "/REPLACE_ME_WITH_THE_CHANGE_LOG_USING_SED/,$ d" "$newtabtemp" > "$newtab" +( +sed "/REPLACE_ME_WITH_THE_CHANGE_LOG_USING_SED/,$ d" "$newtabtemp" # Note: If you're going to change this HTML, make sure you don't break the JS in src/newtab.ts -echo """ +cat <
-""" >> "$newtab" -"$(npm bin)/marked" ../../CHANGELOG.md >> "$newtab" +EOF +"$(npm bin)/marked" ../../CHANGELOG.md echo """
-""" >> "$newtab" -sed "1,/REPLACE_ME_WITH_THE_CHANGE_LOG_USING_SED/ d" "$newtabtemp" >> "$newtab" +""" +sed "1,/REPLACE_ME_WITH_THE_CHANGE_LOG_USING_SED/ d" "$newtabtemp" +) > "$newtab" rm "$newtabtemp" diff --git a/scripts/wine-pyinstaller.sh b/scripts/wine-pyinstaller.sh index 078bc968..9b73a6d7 100755 --- a/scripts/wine-pyinstaller.sh +++ b/scripts/wine-pyinstaller.sh @@ -26,34 +26,35 @@ MIN_WINE_VER="4" MIN_7ZIP_VER="16" checkRequiredVersions() { - if [ -z "$(7z \ - | awk '/Version/{print $3}' \ - | grep "${MIN_7ZIP_VER}")" ]; then + if ! 7z | awk '/Version/{print $3}' | grep -q "${MIN_7ZIP_VER}"; then colorEcho \ - "[-] p7zip minimum version ${MIN_7ZIP_VER} required\n" \ + '[-] p7zip minimum version '"${MIN_7ZIP_VER}"' required\n' \ "alert" exit -1 fi - if [ -z "$(wine --version 2> /dev/null \ - | grep "wine-${min_wine_ver}")" ]; then + if ! wine --version 2> /dev/null | grep -q "wine-${MIN_WINE_VER}"; then colorecho \ - "[-] wine minimum version ${min_wine_ver} required\n" \ + '[-] wine minimum version '"${MIN_WINE_VER}"' required\n' \ "alert" exit -1 fi } stripWhitespace() { - local input="$@" - printf "${input}\n" | tr -d "[:space:]" + local input="$*" + printf '%s\n' "${input}" | tr -d "[:space:]" } colorEcho() { - local COLOR_RESET=$(tput sgr0 2>/dev/null) - local COLOR_BOLD=$(tput bold 2>/dev/null) - local COLOR_BAD=$(tput setaf 1 2>/dev/null) - local COLOR_GOOD=$(tput setaf 2 2>/dev/null) + local COLOR_RESET; + COLOR_RESET="$(tput sgr0 2>/dev/null)" + local COLOR_BOLD; + COLOR_BOLD="$(tput bold 2>/dev/null)" + local COLOR_BAD; + COLOR_BAD="$(tput setaf 1 2>/dev/null)" + local COLOR_GOOD; + COLOR_GOOD="$(tput setaf 2 2>/dev/null)" local str="$1" local color="${COLOR_GOOD}${COLOR_BOLD}" @@ -63,19 +64,20 @@ colorEcho() { color="${COLOR_BAD}${COLOR_BOLD}" fi - printf "${color}${str}${COLOR_RESET}" + printf '%s' "${color}${str}${COLOR_RESET}" } checkPrerequisite() { local bin_name="$1" - local bin_loc=$(which "${bin_name}" 2>/dev/null) + local bin_loc; + bin_loc="$(command -v "${bin_name}" 2>/dev/null)" if [ -z "${bin_loc}" ] \ || [ ! -f "${bin_loc}" ]; then - printf " - '$1' not found, quitting ...\n" + printf '%s\n' " - '$1' not found, quitting ..." exit -1 else - printf " - '${bin_name}' found at ${bin_loc}\n" + printf '%s\n' " - '${bin_name}' found at ${bin_loc}" fi } @@ -86,7 +88,7 @@ mainFunction() { ## Check prerequisites - colorEcho "[+] Checking prerequisites ...\n" + colorEcho '[+] Checking prerequisites ...\n' for bin in ${PREREQUISITES}; do checkPrerequisite "${bin}" done @@ -102,7 +104,7 @@ mainFunction() { ## Download Python and Pip - colorEcho "[+] Downloading necessary files ...\n" + colorEcho '[+] Downloading necessary files ...\n' if [ ! -f "${WINPY_EXE}" ]; then wget \ @@ -112,7 +114,7 @@ mainFunction() { if [ ! "$(sha256sum "${WINPY_EXE}" \ | cut -d" " -f1)" = ${WINPY_HASH} ]; then - colorEcho "[-] ${WINPY_EXE} has incorrect hash, quitting ...\n" + colorEcho '[-] '"${WINPY_EXE}"' has incorrect hash, quitting ...\n' exit 1 fi @@ -122,17 +124,17 @@ mainFunction() { local winepython="wine $PYDIR/python.exe" if [ ! -f "$PYDIR/python.exe" ]; then - colorEcho "[+] Extract Python-${PYVER}\n" + colorEcho '[+] Extract Python-'${PYVER}'\n' 7z x "${DLDIR}/winpython-${PYVER}.exe" "python-$PYVER" -o"$BUILDROOT" $winepython -m pip install --upgrade pip - colorEcho "[+] Installing PyInstaller ...\n" + colorEcho '[+] Installing PyInstaller ...\n' $winepython -m pip install pyinstaller fi ## Compile with PyInstaller - colorEcho "[+] Compiling with PyInstaller under Wine ...\n" + colorEcho '[+] Compiling with PyInstaller under Wine ...\n' rm -rf "${OUTDIR}" PYTHONHASHSEED=1 wine "$PYDIR"/Scripts/pyinstaller.exe \ --clean \ @@ -146,7 +148,7 @@ mainFunction() { "$TRIDIR/native/native_main.py" ## Test the compiled EXE - colorEcho "[+] Checking compiled binary ...\n" + colorEcho '[+] Checking compiled binary ...\n' OUTFILE="${OUTDIR}/native_main.exe" cp "$OUTFILE" "$TRIDIR"/web-ext-artifacts/ @@ -155,11 +157,11 @@ mainFunction() { "$TRIDIR/native/gen_native_message.py" cmd..version \ | wine "$TRIDIR"/web-ext-artifacts/native_main.exe - printf "\n" - colorEcho "[+] PyInstaller with Wine was successful!\n" + printf '\n' + colorEcho '[+] PyInstaller with Wine was successful!\n' else colorEcho \ - "[-] PyInstaller compilation failed, quitting ...\n" \ + '[-] PyInstaller compilation failed, quitting ...\n' \ "alert" exit -1 fi