Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Created Sep 30, 2021
Embed
What would you like to do?
Fix shellcheck errors for archlinux-java script
11c11
< DEFAULT_NAME_JRE=default-runtime
---
> DEFAULT_NAME_JRE="default-runtime"
18c18,19
< if [ $(id -u) -ne 0 ]; then
---
> #if [ $(id -u) -ne 0 ]; then
> if (( UID != 0 )); then
27c28
< if [ $1 -ne $2 ]; then
---
> if [[ "${1}" -ne "${2}" ]]; then
37,38c38,39
< if [ "x${path}" != "x/dev/null" ]; then
< echo ${path/${JVM_DIR}\/}
---
> if [[ "${path}" != "/dev/null" ]]; then
> echo "${path/${JVM_DIR}\/}"
47,48c48,49
< if [ -x ${dir}/bin/java ]; then
< javas+=(${dir/${JVM_DIR}\/})
---
> if [ -x "${dir}/bin/java" ]; then
> javas+=("${dir/${JVM_DIR}\/}")
50,51c51,52
< if [ -x ${dir}/jre/bin/java ]; then
< javas+=(${dir/${JVM_DIR}\/}/jre)
---
> if [ -x "${dir}/jre/bin/java" ]; then
> javas+=("${dir/${JVM_DIR}\/}/jre")
56c57
< echo ${javas[@]}
---
> echo "${javas[*]}"
61c62
< test "x$1" != "x${DEFAULT_NAME}" && test -x ${JVM_DIR}/$1/bin/java
---
> test "x$1" != "x${DEFAULT_NAME}" && test -x "${JVM_DIR}/${1}/bin/java"
66,72c67,73
< new_default=$1
< unlink ${DEFAULT_PATH} 2>/dev/null
< ln -sf ${new_default} ${DEFAULT_PATH}
<
< unlink ${DEFAULT_PATH_JRE} 2>/dev/null
< if [[ -d ${new_default}/jre ]]; then
< ln -sf ${new_default}/jre ${DEFAULT_PATH_JRE}
---
> new_default="${1}"
> unlink "${DEFAULT_PATH}" 2>/dev/null
> ln -sf "${new_default}" "${DEFAULT_PATH}"
>
> unlink "${DEFAULT_PATH_JRE}" 2>/dev/null
> if [[ -d "${new_default}/jre" ]]; then
> ln -sf "${new_default}/jre" "${DEFAULT_PATH_JRE}"
74c75
< ln -sf ${new_default} ${DEFAULT_PATH_JRE}
---
> ln -sf "${new_default}" "${DEFAULT_PATH_JRE}"
86c87,88
< installed_java=($(get_installed_javas))
---
> #installed_java=($(get_installed_javas))
> IFS=" " read -r -a installed_java < <(get_installed_javas)
92c94
< for java in ${installed_java[@]}; do
---
> for java in "${installed_java[@]}"; do
96c98
< elif [ ${java} = "${default_java}" ]; then
---
> elif [ "${java}" = "${default_java}" ]; then
102c104
< if [ -z ${default_java} ]; then
---
> if [ -z "${default_java}" ]; then
114c116
< if ! is_java_valid $1; then
---
> if ! is_java_valid "${1}"; then
119c121
< if [ "x$1" != "x${default}" ] || ! is_java_valid ${default}; then
---
> if [[ "$1" != "${default}" ]] || ! is_java_valid "${default}"; then
121c123
< set_default_link_to $1
---
> set_default_link_to "${1}"
138c140
< if is_java_valid ${default}; then
---
> if is_java_valid "${default}"; then
140c142
< if is_java_valid $(dirname ${default}); then
---
> if is_java_valid "$(dirname "${default}")"; then
142c144
< set_default_link_to $(dirname ${default})
---
> set_default_link_to "$(dirname "${default}")"
153,156c155,159
< to_check=(${potential_fixes[@]} ${openjdk8[@]} $(get_installed_javas))
< for java in ${to_check[@]}; do
< if ! is_java_valid $(get_default_java) && is_java_valid ${java}; then
< set_default_link_to ${java}
---
> IFS=" " read -r -a to_check < <(get_installed_javas)
> to_check=("${potential_fixes[@]}" "${openjdk8[@]}" "${to_check[@]}")
> for java in "${to_check[@]}"; do
> if ! is_java_valid "$(get_default_java)" && is_java_valid "${java}"; then
> set_default_link_to "${java}"
160c163
< if ! is_java_valid $(get_default_java); then
---
> if ! is_java_valid "$(get_default_java)"; then
166c169
< echo "$(basename $0) <COMMAND>"
---
> echo "$(basename "${0}") <COMMAND>"
176c179
< case $1 in
---
> case "${1}" in
179c182
< 'set') check_root; check_param_count $# 2; do_set $2;;
---
> 'set') check_root; check_param_count "${#}" 2; do_set "${2}";;
183c186
< *) echo "$(basename $0): unknown option '$@'"; exit 1;;
---
> *) echo "$(basename "${0}"): unknown option '${*}'"; exit 1;;
27c27
< if [ $1 -ne $2 ]; then
---
> if [[ "${1}" -ne "${2}" ]]; then
11c11
< DEFAULT_NAME_JRE=default-runtime
---
> DEFAULT_NAME_JRE="default-runtime"
138c138
< if is_java_valid ${default}; then
---
> if is_java_valid "${default}"; then
140c140
< if is_java_valid $(dirname ${default}); then
---
> if is_java_valid "$(dirname "${default}")"; then
142c142
< set_default_link_to $(dirname ${default})
---
> set_default_link_to "$(dirname "${default}")"
153,156c153,157
< to_check=(${potential_fixes[@]} ${openjdk8[@]} $(get_installed_javas))
< for java in ${to_check[@]}; do
< if ! is_java_valid $(get_default_java) && is_java_valid ${java}; then
< set_default_link_to ${java}
---
> IFS=" " read -r -a to_check < <(get_installed_javas)
> to_check=("${potential_fixes[@]}" "${openjdk8[@]}" "${to_check[@]}")
> for java in "${to_check[@]}"; do
> if ! is_java_valid "$(get_default_java)" && is_java_valid "${java}"; then
> set_default_link_to "${java}"
160c161
< if ! is_java_valid $(get_default_java); then
---
> if ! is_java_valid "$(get_default_java)"; then
114c114
< if ! is_java_valid $1; then
---
> if ! is_java_valid "${1}"; then
119c119
< if [ "x$1" != "x${default}" ] || ! is_java_valid ${default}; then
---
> if [[ "$1" != "${default}" ]] || ! is_java_valid "${default}"; then
121c121
< set_default_link_to $1
---
> set_default_link_to "${1}"
86c86,87
< installed_java=($(get_installed_javas))
---
> #installed_java=($(get_installed_javas))
> IFS=" " read -r -a installed_java < <(get_installed_javas)
92c93
< for java in ${installed_java[@]}; do
---
> for java in "${installed_java[@]}"; do
96c97
< elif [ ${java} = "${default_java}" ]; then
---
> elif [ "${java}" = "${default_java}" ]; then
102c103
< if [ -z ${default_java} ]; then
---
> if [ -z "${default_java}" ]; then
37,38c37,38
< if [ "x${path}" != "x/dev/null" ]; then
< echo ${path/${JVM_DIR}\/}
---
> if [[ "${path}" != "/dev/null" ]]; then
> echo "${path/${JVM_DIR}\/}"
47,48c47,48
< if [ -x ${dir}/bin/java ]; then
< javas+=(${dir/${JVM_DIR}\/})
---
> if [ -x "${dir}/bin/java" ]; then
> javas+=("${dir/${JVM_DIR}\/}")
50,51c50,51
< if [ -x ${dir}/jre/bin/java ]; then
< javas+=(${dir/${JVM_DIR}\/}/jre)
---
> if [ -x "${dir}/jre/bin/java" ]; then
> javas+=("${dir/${JVM_DIR}\/}/jre")
56c56
< echo ${javas[@]}
---
> echo "${javas[*]}"
18c18,19
< if [ $(id -u) -ne 0 ]; then
---
> #if [ $(id -u) -ne 0 ]; then
> if (( UID != 0 )); then
61c61
< test "x$1" != "x${DEFAULT_NAME}" && test -x ${JVM_DIR}/$1/bin/java
---
> test "x$1" != "x${DEFAULT_NAME}" && test -x "${JVM_DIR}/${1}/bin/java"
176c176
< case $1 in
---
> case "${1}" in
179c179
< 'set') check_root; check_param_count $# 2; do_set $2;;
---
> 'set') check_root; check_param_count "${#}" 2; do_set "${2}";;
183c183
< *) echo "$(basename $0): unknown option '$@'"; exit 1;;
---
> *) echo "$(basename "${0}"): unknown option '${*}'"; exit 1;;
166c166
< echo "$(basename $0) <COMMAND>"
---
> echo "$(basename "${0}") <COMMAND>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment