#!/bin/sh
# apt2aptproxy.sh
# A config helper script for 'apt-proxy'.
# Look through '/etc/apt/sources.list', and try to convert 'em to
# 'apt-proxy' backend server format.
#	 - Mon Mar  6 03:17:20 2006,  A. Costa

# variables: sed commands; sorta self commenting.
  SEDdelcomments='/^#.*$/d'		# delete lines beginning with '#'
SEDdelblanklines='/^ *$/d'		# delete blank or whitespace lines
SEDdelsourcetype='s/[^ ]* //'		# delete leading apt source type field
   SEDdeldistrib='s/ .*//'		# delete traling distribution and component fields
 SEDdellastslash='s/\/$//'		# chop off any trailing '/' if need be
       SEDindent='s/\(.*\)/\t\1/'	# insert a leading tab, one per line

AptSource=/etc/apt/sources.list		# where the data's coming from

APname=default	# some name for this grouping of apt servers.

MakeNoBrainerBackendList()
{
    echo
    echo "[$APname]"
    echo ";; The servers in this system's '/etc/apt/sources.list'"
    echo "backends="
    sed -e "${SEDdelcomments}"     -e "${SEDdelblanklines}"  \
        -e "${SEDdelsourcetype}"   -e "${SEDdeldistrib}"  \
        -e "${SEDdellastslash}"    -e "${SEDindent}" \
	$AptSource
    echo
    echo
}

MakeNoBrainerBackendList