Download CURL and GREP Explanation

So, it is all piped together which causes the command to be executed from left to right something like this:

  1. curl is run up to first | to get the latest web data from releases html page.
  2. then grep is used to find “browser_download_url”
    • This returns many of them so the next grep is used to clean this up more
    • “browser_download_url”…checksums.txt”
    • “browser_download_url”…docker-compose-windows-x86_64.exe”
    • “browser_download_url”…compose-windows-x86_64.exe.sha256”
    • “browser_download_url”…LICENSE”
  3. in all the returned data find "docker-compose-$(uname -s)-$(uname -m)\"$" with case insensitivity
    • $(uname -s) returns Linux in my case
    • $(uname -m) returns x86_64
    • In the download URL they are all lower case that is why I added the -i for case insensitivity
    • \”$ is there because there are two results still one for the binary and one for the checksum file and I only wanted the binary. This command look for a quote at the end of the string
      • the returned data without the \”$
        • …docker-compose-linux-x86_64″
        • …docker-compose-linux-x86_64.sha256″
      • \” – looks for a literal quote \ tells grep and for that matter Linux the next character is to be taken literally and not treated as a delimiter.
      • $ – this tells grep to search at the end of the line this eliminating the other entry with the added extension.
  4. So with all of that it will download only the binary compatible with your linux flavor as long as docker-compose has the proper lables listed for $(uname -s) and $(uname -m) . So, this worked for me and I hope it is as clear as mud!
    • It is possible to do echo "docker-compose-$(uname -s)-$(uname -m)\"" to see if the output is close to what is expected
    • Then run curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url to see if there is a line that will match your expected output.
    • Also, can combine the greps like this
      • curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep -i "docker-compose-$(uname -s)-$(uname -m)"
      • Note: two lines should return as this does not filter on \”$

Leave a Reply

Your email address will not be published. Required fields are marked *