Monday, November 22, 2010

To download Android codes under a firewall blocking the default GIT port

A firewall of an institute can block GIT from downloading source codes from a web site. This may be because the firewall blocks the default GIT port, which is 9418. In this problematic case, HTTP can replace GIT protocol. GIT supports HTTP protocol for download, and firewalls usually permit the HTTP ports. I met this situation when I tried to download Android source codes in a campus of a Korean University. This is a very simple tip to use HTTP protocol to download the Android codes using GIT.


[Steps]


Ubuntu 10.04 LTS is my environment, though it doesn't matter very much.


The general guideline for downloading Android codes is available on http://source.android.com/source/download.html.

According to the above guideline, you are assumed to have the utility, repo, to run successfully it, and to have .repo directory. This is the point where I met the firewall problem.

You need to replace all uses of GIT protocol, "git:", with "http:" in the initialization. I have a little tip to do this quickly and, hopefully, correctly.
  • $ grep -sr "git:" .repo | cut -d: -f1 | xargs -d '\n' sed -i -e 's/git:/http:/g'
In case the above command doesn't work, you may be required to correct some in the command. For the purpose, I give a brief explanation on it.
  • -s of grep to suppress error messages
  • -r of grep to do recursively
  • -d: of cut to use ':' as a delimeter
  • -f1 of cut to select the first column of the delimetered tokens
  • -d '\n' of xargs to use '\n' as a delimeter of xargs this time
  • -i of sed to replace each matched pattern with the target one in place
  • -e 's/git:/http:/g of sed to give a command to substitute every occurrence of "git:" with "http:" globally

    4 comments:

    Anonymous said...

    It is working! Thanks for the useful info. for those facing git port block in there network.

    After repo init, I did the same changes in manifest.xml; before issuing sync command.

    lazyswamp said...

    Great to hear it helped you. Thanks for leaving your comment.

    Anonymous said...

    This works great! I'm behind a restrictive firewall, so I couldn't even run repo init; I had to run that from another server, tar it up, and bring it to my machine. Once I could do that, though, your script seems to have done the trick!

    SK said...

    Works Great !!
    Thanks a lot