Tim Edwards | debc0a4 | 2020-12-28 22:11:40 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Tim Edwards | 6ee1153 | 2021-02-11 12:29:33 -0500 | [diff] [blame] | 3 | # 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 Edwards | debc0a4 | 2020-12-28 22:11:40 -0500 | [diff] [blame] | 18 | # 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 Edwards | debc0a4 | 2020-12-28 22:11:40 -0500 | [diff] [blame] | 20 | |
| 21 | DL_CMD= |
| 22 | if type "wget" > /dev/null; then |
| 23 | DL_CMD="wget -qO" |
| 24 | fi |
| 25 | |
| 26 | if type "curl" > /dev/null; then |
| 27 | DL_CMD="curl -sLo" |
| 28 | fi |
| 29 | |
| 30 | if [ "$DL_CMD" = "" ]; then |
Tim Edwards | 6ee1153 | 2021-02-11 12:29:33 -0500 | [diff] [blame] | 31 | echo "ERROR: Either curl or wget are required to automatically install tools." |
Tim Edwards | debc0a4 | 2020-12-28 22:11:40 -0500 | [diff] [blame] | 32 | exit 1 |
| 33 | fi |
| 34 | |
Tim Edwards | 6ee1153 | 2021-02-11 12:29:33 -0500 | [diff] [blame] | 35 | pdir=`dirname $2` |
| 36 | mkdir -p $pdir |
| 37 | cd $pdir |
| 38 | |
| 39 | echo "Downloading $1 to $2" |
| 40 | $DL_CMD $2.tar.gz $1 |
| 41 | |
| 42 | mkdir -p $2 |
| 43 | tar -xf $2.tar.gz --strip-components 1 -C $2 |
| 44 | rm $2.tar.gz |
| 45 | exit 0 |