blob: 1bfadc11ab9af209ec3961463984ca6c02406f53 [file] [log] [blame]
Tim Edwardsdebc0a42020-12-28 22:11:40 -05001#!/bin/sh
2#
Tim Edwards6ee11532021-02-11 12:29:33 -05003# download.sh --
4# Download a tarball from the specified URL to the specified target
5# directory, untar it, and remove the tarball file.
6#
7# Usage: download.sh <url> <target_dir>
8#
9# where:
10#
11# <url> is the URL of the repository to download, in gzipped tarball format
12# <target_dir> is the local name to call the untarred directory. The
13# tarball will be downloaded to the directory above this,
14# untarred while renaming to <target_dir>, and then the tarball
15# file will be deleted.
16#
17
Tim Edwardsdebc0a42020-12-28 22:11:40 -050018# Neither curl or wget are guaranteed to be included in all *nix systems,
19# (but most have *one* of them). This tools tries its best to find one.
Tim Edwardsdebc0a42020-12-28 22:11:40 -050020
21DL_CMD=
22if type "wget" > /dev/null; then
23 DL_CMD="wget -qO"
24fi
25
26if type "curl" > /dev/null; then
27 DL_CMD="curl -sLo"
28fi
29
30if [ "$DL_CMD" = "" ]; then
Tim Edwards6ee11532021-02-11 12:29:33 -050031 echo "ERROR: Either curl or wget are required to automatically install tools."
Tim Edwardsdebc0a42020-12-28 22:11:40 -050032 exit 1
33fi
34
Tim Edwards6ee11532021-02-11 12:29:33 -050035pdir=`dirname $2`
36mkdir -p $pdir
37cd $pdir
38
39echo "Downloading $1 to $2"
40$DL_CMD $2.tar.gz $1
41
42mkdir -p $2
43tar -xf $2.tar.gz --strip-components 1 -C $2
44rm $2.tar.gz
45exit 0