-1

I try to figure out why the command below doesn't work because on one UDM-Pro it worked perfectly.

dl_url=$(curl -fsL "https://api.github.com/repos/boostchicken-dev/udm-utilities/releases/latest" | awk '$0 ~ /"browser_download_url"/ {sub(/.*:\s*"/,"",$0); gsub("\"", "", $0); print $2}')
curl -Lo udm-boot_latest.deb $dl_url

The output is the following:

Output picture

unifi-os shell

root@ubnt:/# dl_url=$(curl -fsL "https://api.github.com/repos/boostchicken-dev/udm-utilities/releases/latest" | awk '$0 ~ /"browser_download_url"/ {sub(/.:\s"/,"",$0); gsub(""", "", $0); print $2}')

root@ubnt:/# curl -Lo udm-boot_latest.deb $dl_url

curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information

root@ubnt:/#

What is wrong with this command? On another UDM-Pro it worked perfectly.

Thx a lot! :)

I don't know what I can change?

M-LAN
  • 1
  • 1
  • Do it in pieces to see where the process breaks down: `curl ... > tmpfile` then `awk ... < tmpfile` – glenn jackman Nov 24 '22 at 16:38
  • The `\s` in the awk regex looks suspicious: not every awk supports that – glenn jackman Nov 24 '22 at 16:38
  • Note also that curl will output headers with `\r\n` line endings: you may need to remove the carriage return` – glenn jackman Nov 24 '22 at 16:39
  • Separately, [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Nov 24 '22 at 18:04
  • Putting the `set -x` command at the beginning to get an execution trace is another good way to get info about what's happening (especially, what the `dl_url` variable is actually getting set to). – Gordon Davisson Nov 24 '22 at 18:41
  • Thx a lot to all, I'll try it! It's also much easier when I follow the api link and copy the url under "browser_download_url" manually. Like: curl -Lo udm-boot_latest.deb "Manually copied link". But again I'll try to modify the command above. :) – M-LAN Nov 25 '22 at 10:23

1 Answers1

0

Your problem is that you likely did not use the command in an identical fashion to the previous successful cases.

The triple double-quote is where the big problem lies. Logically, you cannot encapsulate any type of quotation (single or double) by the same type of quotation, so that >> """ << is a bust! You need to use the form /"/ instead, which is hinted at by the documentation for the AWK gsub function specifying regexp in the first field.

Also, there is no need for the use of sub in this script. You can avoid that by making the reference to $2. The resulting assignment should look like this:

PROJ_DEPOT="https://api.github.com/repos/boostchicken-dev/udm-utilities/releases/latest"
dl_url=$(curl -fsL "${PROJ_DEPOT}" | 
    awk '$0 ~ /"browser_download_url"/ { gsub(/"/, "", $0 ) ; print $2 }' )
Eric Marceau
  • 1,601
  • 1
  • 8
  • 11