#
# Copyright 2013, whitestar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

############# config ##################
#
set base_path    <%= node['apt_utils']['mirror']['base_path'] %>
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     <%= node['apt_utils']['mirror']['nthreads'] %>
set _tilde <%= node['apt_utils']['mirror']['_tilde'] %>
#
############# end config ##############

<%
country = node['apt_utils']['mirror']['country']

node['apt_utils']['mirror']['distributions'].each do |name, dist|
  code_names = dist['code_names']
  architectures = dist['architectures']
  components = dist['components']

  mirror_url = nil
  case name
  when 'debian'
    mirror_url = "http://ftp.#{country}.debian.org/debian"
  when 'ubuntu'
    mirror_url = "http://#{country}.archive.ubuntu.com/ubuntu"
  end

  used_urls = []
  code_names.each do |code_name|
    # Debian backports integrated into the main archive for wheezy or later.
    normalized_mirror_url = mirror_url
    if code_name == 'squeeze-backports' then  # oldstable
      normalized_mirror_url = "http://ftp.#{country}.debian.org/debian-backports"
    end
    used_urls.push(normalized_mirror_url)

    architectures.each do |architecture|
-%>
deb-<%= architecture %> <%= normalized_mirror_url %> <%= code_name %> <%= components.join(' ') %>
<%
    end
  end

  unless code_names.empty? then
    used_urls.uniq.each do |used_url|
-%>
clean <%= used_url %>
<%
    end
  end
end
-%>

#deb http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-src http://ftp.us.debian.org/debian unstable main contrib non-free

# mirror additional architectures
#deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-amd64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-m68k http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mipsel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-s390 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free

#clean http://ftp.us.debian.org/debian
