cleanup
[cmdllinux.git] / scripts / _wget_retval_bashpipe.sh
blob4e5ce6a07edaab925d23c664eed714cfab5c87ec
2 WGET_CONNOPTS="--passive-ftp -t 1 --timeout=5"
3 WGET_OPTS="-q --progress=dot --show-progress"
5 [ -z "$1" ] && exit 1
6 URL="$1"
7 FILE="${URL##*/}"
9 bar=`expr $(stty size | cut -d " " -f 2) - ${#FILE} - 1 - 2 - 4 - 1 - 1`
11 wget $WGET_OPTS $WGET_CONNOPTS $URL -O $FILE 2>&1 | \
12 sed -u -n -e 's/%.*//' -e 's/.* //p' | \
13 while read perc; do
14 if [ "$dperc" != "$perc" ]; then
15 barp=$(($bar * $perc / 100))
16 barend=$(($bar - $barp))
17 printf "\r%-$((${#FILE} + 1))s" "$FILE"
18 printf "["
19 for i in $(seq 1 $barp); do
20 printf "#"
21 done
22 for i in $(seq 1 $barend); do
23 printf " "
24 done
25 printf "] "
26 printf "%4s" "${perc}%"
27 dperc=$perc
29 done
30 retval=${PIPESTATUS[0]}
31 if [ "$retval" = "0" ]; then
32 printf "\r%-$((${#FILE} + 1))s" "$FILE"
33 printf "["
34 for i in $(seq 1 $bar); do
35 printf "#"
36 done
37 printf "] "
38 printf "%4s" "100%"
39 printf "\n"
42 exit $retval