#!/bin/sh
# -*-mode: sh; tab-width: 8; coding: utf-8-unix -*-
# filter or .uris

ROLE=base
[ -z "$CACHE" ] && CACHE=/mnt/o/Cache/Apt/Debian/10.6
[ -d "$CACHE" ] || mkdir $CACHE # || exit 1$?

# debian --print-uris
if [ $? -eq 0 ] ; then
    # filter
grep 'https*://' | \
  sed -e 's@ftp://[^ ]*@@g'  -e 's@.*https*://@https://@g' -e "s@'.*@@g" | \
  while read line ; do
    for url in $line ; do
        base=`basename "$url"`
        pre=`sed -e "s@https*://@${CACHE}@" <<< $url`
        [ -e $pre ] && break
        echo $line
        break
      done
  done
  fi
for elt in "$@" ; do
    base=$( basename $elt .elts )
    [ -s $base.urls ] && continue
    sh $0 < $elt  > $base.urls
    [ -s  $base.urls ] || rm  $base.urls
  done

exit 0
