halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
468 stars 87 forks source link

Fix ShellCheck warnings and make script more strict #52

Closed joschi closed 4 years ago

joschi commented 4 years ago

This change set fixes all ShellCheck warnings and errors in bin/functions.

Fixed warnings and errors: ```text > shellcheck bin/functions In bin/functions line 3: PLUGIN_HOME=$(dirname $(dirname "${0}")) ^---------------^ SC2046: Quote this to prevent word splitting. In bin/functions line 33: trap "rm -rf ${TEMP_DIR}" EXIT ^---------^ SC2064: Use single quotes, otherwise this expands now rather than when signalled. In bin/functions line 37: bold=`tput bold` ^---------^ SC2006: Use $(...) notation instead of legacy backticked `...`. Did you mean: bold=$(tput bold) In bin/functions line 38: nc=`tput sgr0` ^---------^ SC2006: Use $(...) notation instead of legacy backticked `...`. Did you mean: nc=$(tput sgr0) In bin/functions line 42: printf "$USAGE" >&2 ^------^ SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo". In bin/functions line 55: if [[ -z "$(ls -A ${CACHE_DIR})" ]] || [[ $(set -- $(${STAT}) && echo ${1}) -le $(( `date +%s` - 3600)) ]] ^--------^ SC2046: Quote this to prevent word splitting. ^--^ SC2086: Double quote to prevent globbing and word splitting. ^--------^ SC2006: Use $(...) notation instead of legacy backticked `...`. Did you mean: if [[ -z "$(ls -A ${CACHE_DIR})" ]] || [[ $(set -- $(${STAT}) && echo "${1}") -le $(( $(date +%s) - 3600)) ]] In bin/functions line 59: curl -s -L ${url} -# -w "%{filename_effective}\n" -o "${CACHE_DIR}/adopt-#1.json" 2>&1 >> /dev/null ^----^ SC2086: Double quote to prevent globbing and word splitting. ^--^ SC2069: To redirect stdout+stderr, 2>&1 must be last (or use '{ cmd > file; } 2>&1' to clarify). Did you mean: curl -s -L "${url}" -# -w "%{filename_effective}\n" -o "${CACHE_DIR}/adopt-#1.json" 2>&1 >> /dev/null In bin/functions line 61: for i in `ls ${CACHE_DIR}` ^---------------^ SC2045: Iterating over ls output is fragile. Use globs. ^---------------^ SC2006: Use $(...) notation instead of legacy backticked `...`. Did you mean: for i in $(ls ${CACHE_DIR}) In bin/functions line 64: ${CACHE_DIR}/${i} > ${CACHE_DIR}/${i}.temp ^--^ SC2086: Double quote to prevent globbing and word splitting. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: ${CACHE_DIR}/"${i}" > ${CACHE_DIR}/"${i}".temp In bin/functions line 65: mv ${CACHE_DIR}/${i}.temp ${CACHE_DIR}/${i} ^--^ SC2086: Double quote to prevent globbing and word splitting. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: mv ${CACHE_DIR}/"${i}".temp ${CACHE_DIR}/"${i}" In bin/functions line 72: jq -s 'add' ${CACHE_DIR}/*.json ${PLUGIN_HOME}/corretto/corretto.json ${PLUGIN_HOME}/zulu/zulu.json ^------------^ SC2086: Double quote to prevent globbing and word splitting. ^------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: jq -s 'add' ${CACHE_DIR}/*.json "${PLUGIN_HOME}"/corretto/corretto.json "${PLUGIN_HOME}"/zulu/zulu.json In bin/functions line 85: echo $(all-json | jq -r "${hotspot}" ; all-json | jq -r "${openj9_normal_heap}" ; all-json | jq -r "${openj9_large_heap}") ^-- SC2046: Quote this to prevent word splitting. In bin/functions line 97: local binary=$(all-json | jq "$select_release | $select_binary") ^----^ SC2155: Declare and assign separately to avoid masking return values. In bin/functions line 98: local binary_link=$(set -- $(echo ${binary} | jq -r ".binary_link") ; echo ${1}) ^---------^ SC2155: Declare and assign separately to avoid masking return values. ^-- SC2046: Quote this to prevent word splitting. ^-------^ SC2086: Double quote to prevent globbing and word splitting. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: local binary_link=$(set -- $(echo "${binary}" | jq -r ".binary_link") ; echo "${1}") In bin/functions line 99: local checksum_link=$(set -- $(echo ${binary} | jq -r ".checksum_link") ; echo ${1}) ^-----------^ SC2155: Declare and assign separately to avoid masking return values. ^-- SC2046: Quote this to prevent word splitting. ^-------^ SC2086: Double quote to prevent globbing and word splitting. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: local checksum_link=$(set -- $(echo "${binary}" | jq -r ".checksum_link") ; echo "${1}") In bin/functions line 101: cd ${TEMP_DIR} ^------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. ^---------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: cd "${TEMP_DIR}" || exit In bin/functions line 102: curl -LO -# -w "%{filename_effective}\n" ${binary_link} ^------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: curl -LO -# -w "%{filename_effective}\n" "${binary_link}" In bin/functions line 103: if [ $? -ne 0 ] ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. In bin/functions line 108: curl -LO -# -w "%{filename_effective}\n" ${checksum_link} ^--------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: curl -LO -# -w "%{filename_effective}\n" "${checksum_link}" In bin/functions line 109: if [ $? -ne 0 ] ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. In bin/functions line 114: ${SHA256SUM} -c $(basename ${checksum_link}) ^--------------------------^ SC2046: Quote this to prevent word splitting. ^--------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: ${SHA256SUM} -c $(basename "${checksum_link}") In bin/functions line 116: tar zxf $(basename ${binary_link}) ^------------------------^ SC2046: Quote this to prevent word splitting. ^------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: tar zxf $(basename "${binary_link}") In bin/functions line 117: dir=$(set -- $(ls -d */) ; echo ${1}) ^---------^ SC2046: Quote this to prevent word splitting. ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: dir=$(set -- $(ls -d */) ; echo "${1}") In bin/functions line 118: cd ${dir} ^-------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. ^----^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: cd "${dir}" || exit In bin/functions line 119: mkdir -p ${ASDF_INSTALL_PATH} ^------------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: mkdir -p "${ASDF_INSTALL_PATH}" In bin/functions line 123: azul*) mv * ${ASDF_INSTALL_PATH} ;; ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options. ^------------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: azul*) mv * "${ASDF_INSTALL_PATH}" ;; In bin/functions line 124: *) mv Contents/Home/* ${ASDF_INSTALL_PATH} ;; ^------------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: *) mv Contents/Home/* "${ASDF_INSTALL_PATH}" ;; In bin/functions line 126: *) mv * ${ASDF_INSTALL_PATH} ;; ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options. ^------------------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: *) mv * "${ASDF_INSTALL_PATH}" ;; In bin/functions line 130: case `basename ${0}` in ^-------------^ SC2006: Use $(...) notation instead of legacy backticked `...`. ^--^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: case $(basename "${0}") in For more information: https://www.shellcheck.net/wiki/SC2045 -- Iterating over ls output is fragi... https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2064 -- Use single quotes, otherwise this... ```

Changes from pull request #44 (support for SapMachine) are included in this PR. I will rebase it on current master if PR #44 has been merged before this PR.

joschi commented 4 years ago

@halcyon I think the Travis CI check is failing due to rate limits in the GitHub API.

halcyon commented 4 years ago

@halcyon I think the Travis CI check is failing due to rate limits in the GitHub API.

That's an interesting problem. Could Github Actions be vulnerable to the same problem?

joschi commented 4 years ago

That's an interesting problem. Could GitHub Actions be vulnerable to the same problem?

@halcyon In theory yes, but the fact that we can use the automatically generated token in GitHub workflows, the limit will be much higher.

https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token