Philip Hands wrote:

> BTW I note that in the original (and therefore in this too) that the
> exclusion of cdrom: and the 'deb file' to 'deb copy' bits only work if
> there's no [option] bit in the line -- was that an oversight?

I would guess so, yes.

In light of that (and whilst my shell is a little rusty) but how about
we just make this all more explicit instead of abusing sed/awk?

For example:

get_mirrors () {
        local file
        local line
        for file in $@; do
                while read line
                do
                        if ! echo "$line" | grep -qs '^deb[[:space:]]'; then
                                continue
                        fi

                        local options=
                        local uri="$(echo "$line" | cut -d' ' -f2)"
                        local dist="$(echo "$line" | cut -d' ' -f3)"
                        local components="$(echo "$line" | cut -d' ' -f4-)"

                        case "$uri" in
                        \[*)
                                options="$uri "
                                uri="$(echo "$line" | cut -d' ' -f3)"
                                dist="$(echo "$line" | cut -d' ' -f4)"
                                components="$(echo "$line" | cut -d' ' -f5-)"
                                ;;
                        esac

                        case "$uri" in
                        cdrom:*|*security.debian.org*|*volatile.debian.*)
                                continue
                                ;;
                        file:*)
                                uri="$(echo "${uri}" | sed 's,^file,copy,')"
                                ;;
                        esac

                        echo "deb ${options}${uri} ${dist} ${components}"
                done < $file
        done    
}


Best wishes,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      [email protected] 🍥 chris-lamb.co.uk
       `-

Reply via email to