#!/bin/bash
# -*-mode: sh; tab-width: 8; coding: utf-8-unix -*-

ROLE=testforge
TXT=/usr/local/sbin/gentoo_link_to_cache.txt

# replace /usr/net/Http/Makefile
[ "$#" -gt 0 ] && cd $1 || cd /usr/net/Http
[ -z "$DISTFILES" ] && DISTFILES=../../portage/distfiles

find -L $DISTFILES/ -type l -delete

find */ prdownloads.sourceforge.net/*/ github.com/*/ -type f -o -type l -name \*.\* | \
    grep -v ' \|\.[a-z]\|/archive/\|/tarball/' \
    | grep -v 'htm$\|html$\|txt$\|Makefile$\|\.py$\|~$' \
    | while read file ; do
      base=`basename $file`
      [ -h  ${DISTFILES}/"$base" ] && continue
      from=$(readlink ../../net/Http/"$file")
      [ -z "$from" ] && from=../../net/Http/"$file"
      ln -s $from ${DISTFILES}/"$base"
done

# golang/net/archive/8d16fa6dc9a8.tar.gz
#    burpsuite_community_v2020.9.1.jar portswigger.net/burp/releases/download@product=community&version=2020.9.1
    # burpsuite_community_v2020.4.jar mirror.leaseweb.com/gentoo/distfiles/0f/burpsuite_community_v2020.4.jar
    # burpsuite_community_v2020.4.jar portswigger.net/burp/releases/download@product=community&version=2020.4
    # burpsuite_community_v2020.4.1.jar portswigger.net/burp/releases/download@product=community&version=2020.4.1

grep -v '^#' $TXT | while read base file ; do
    if [ -z "$base" ] ; then
	continue
    fi
    if [ -z "$file" ] ; then
	echo ERROR: empty target for $base && continue
    fi

    rm -f "${DISTFILES}/$base"
    ln -s ../../net/Http/"$file" ${DISTFILES}/"$base"
    [ -e /i/net/Http/distfiles.gentoo.org/distfiles/"$base" ] || \
      ln -s /i/net/Http/"$file" /i/net/Http/distfiles.gentoo.org/distfiles/"$base"
    base=""
  done
exit 0
# RfCatDonsCCBootloader-1.9.2.hex atlas0fd00m/rfcat/releases/download/v1.9.2/RfCatDonsCCBootloader.hex
