-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Change FTLcheckUpdate logic #5190
base: development
Are you sure you want to change the base?
Conversation
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 do think this section of code needs to be redone but I think there's a lot of missed opportunities here. We are using jq
now so we should actually use it to it's abilities and not just as a dumb parser.
jq
has a very rich conditionals and comparisons ability that we can use for checking the output from curl
and to process that output for validity. See https://manpages.ubuntu.com/manpages/xenial/man1/jq.1.html#conditionals%20and%20comparisons
|
||
if ! FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep --color=never -i Location: | awk -F / '{print $NF}' | tr -d '[:cntrl:]'); then | ||
if [ -z "${FTLlatesttag}" ]; 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.
This will fail if there is a bad response from the curl
command.
Viking:~$ tag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/lates | jq -r .tag_name)
Viking:~$ echo $tag
null
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 tested and never got null
inside the script, but I will replace the command with:
curl -s https://api.github.com/repos/pi-hole/FTL/releases/lates | jq -r '.tag_name | values'
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.
Do you want to use jq
for the test, like this?
curl -s https://api.github.com/repos/pi-hole/FTL/releases/lat | jq '.tag_name == "${FTLversion}"'
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 current code will work for any curl
response:
- if
curl
returns a valid JSON,jq
will try to find and returntag_name
. - if no
tag_name
is found in JSON response, an empty string will be returned. - if
curl
responds with anything that is not a valid JSON,jq
command will return an empty string.
Command details:
jq -sRr 'fromjson? | .tag_name | values'
-s
will read the entire input file into a large array before apply the filters;-R
will not parse the input as JSON. When combined with-s
, it reads the whole response into a single long string;- The
?
is the error suppression operator and works like a simpletry/catch
. fromjson?
will try to parse the text into JSON format. If not possible will returnnull
..tag_name
will return the value of "tag_name" (ornull
if not found);values
will filter the result and return only "non null values" (returning an empty string in case ofnull
).-r
will output the result as plain text (without the quotes).
- execute `curl` in a separate step - use api.github.com and `jq` to retrieve tag_name - check if current FTL version is less than latest - show error message if return is empty (curl failed) Signed-off-by: RD WebDesign <[email protected]>
7054678
to
1f0eb73
Compare
|
What are you showing there Yubi? Is that output expected or unexpected. |
It's the expected output. When address is not reachable the output of the whole function is an empty string. As opposed to |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Signed-off-by: RD WebDesign <[email protected]>
Conflicts have been resolved. |
Re-requesting review from @dschaper |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. |
What does this PR aim to accomplish?
Fix #5189
How does this PR accomplish the above?
Changing the logic of the function:
curl
in a separate stepapi.github.com
andjq
to retrieve tag_nameLink documentation PRs if any are needed to support this PR:
none
By submitting this pull request, I confirm the following:
git rebase
)