#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## https://forums.whonix.org/t/debian-bullseye-apt-get-error-on-any/12068
## apt-get --error-on=any install
## E: Command line option --error-on=any is not understood in combination with the other options

#set -x
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace

aptgetopt_add "APT::Update::Error-Mode=any"
aptgetopt_conf_add "APT::Update::Error-Mode any;"

## {{ apt_sourcelist_empty apt_sourceparts

## Using short option -o instead of long option --option, because aptitude does
## (used by grml-debootstrap) not support that.

## The EMPTY_DIR variable is provided by the help-steps/variables script.
## export, so chroot-scripts-post.d can read it. It defaults to /tmp/empty.
## You can leave it as is.
if [ "${apt_sourcelist_empty:-}" = "" ]; then
   export apt_sourcelist_empty=" -o Dir::Etc::sourcelist=$EMPTY_DIR "
fi

## The dist_sources_list_temp_build_folder variable is provided by the 25_apt_sources.conf script.
## You can leave it as is.
if [ "${apt_sourceparts:-}" = "" ]; then
   export apt_sourceparts=" -o Dir::Etc::sourceparts=$dist_sources_list_temp_build_folder "
fi

## }}

## {{ apt performance opts

## Don't fetch Translation and Contents file.
## We don't need them and we will throw them away later anyway.
aptgetopt_add "Acquire::Languages=none"
aptgetopt_conf_add "Acquire::Languages none;"

aptgetopt_add "Acquire::IndexTargets::deb::Contents-deb::DefaultEnabled=false"
aptgetopt_conf_add "Acquire::IndexTargets::deb::Contents-deb::DefaultEnabled false;"

## }}

## {{ apt essential configuration

## --no-install-recommends
aptgetopt_add "Apt::Install-Recommends=false"
aptgetopt_conf_add "Apt::Install-Recommends false;"

## }}

## {{ apt_timeout_opts

aptgetopt_add "Acquire::Retries=5"
aptgetopt_conf_add "Acquire::Retries 5;"

## }}

## {{ unattended options

[ -n "${DEBIAN_FRONTEND:-}" ] || DEBIAN_FRONTEND="noninteractive"
[ -n "${DEBIAN_PRIORITY:-}" ] || DEBIAN_PRIORITY="critical"
[ -n "${DEBCONF_NOWARNINGS:-}" ] || DEBCONF_NOWARNINGS="yes"
[ -n "${APT_LISTCHANGES_FRONTEND:-}" ] || APT_LISTCHANGES_FRONTEND="text"
export DEBIAN_FRONTEND DEBIAN_PRIORITY DEBCONF_NOWARNINGS APT_LISTCHANGES_FRONTEND

aptgetopt_add "Dpkg::Options::=--force-confnew"
## forgetting "--" can break aptitude
## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=95043
aptgetopt_conf_add "Dpkg::Options --force-confnew;"

## }}
