How to download JDK with curl

Sometimes you have to download Oracle JDK without FireFox or any other graphical browsers on Linux. I tried to download it with Lynx and w3m, but I couldn't.


I first thought that you can download it with a direct file link. But it seems like Oracle checks cookies and I couldn't. Then I thought I could get a cookie by download the file link page first, then I would be able to download it. But there's no cookies set when you download the link page.


After then, I read JavaScript within that link page. I found when you click the "accept" radio button, it surely put the cookie there.


So here's my little bash script using curl to download JDK.

#!/bin/bash
# second and nano second
T=$(date +%s%N)
# Make it 13 digits cause JavaScript Date has only millisecond
T=${T:0:13}
P1="s_nr=${T};"
P2="gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk-6u32-downloads-1594644.html;"
P3="s_sq=%5B%5BB%5D%5D"
COOKIE="$P1 $P2 $P3"
AGENT='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20120421 Firefox/11.0'
TARGET='http://download.oracle.com/otn-pub/java/jdk/6u32-b05/jdk-6u32-linux-x64-rpm.bin'
REFERER='http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html'
curl -v -b "$COOKIE" --user-agent "$AGENT" --referer "$REFERER" -L -O "$TARGET"

なぜ英語?

ググったら同じく困っている人は見かけても回答が見つからなかったので(笑
今回これ自体の開発はChromeのデバッガとCygwinでひたすら地道にやっていたのですが、vimcygwinの組合せが改行コードが異なるのではまりました。
保存時に以下のようにすると改行をunixに強制できるということを勉強しました。

:w ++ff=unix