sublimino
6/15/2016 - 3:06 PM

update-debian-to-testing.sh

update-debian-to-testing.sh

#!/bin/bash

set -euo pipefail

OUTFILE=/tmp/fastest-sources.list
ARCHITECTURES=$(printf "$(
  dpkg --print-architecture
  dpkg --print-foreign-architectures
)")
NS_ARCH_OPTIONS=$(echo "${ARCHITECTURES}" | sed -E 's#(.*)#--arch \1#' | tr '\n' ' ')

cp -a /etc/apt/sources.list ~/sources.list.bak

sudo apt install apt-listbugs apt-listchanges netselect-apt -t testing

sudo netselect-apt testing ${NS_ARCH_OPTIONS} --outfile "${OUTFILE}" --nonfree --sources
SOURCES=$(sed -E '/^#|^$/d' "${OUTFILE}")

(
  for REPO in testing unstable; do
    echo "${SOURCES}" | sed "s#testing#${REPO}#" | sed -E "s/^(deb(-src)?)/\1 [arch=$(printf "${ARCHITECTURES}" | tr '\n' ',')]/"
    echo
  done
  echo "deb http://security.debian.org/ testing/updates main contrib non-free"
  echo "deb-src http://security.debian.org/ testing/updates main contrib non-free"
) | sudo tee /etc/apt/sources.list