#!/usr/bin/env bash
dir="$HOME/code/thirdparty"
list="$dir/SOURCE.txt"

grep '^[^#]' "$list" | while read -r file url mode; do
	echo "$url → $file"
	path="$dir/$file"
	case $url in
		/afs/*)
			#url="https://lost-contact.mit.edu$url" ;;&
			scp "wind:$url" "$path" ;;
		http://*|https://*)
			curl -s -S -f -L "$url" -o "$path" ;;
	esac
	if [[ $mode ]]; then
		chmod "$mode" "$path"
	fi
done
