setup-download-links.sh 2.49 KB
Newer Older
Houtan Bastani's avatar
Houtan Bastani committed
1
#!/usr/bin/env bash
2 3 4

set -e

Houtan Bastani's avatar
Houtan Bastani committed
5
cd _includes
6

7
for branch in release snapshot; do
8 9
    mkdir -p "$branch"
    cd "$branch"
10

Sébastien Villemot's avatar
Sébastien Villemot committed
11 12
    for dir in macos source windows windows-7z windows-zip; do
        wget --no-verbose "https://www.dynare.org/$branch/$dir.json"
Houtan Bastani's avatar
Houtan Bastani committed
13 14
        readarray -t filenames < <(jq .[].filename "$dir.json")
        readarray -t timestamps < <(jq .[].date "$dir.json")
15
        readarray -t size < <(jq .[].size "$dir.json")
16
        n=$(jq length "$dir.json")
Houtan Bastani's avatar
Houtan Bastani committed
17
        includeFilename="download-$branch-$dir.html"
18 19 20 21
        echo > "$includeFilename"
        for ((i = 0; i < n; i++)); do
            filename=${filenames[i]%\"}
            filename=${filename#\"}
22
            mb=$((size[i] / (10 ** 6)))
23
            if [[ $branch == release ]]; then
24
                readarray -t -d - split <<< "$filename"
25 26
                if [[ $dir == windows* ]]; then
                    version=${split[1]}
Houtan Bastani's avatar
Houtan Bastani committed
27
                    ext=${filename##*.}
28
                elif [[ $dir == macos ]]; then
Houtan Bastani's avatar
Houtan Bastani committed
29 30 31
                    version=${split[1]%.*}
                    ext=${filename##*.}
                else
32 33
                    ext=$(echo "${split[1]}" | rev | cut -d. -f2,1 | rev)
                    version=$(echo "${split[1]}" | cut -d. -f1,2,3)
34
                    echo "{% assign dynare_stable_version = \"$version\" %}" > ../dynare_stable_version.md
Houtan Bastani's avatar
Houtan Bastani committed
35
                fi
Houtan Bastani's avatar
Houtan Bastani committed
36
                {
Houtan Bastani's avatar
Houtan Bastani committed
37
                    echo "<a href=\"https://www.dynare.org/$branch/$dir/$filename\">Dynare $version ($ext)</a> ($mb MB)"
Houtan Bastani's avatar
Houtan Bastani committed
38 39
                    echo "<a href=\"https://www.dynare.org/$branch/$dir/$filename.sig\">[signature]</a>"
                } >> "$includeFilename"
Houtan Bastani's avatar
Houtan Bastani committed
40
            else
41 42 43 44
                timestamp=${timestamps[i]%\"}
                timestamp=${timestamp#\"}
                if [[ $OSTYPE == darwin* ]]; then
                    datestr=$(date -r "$timestamp")
Houtan Bastani's avatar
Houtan Bastani committed
45
                else
46
                    datestr=$(date -d @"$timestamp")
Houtan Bastani's avatar
Houtan Bastani committed
47
                fi
Houtan Bastani's avatar
Houtan Bastani committed
48 49
                {
                    echo "<div class=\"download_row\" onclick=\"document.location = 'https://www.dynare.org/$branch/$dir/$filename'\" onkeypress=\"document.location = 'https://www.dynare.org/$branch/$dir/$filename'\">"
Houtan Bastani's avatar
Houtan Bastani committed
50 51
                    echo "  <div class=\"download_cell_left\"><i class=\"fas fa-file-download\"></i>&nbsp;$datestr</div>"
                    echo "  <div class=\"download_cell_right\"><a href=\"#\">$filename</a> ($mb MB)</div>"
Houtan Bastani's avatar
Houtan Bastani committed
52 53
                    echo "</div>"
                } >> "$includeFilename"
Houtan Bastani's avatar
Houtan Bastani committed
54
            fi
55 56
        done
    done
Houtan Bastani's avatar
Houtan Bastani committed
57
    rm -- *json*
58
    cd ..
59
done