fetch_libs.sh 1.96 KB
Newer Older
1
#!/bin/bash
Camil Staps's avatar
Camil Staps committed
2 3 4 5 6 7
set -e

if [ ! -e libs.json ]; then
   echo "libs.json not found"
	exit -1
fi
8 9 10

DEST="$1"

11 12
CURL="curl -sSL --retry 20 --retry-connrefused"

13 14 15
rm -rf "$DEST"
mkdir -p "$DEST"

16
exec 5< <(jq '.[]' < libs.json | jq '.[]' | jq -cMr '.name,.fetch_url[0,1],.fetch_url[2][0,1],.path')
17 18 19 20 21

while read lib <&5
do
	read fetch_method <&5
	read fetch_url <&5
22 23
	read platform <&5
	read distribution <&5
24 25
	read path <&5

26 27
	rm -rf "$DEST/$lib"

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	case "$fetch_method" in
		"SVN")
			if [[ "$path" == "null" ]]; then
				echo "Fetching $fetch_url..."
				svn checkout -q "$fetch_url" "$DEST/$lib"
			else
				echo "Fetching $fetch_url/$path..."
				svn checkout -q "$fetch_url/$path" "$DEST/$lib"
			fi
			;;
		"Git")
			if [[ "$path" == "null" ]]; then
				echo "Fetching $fetch_url..."
				git clone -q "$fetch_url" "$DEST/$lib"
			else
				echo "Fetching $fetch_url/$path..."
				git clone -q "$fetch_url" "/tmp/$lib"
				mv "/tmp/$lib/$path" "$DEST/$lib"
				rm -rf "/tmp/$lib"
			fi
			;;
		"CleanDistribution")
50 51
			if [[ "$platform" == windows* ]]; then
				URL="https://ftp.cs.ru.nl/Clean/builds/$platform/clean-$distribution-$platform-latest.zip"
52
				$CURL "$URL" -o temp.zip
53 54 55 56 57 58 59 60
				unzip -q -d "$DEST" temp.zip "clean-$distribution/Libraries/*"
				rm temp.zip
				mv "$DEST/clean-$distribution/Libraries"/* "$DEST"
				rmdir "$DEST/clean-$distribution/Libraries"
				rmdir "$DEST/clean-$distribution"
			else
				URL="https://ftp.cs.ru.nl/Clean/builds/$platform/clean-$distribution-$platform-latest.tgz"
				echo "Fetching $URL..."
61
				$CURL "$URL" | tar xz --exclude=exe -C "$DEST" --strip-components=2 "clean-$distribution/lib"
62
			fi
63 64 65 66 67 68 69
			;;
		*)
			echo "Unknown fetch method '$fetch_method'"
			exit 1
			;;
	esac
done
70 71 72 73 74 75 76 77 78 79

shopt -s globstar
for f in "$DEST"/**/*.[id]cl; do
	enc="$(file -bi "$f" | grep -Po '(?<=charset=).*')"
	if [ "$enc" != 'us-ascii' -a "$enc" != 'binary' -a "$enc" != 'utf-8' ]; then
		iconv -f "$enc" -t utf-8 < "$f" > "$f.tmp"
		mv "$f.tmp" "$f"
		echo "converted $f from $enc to utf-8"
	fi
done