#!/bin/bash
# Filename:      ${GRML_FAI_CONFIG}/scripts/GRMLBASE/33-aptsetup
# Purpose:       configure Debian package management of live-system
# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports:   see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2 or any later version.
################################################################################

set -e
set -u

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# use snapshot.debian.org based on build date for release
if ifclass RELEASE ; then
  current_date=$(date --utc -d "@${SOURCE_DATE_EPOCH}" +%Y%m%d)
  perl -pi -e 'BEGIN { $d="'"$current_date"'"; } \
    s#^(URIs:)\s+(.*://deb.debian.org/)(.*)\/?$#$1 http://snapshot.debian.org/archive/$3/$d#' \
    "${target}"/etc/apt/sources.list.d/debian.sources

  sed -i '/^Types:/a Check-Valid-Until: no' "${target}"/etc/apt/sources.list.d/debian.sources
fi

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
