Issue with curl downloading corrupt DMG images

859 Views Asked by At

I'm trying to create an automated way to download multiple applications and install them, and I seem to be having trouble at the first hurdle. I am able to download and install .pkg files with no issue, but when it comes to .dmg files I'm getting an 'Image not recognized' error. Here is the lines of commands I'm having issue with:

curl --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15" -L -k https://m.vona.ge/getMAC > /tmp/vonage.dmg
hdiutil attach -mountpoint /Volumes/vonage /tmp/vonage.dmg
cp -R /Volumes/vonage/Vonage\ Business.app /Applications/

The DMG files download and open with no issue when downloaded in Safari, but using curl in Terminal gives me the same problem every time. Here is my error:

hdiutil: attach failed - image not recognized

Any help would be greatly appreciated!

2

There are 2 best solutions below

1
On

First, do a curl with -I option. It will only do a head request and return headers. Usually there are a few location headers that redirect. Once you reach the final page, do a curl -i and see the headers with the body, and make sure it's the actual file, not a piece of Javascript that redirects to file download.

If you don't, you're basically downloading the HTML, not the file. Your browser automatically does the redirect and runs Javascript.

0
On

If the link results in a redirect, the browser will automatically follow it where curl won't.

See if curl -L ... with the L-flag fixes the issue.