Skip to content
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

Consider fixing shellcheck issues #36

Open
shuuryou opened this issue Oct 28, 2023 · 0 comments
Open

Consider fixing shellcheck issues #36

shuuryou opened this issue Oct 28, 2023 · 0 comments

Comments

@shuuryou
Copy link

There are some minor issues when running ShellCheck on the script. The biggest ones (using features not available on POSIX sh) can be fixed by changing the shebang from #!/bin/sh to e.g. #!/usr/bin/env bash

What follows is the full ShellCheck output so you can get an idea. This is after I changed the interpreter from sh to bash. I understand that majority of the problems it finds are subjective, but I still figured I'd let you know. Feel free to close the issue as WONTFIX etc. if you don't care.

# shellcheck hetznerddns.sh

In hetznerddns.sh line 46:
  echo ${1}: Record_Name: ${record_name} : ${2}
       ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
                          ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                           ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
  echo "${1}": Record_Name: "${record_name}" : "${2}"


In hetznerddns.sh line 81:
          --header 'Auth-API-Token: '${auth_api_token})
                                     ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          --header 'Auth-API-Token: '"${auth_api_token}")


In hetznerddns.sh line 84:
if [[ "$(echo ${zone_info} | jq --raw-output '.zones[] | select(.name=="'${zone_name}'") | .id')" = "" && "$(echo ${zone_info} | jq --raw-output '.zones[] | select(.id=="'${zone_id}'") | .name')" = "" ]]; then
              ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                         ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                  ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                                                                           ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
if [[ "$(echo "${zone_info}" | jq --raw-output '.zones[] | select(.name=="'"${zone_name}"'") | .id')" = "" && "$(echo "${zone_info}" | jq --raw-output '.zones[] | select(.id=="'"${zone_id}"'") | .name')" = "" ]]; then


In hetznerddns.sh line 93:
  zone_id=$(echo ${zone_info} | jq --raw-output '.zones[] | select(.name=="'${zone_name}'") | .id')
                 ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                            ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
  zone_id=$(echo "${zone_info}" | jq --raw-output '.zones[] | select(.name=="'"${zone_name}"'") | .id')


In hetznerddns.sh line 98:
  zone_name=$(echo ${zone_info} | jq --raw-output '.zones[] | select(.id=="'${zone_id}'") | .name')
                   ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                            ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
  zone_name=$(echo "${zone_info}" | jq --raw-output '.zones[] | select(.id=="'"${zone_id}"'") | .name')


In hetznerddns.sh line 137:
                 --request GET 'https://dns.hetzner.com/api/v1/records?zone_id='${zone_id} \
                                                                                ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
                 --request GET 'https://dns.hetzner.com/api/v1/records?zone_id='"${zone_id}" \


In hetznerddns.sh line 138:
                 --header 'Auth-API-Token: '${auth_api_token})
                                            ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
                 --header 'Auth-API-Token: '"${auth_api_token}")


In hetznerddns.sh line 145:
    record_id=$(echo ${record_zone} | jq | sed '$d' | jq --raw-output '.records[] | select(.type == "'${record_type}'") | select(.name == "'${record_name}'") | .id')
                     ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                      ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                                                                                                            ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
    record_id=$(echo "${record_zone}" | jq | sed '$d' | jq --raw-output '.records[] | select(.type == "'"${record_type}"'") | select(.name == "'"${record_name}"'") | .id')


In hetznerddns.sh line 156:
       -H 'Auth-API-Token: '${auth_api_token} \
                            ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
       -H 'Auth-API-Token: '"${auth_api_token}" \


In hetznerddns.sh line 158:
          "value": "'${cur_pub_addr}'",
                     ^-------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          "value": "'"${cur_pub_addr}"'",


In hetznerddns.sh line 159:
          "ttl": '${record_ttl}',
                  ^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          "ttl": '"${record_ttl}"',


In hetznerddns.sh line 160:
          "type": "'${record_type}'",
                    ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          "type": "'"${record_type}"'",


In hetznerddns.sh line 161:
          "name": "'${record_name}'",
                    ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          "name": "'"${record_name}"'",


In hetznerddns.sh line 162:
          "zone_id": "'${zone_id}'"
                       ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
          "zone_id": "'"${zone_id}"'"


In hetznerddns.sh line 166:
  cur_dyn_addr=`curl -s "https://dns.hetzner.com/api/v1/records/${record_id}" -H 'Auth-API-Token: '${auth_api_token} | jq --raw-output '.record.value'`
               ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                                                                                   ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
  cur_dyn_addr=$(curl -s "https://dns.hetzner.com/api/v1/records/${record_id}" -H 'Auth-API-Token: '"${auth_api_token}" | jq --raw-output '.record.value')


In hetznerddns.sh line 171:
  if [[ $cur_pub_addr == $cur_dyn_addr ]]; then
                         ^-----------^ SC2053 (warning): Quote the right-hand side of == in [[ ]] to prevent glob matching.


In hetznerddns.sh line 178:
         -H 'Auth-API-Token: '${auth_api_token} \
                              ^---------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
         -H 'Auth-API-Token: '"${auth_api_token}" \


In hetznerddns.sh line 180:
           "value": "'${cur_pub_addr}'",
                      ^-------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
           "value": "'"${cur_pub_addr}"'",


In hetznerddns.sh line 181:
           "ttl": '${record_ttl}',
                   ^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
           "ttl": '"${record_ttl}"',


In hetznerddns.sh line 182:
           "type": "'${record_type}'",
                     ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
           "type": "'"${record_type}"'",


In hetznerddns.sh line 183:
            "name": "'${record_name}'",
                      ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
            "name": "'"${record_name}"'",


In hetznerddns.sh line 184:
           "zone_id": "'${zone_id}'"
                        ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
           "zone_id": "'"${zone_id}"'"


In hetznerddns.sh line 186:
    if [[ $? != 0 ]]; then
          ^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.

For more information:
  https://www.shellcheck.net/wiki/SC2053 -- Quote the right-hand side of == i...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
  https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant