#!/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 --vendor? # - support setting --mirror-map (for --profile) # - list Ubuntu security pocket? 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_vendor() { local dist="$1" case "$dist" in etch|lenny|squeeze|sid|testing|unstable|experimental) echo "debian" ;; hardy|intrepid|jaunty|karmic|lucid) echo "ubuntu" ;; *) die "Unknown vendor for dist=$dist" ;; esac } guess_vendor_arch_mirror() { local vendor="$1" local arch="$2" case "$vendor" in backports.org) echo "http://www.backports.org/backports.org/" ;; debian) echo "http://ftp.us.debian.org/debian/" ;; ubuntu) case "$arch" in amd64|i386) echo "http://archive.ubuntu.com/ubuntu/" ;; armel|hppa|ia64|lpia|powerpc|sparc) echo "http://ports.ubuntu.com/ubuntu-ports/" ;; *) die "Unknown mirror for Ubuntu and arch=$arch" ;; esac ;; volatile) echo "http://volatile.debian.org/debian-volatile/" ;; *) die "Unknown mirror for vendor=$vendor" ;; 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="" vendor="" 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 ;; --vendor) vendor="$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_vendor="`guess_dist_vendor "$base_dist"`" base_mirror="`guess_vendor_arch_mirror "$base_vendor" "$arch"`" case "$base_vendor" 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 vendor="volatile" mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`" 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 vendor="backports.org" mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`" 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) case "$profile" in *-backports) pockets="updates backports" ;; *-proposed) pockets="updates proposed" ;; *-updates|*-security) pockets="updates" ;; *) if [ "$base_dist" != "$profile" ]; then die "Unknown Ubuntu 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_vendor=$base_vendor" ;; esac exit 0 fi if [ -n "$suite" ]; then if [ -z "$mirror" ]; then if [ -z "$vendor" ]; then vendor="`guess_dist_vendor "$suite"`" fi mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`" fi output_sources "$with_sources" "$mirror" "$suite" "$components" exit 0 fi