I suggest just setting two variables in the if statement here; the URL to download and the decompression parameter for tar.  You can then do the common code afterward.