#!/bin/bash
workdir=$(mktemp -d)
cd $workdir
wget -r https://www.felixcloutier.com
workdir+=/www.felixcloutier.com/x86
for f in $workdir/*; do
    if [[ $f == *:* ]]; then
        mv "$f" "${f//:/.}"
        : "${f##*/}"
        sed -i "s|$_|${_//:/.}|g" $workdir/*
        f=${f//:/.}
    fi
    [[ $f == *html ]] || mv "$f" "$f.html"
done
sed -i -E "/href='\/x86[^#']+#/s|href='/x86/([^'#]+)#|href='\1.html#|g" $workdir/*
sed -i -E "/href='\/x86[^']+'/s|href='/x86/([^']+)'|href='\1.html'|g" $workdir/*
sed -i "/href='\/x86\/'/s|href='/x86/'|href='index.html'|g" $workdir/*
