summarylogtreecommitdiffstats
path: root/dlagent
blob: 673ebdbe704eb4392229e1b1bb3621f459edacf9 (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
#!/bin/sh
set -eu

if [ $# -lt 3 ]; then
    echo "Error: arguments base_url, file_url and target_file required." >&2
    exit 1
fi

base_url="$1"
file_url="$2"
target_file="$3"
success=false

rm -f "$target_file"

for i in 1 2 3; do
    echo "Authenticating for download ..." >&2
    curl -fsSL -A Mozilla "$base_url/cookie/init.js.php" > /dev/null

    echo "Downloading ..." >&2
    curl -fLC - --retry 5 --retry-delay 3 -A Mozilla -o "$target_file" "$file_url"

    echo "Checking ..." >&2
    if unzip -p "$target_file" >/dev/null 2>&1; then
        success=true
        break
    fi

    if [ $i -lt 3 ]; then
        rm -f "$target_file"
        echo "Warning: invalid zip file - retrying." >&2
    else
        echo "Error: invalid zip file." >&2
    fi
done

[ "$success" = "true" ] && exit 0 || exit 1