summaryrefslogblamecommitdiffstats
path: root/modules/download.inc
blob: 8c717eb697524343c7c3b4e92cbfe7ca75b72e0b (plain) (tree)
1
2
3
4
5
6
7


            
                                                                             

 
                  














                                                                 
            
                     

 
#!/bin/ash

download() {
	curl --location --max-redirs 5 --max-time 15 --connect-timeout 2 "$@"
}

download_retry() {
	local delay max_time start end ret
	max_time=8
	ret=100
	if [ "$1" = "--slx-time" ]; then
		max_time="$2"
		shift 2
	fi
	start="$( date +%s )"
	for delay in 1 2 2 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5 ""; do
		download "$@"
		ret="$?"
		[ "$ret" = 0 ] && return 0
		end="$( date +%s )"
		[ "$(( end - start ))" -ge "$max_time" ] && break
		[ -n "$delay" ] && sleep "$delay"
	done
	return "$ret"
}