#!/bin/bash

if [ $# -lt 1 ]; then
    echo "usage: $0 wims-version number". 
    echo "example: $0 4.02"
    exit 1
fi

url=https://sourcesup.cru.fr/frs/?group_id=379

archiveUrl=$(wget -q -O - $url | sed -n 's%.*\(https://sourcesup.cru.fr/frs/download.php.*/wims-'$1'.tgz\).*%\1% p')

if [ -n "$archiveUrl" ]; then
    targetDir="wims-$1/wims"
    mkdir -p "$targetDir"
    wget -q -O - $archiveUrl | tar xzf - -C "$targetDir"
else
    echo "archive not found"
fi

