#!/bin/bash

set -e

cd $(dirname $0)/..

# tree -L 1 -H https://downloads.syncevolution.org/ >index.html

(echo .; find * -type d) | while read -r dir; do
    file="$dir/index.html"
    if [ -e "$file" ]; then
        if ! grep -q "Made by 'tree'" "$file"; then
            continue
        fi
    fi
    tree -L 1 -H https://downloads.syncevolution.org/$dir/ $dir | \
        sed -e 's;.*\(<hr>\|tree v\|HTML output\|JSON output\|OS/2 support\).*;;' \
            -e 's;//*;/;g' \
            -e 's;https:/;https://;' \
            >"$file"
done
