2014-02-21 22:32:35 -07:00
|
|
|
platform='unknown'
|
|
|
|
unameval=`uname`
|
2014-02-23 13:01:41 -07:00
|
|
|
if [ "$unameval" = 'Linux' ]; then
|
2014-02-21 22:32:35 -07:00
|
|
|
platform='linux'
|
2014-02-23 13:01:41 -07:00
|
|
|
elif [ "$unameval" = 'FreeBSD' ]; then
|
2014-02-21 22:32:35 -07:00
|
|
|
platform='freebsd'
|
|
|
|
fi
|
|
|
|
|
|
|
|
sha1sumcmd='sha1sum'
|
2014-02-23 13:01:41 -07:00
|
|
|
if [ "$platform" = 'freebsd' ]; then
|
2014-02-21 22:32:35 -07:00
|
|
|
sha1sumcmd='shasum'
|
|
|
|
fi
|
|
|
|
|
2014-02-01 07:20:02 -07:00
|
|
|
pkgroot="$(pwd)"
|
|
|
|
deps="$pkgroot/.deps"
|
|
|
|
prefix="$deps/usr"
|
|
|
|
export PATH="$prefix/bin:$PATH"
|
|
|
|
|
|
|
|
download() {
|
|
|
|
local url=$1
|
|
|
|
local tgt=$2
|
|
|
|
local sha1=$3
|
|
|
|
|
|
|
|
if [ ! -d "$tgt" ]; then
|
|
|
|
mkdir -p "$tgt"
|
2014-02-22 15:49:53 -07:00
|
|
|
local download_command=""
|
2014-02-01 07:20:02 -07:00
|
|
|
if which wget > /dev/null 2>&1; then
|
2014-02-22 15:49:53 -07:00
|
|
|
# -O - to send output to stdout
|
|
|
|
download_command="wget $url -O -"
|
|
|
|
elif which curl >/dev/null 2>&1; then
|
|
|
|
# -L to follow the redirects that github will send us
|
|
|
|
# -sS to supress the progress bar, but show errors
|
|
|
|
# curl sends output to stdout by default
|
|
|
|
download_command="curl -L -sS $url"
|
2014-02-01 07:20:02 -07:00
|
|
|
else
|
2014-02-22 15:49:53 -07:00
|
|
|
echo "Missing wget utility and curl utility"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
local tmp_dir=$(mktemp -d "/tmp/download_sha1check_XXXXXXX")
|
|
|
|
local fifo="$tmp_dir/fifo"
|
|
|
|
mkfifo "$fifo"
|
|
|
|
# download, untar and calculate sha1 sum in one pass
|
|
|
|
($download_command | tee "$fifo" | \
|
|
|
|
(cd "$tgt"; tar --strip-components=1 -xvzf -)) &
|
|
|
|
local sum=$("$sha1sumcmd" < "$fifo" | cut -d ' ' -f1)
|
|
|
|
rm -rf "$tmp_dir"
|
|
|
|
if [ "$sum" != "$sha1" ]; then
|
|
|
|
echo "SHA1 sum doesn't match, expected '$sha1' got '$sum'"
|
2014-02-01 07:20:02 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
github_download() {
|
|
|
|
local repo=$1
|
|
|
|
local ver=$2
|
|
|
|
download "https://github.com/${repo}/archive/${ver}.tar.gz" "$3" "$4"
|
|
|
|
}
|