summaryrefslogtreecommitdiff
path: root/scripts/fetch-curl.sh
blob: 1e35c68df8f0ac7cf7d93407955b3ef569e924a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
: "${SHA256SUM:=sha256sum}"
: "${PAXREAD:=pax -r}"

set -e

if [ "$#" != 1 ] ; then
	echo 'usage: fetch-curl.sh dir' >&2
	exit 2
fi

dir=$1
shift

cd "$dir"

if [ -e src ] ; then
	rm -rf src
fi

if ! $SHA256SUM -c sha256 2>/dev/null ; then
	curl -L -K url -O
	$SHA256SUM -c sha256
fi

while read -r _ archive ; do
	case $archive in
	*.tar.gz|*.tgz)
		tool=gzip ;;
	*.tar.bz2)
		tool=bzip2 ;;
	*.tar.xz)
		tool=xz ;;
	*)
		tool=
	esac
	if [ -n "$tool" ] ; then
		"$tool" -d -c "$archive" | $PAXREAD -s ',^[^/]*,src,' '*/*'
	fi
done <sha256

if [ -d patch ] ; then
	git apply -v --whitespace=nowarn --directory "$dir/src" patch/*
fi