#!/bin/bash -e
#
# Skript zum Runterladen eines www.mikrocontroller.net Threads inklusive aller Attachments.
# Vorraussetzungen sind wget und bash; unter Windows kann https://www.msys2.org/ verwendet werden.
#
# Version 2026-08-06
# Verbesserungen und Fragen an <udo.krebelder@gmx.at>
#
# Aufruf:
# ./uC_download.bash https://www.mikrocontroller.net/news/mikrocontroller-net-design-update-august-2026 https://www.mikrocontroller.net/topic/586551#new
#
#

accept_regex='(https://www.mikrocontroller.net/attachment/.*/.*)|(https://www.mikrocontroller.net/.*/.*page)'

for url in "$@"
do
    # remove ?page=2 or ?goto=new#new
    url2="${url%%\?*}"

    wget -e robots=off -N --no-if-modified-since -r -l3 -k -E --accept-regex "$accept_regex" "$url2" 

    #file="${url2#https://}"
    #file="${file/\?/@}"
    #true < "$file".html || { echo ERROR; }
done
