#!/bin/sh # Outputs APT configuration data set -e self="$(basename "$0")" # TODO # - currently only handles a single --suite or --profile; allow multiple ones? # - nicer error messages # - default output when neither --suite nor --profile is set? # - support getting/setting --archive? # - support setting --mirror-map (for --profile) # - Debian security entries? log() { echo "$@" >&2 } usage() { log "$self [--with-sources=[yes|no|disabled]] [--arch=] [--components=,] [--mirror=] [--suite=] [--pockets=,]" >&2 log "$self [--with-sources=[yes|no|disabled]] [--arch=] [--components=,] [--profile=]" >&2 } die() { log "$@" exit 1 } guess_dist_arch_archive() { local dist="$1" local arch="$2" case "$dist" in etch|lenny|squeeze|sid|testing|unstable|experimental) echo "debian" ;; hardy|intrepid|jaunty|karmic|lucid) case "$arch" in amd64|i386) echo "ubuntu" ;; armel|hppa|ia64|lpia|powerpc|sparc) echo "ubuntu-ports" ;; *) die "Unknown Ubuntu archive for arch=$arch" ;; esac ;; *) die "Unknown archive for dist=$dist" ;; esac } get_archive_url() { local archive="$1" case "$archive" in backports.org) echo "http://www.backports.org/backports.org/" ;; debian) echo "http://ftp.us.debian.org/debian/" ;; ubuntu) echo "http://archive.ubuntu.com/ubuntu/" ;; ubuntu-ports) echo "http://ports.ubuntu.com/ubuntu-ports/" ;; volatile) echo "http://volatile.debian.org/debian-volatile/" ;; *) die "Unknown mirror for archive=$archive" ;; esac } output_sources() { local with_sources="$1" local mirror="$2" local dist="$3" local components="$4" case "$with_sources" in yes) echo "deb $mirror $dist $components" echo "deb-src $mirror $dist $components" ;; disabled) echo "deb $mirror $dist $components" echo "#deb-src $mirror $dist $components" ;; no) echo "deb $mirror $dist $components" ;; *) die 'with_sources must be either "yes", "disabled", or "no"' ;; esac } getopt_output="`getopt -o "" -l with-sources::,arch:,components:,mirror:,suite:,pockets:,profile: -n "$self" -s sh -- "$@"`" eval set -- "$getopt_output" with_sources="disabled" arch="`dpkg --print-architecture`" components="main" mirror="" suite="" pockets="" archive="" profile="" while :; do case "$1" in --with-sources) case "$2" in "") with_sources="yes" ;; yes|no|disabled) with_sources="$2" ;; *) die '--with-sources must be either "yes", "disabled", or "no"' ;; esac shift 2 ;; --arch) arch="$2" shift 2 ;; --components) components="$2" shift 2 ;; --mirror) mirror="$2" shift 2 ;; --suite) if [ -z "$2" ]; then die "Need a suite for --suite" fi if [ -n "$profile" ]; then die "Can't set --suite after --profile" fi suite="$2" shift 2 ;; --pockets) pockets="$2" shift 2 ;; --archive) archive="$2" shift 2 ;; --profile) if [ -z "$2" ]; then die "Need a profile for --profile" fi if [ -n "$suite" ]; then die "Can't set --profile after --suite" fi profile="$2" shift 2 ;; --) shift break ;; *) die "Unhandled arg=$1" ;; esac done case $# in 0) command="sources" ;; 1) command="$1" ;; 2) usage exit 1 ;; esac if [ -z "$suite" ] && [ -z "$profile" ]; then die "Please pass --suite or --profile" fi components="$(echo "$components" | tr , " ")" pockets="$(echo "$pockets" | tr , " ")" if [ -n "$profile" ]; then base_dist="${profile%%/*}" base_dist="${base_dist%%-*}" base_archive="`guess_dist_arch_archive "$base_dist" "$arch"`" base_mirror="`get_archive_url "$base_archive"`" case "$base_archive" in debian) case "$profile" in experimental) base_dist="unstable" output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" output_sources "$with_sources" "$base_mirror" "$profile" "$components" ;; */volatile|*/volatile-sloppy) if [ "$base_dist" != "${profile%%/*}" ]; then die "Unknown Volatile based profile=$profile" fi archive="volatile" mirror="`get_archive_url "$archive"`" volatile_dist=${profile%%-*} output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" output_sources "$with_sources" "$mirror" "$volatile_dist" "$components" if [ "$volatile_dist" != "$profile" ]; then output_sources "$with_sources" "$mirror" "$profile" "$components" fi ;; *-backports) if [ "$base_dist" != "${profile%%-*}" ]; then die "Unknown Backports.org based profile=$profile" fi archive="backports.org" mirror="`get_archive_url "$archive"`" output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" output_sources "$with_sources" "$mirror" "$profile" "$components" ;; *-proposed-updates) if [ "$base_dist" != "${profile%%-*}" ]; then die "Unknown Debian updates based profile=$profile" fi output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" output_sources "$with_sources" "$base_mirror" "$profile" "$components" ;; *) if [ "$base_dist" != "$profile" ]; then die "Unknown Debian based profile=$profile" fi output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" ;; esac ;; ubuntu) if [ "$base_dist" != "${profile%%-*}" ]; then die "Unknown Ubuntu based profile=$profile" fi pockets="" case "$profile" in *-security) pockets="security" ;; *-updates) pockets="security updates" ;; *-backports) pockets="security updates backports" ;; *-proposed) pockets="security updates proposed" ;; *) if [ "$base_dist" != "$profile" ]; then die "Unknown Ubuntu pocket based profile=$profile" fi ;; esac output_sources "$with_sources" "$base_mirror" "$base_dist" "$components" for pocket in $pockets; do output_sources "$with_sources" "$base_mirror" "$base_dist-$pocket" "$components" done ;; *) die "Unknown profile for base_archive=$base_archive" ;; esac exit 0 fi if [ -n "$suite" ]; then if [ -z "$mirror" ]; then if [ -z "$archive" ]; then archive="`guess_dist_arch_archive "$suite" "$arch"`" fi mirror="`get_archive_url "$archive"`" fi output_sources "$with_sources" "$mirror" "$suite" "$components" for pocket in $pockets; do output_sources "$with_sources" "$mirror" "$suite-$pocket" "$components" done exit 0 fi