From be30dcfdbb318dec5e98e21f88f38ce9cc76111f Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 25 Oct 2011 16:33:28 -0400 Subject: [PATCH 1/5] mk-sbuild: better support apt http proxy (LP: #881654) This improves the support for apt http proxy. It determines the value for 'http_proxy' by, in increasing importance: * setting in apt.conf (per apt-config) * environment variable 'http_proxy' * command line flag '--debootstrap-proxy' Then, if that is set, it makes use of it in * initial call to debootstrap (environment variable passed through sudo) * 'finish.sh' and subsequent invocation by writing config to /etc/apt/config.d/ Thus, the value here is 'sticky' after the debootstrap invocation. --- debian/changelog | 5 ++++- mk-sbuild | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index 980f1b8..d8567bf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,7 +8,10 @@ ubuntu-dev-tools (0.134) UNRELEASED; urgency=low [ Benjamin Drung ] * syncpackage: Catch user abort. - -- Benjamin Drung Sat, 22 Oct 2011 23:09:56 +0200 + [ Scott Moser ] + * mk-sbuild: better support apt http proxy (LP: #881654) + + -- Scott Moser Tue, 25 Oct 2011 16:10:00 -0400 ubuntu-dev-tools (0.133) unstable; urgency=low diff --git a/mk-sbuild b/mk-sbuild index 9f5d506..a2e7c67 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -52,6 +52,7 @@ function usage() echo " --debootstrap-mirror=URL Use URL as the debootstrap source" echo " --debootstrap-include=list Comma separated list of packages to include" echo " --debootstrap-exclude=list Comma separated list of packages to exclude" + echo " --debootstrap-proxy=URL Use PROXY as apt proxy" echo " --distro=DISTRO Install specific distro:" echo " 'ubuntu' or 'debian' " echo " (defaults to determining from release name)" @@ -70,6 +71,7 @@ function usage() echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)" echo " DEBOOTSTRAP_INCLUDE Included packages (same as --debootstrap-include)" echo " DEBOOTSTRAP_EXCLUDE Excluded packages (same as --debootstrap-exclude)" + echo " DEBOOTSTRAP_PROXY Apt proxy (same as --debootstrap-proxy)" echo " TEMPLATE_SOURCES A template for sources.list" echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza" if [ -z "$1" ]; then @@ -82,12 +84,14 @@ function usage() if [ -z "$1" ]; then usage fi -OPTS=`getopt -o 'h' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,debootstrap-include:,debootstrap-exclude:,personality:,distro:,vg:,type:" -- "$@"` +OPTS=`getopt -o 'h' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,debootstrap-include:,debootstrap-exclude:,debootstrap-proxy:,personality:,distro:,vg:,type:" -- "$@"` eval set -- "$OPTS" VG="" DISTRO="" name="" +proxy="_unset_" + while :; do case "$1" in --debug) @@ -134,6 +138,10 @@ while :; do DEBOOTSTRAP_EXCLUDE="$2" shift 2 ;; + --debootstrap-proxy) + proxy="$2" + shift 2 + ;; --distro) DISTRO="$2" shift 2 @@ -450,6 +458,15 @@ if [ -n "$DEBOOTSTRAP_EXCLUDE" ] ; then debootstrap_opts="$debootstrap_opts --exclude=$DEBOOTSTRAP_EXCLUDE" fi +# if http_proxy is set in the environment (even empty) set 'proxy' to it +[ "$proxy" = "_unset_" -a "${http_proxy-xx}" = "xx" ] && proxy=${http_proxy} +if [ "$proxy" = "_unset_" ]; then + _out=$(apt-config shell x Acquire::HTTP::Proxy) && + _out=$(sh -c 'eval $1 && echo $x' -- "$_out") && [ -n "$_out" ] && + proxy="$_out" +fi +[ "$proxy" = "_unset_" ] && proxy="" + DEBOOTSTRAP_COMMAND=debootstrap # Use qemu-kvm-extras-static for foreign chroots if [ "$CHROOT_ARCH" != "$HOST_ARCH" ] ; then @@ -501,7 +518,7 @@ esac sudo mkdir -p -m 0700 "$MNT"/root/.gnupg # debootstrap the chroot -sudo "$DEBOOTSTRAP_COMMAND" --arch="$CHROOT_ARCH" $variant_opt $debootstrap_opts "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" +sudo ${proxy:+"http_proxy=${proxy}"} "$DEBOOTSTRAP_COMMAND" --arch="$CHROOT_ARCH" $variant_opt $debootstrap_opts "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" # Update the package sources TEMP_SOURCES=`mktemp -t sources-XXXXXX` @@ -629,7 +646,13 @@ sudo bash -c "cat >> $MNT/finish.sh" < /etc/apt/apt.conf.d/99mk-sbuild-proxy < Date: Tue, 25 Oct 2011 17:08:29 -0400 Subject: [PATCH 2/5] remove specification of 'Retries' in apt config. --- mk-sbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk-sbuild b/mk-sbuild index a2e7c67..90e7f3e 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -650,7 +650,7 @@ if [ -n "$proxy" ]; then mkdir -p /etc/apt/apt.conf.d/ cat > /etc/apt/apt.conf.d/99mk-sbuild-proxy < Date: Tue, 25 Oct 2011 19:19:59 -0400 Subject: [PATCH 3/5] add back the accidently removed 'rm /finish.sh' --- mk-sbuild | 1 + 1 file changed, 1 insertion(+) diff --git a/mk-sbuild b/mk-sbuild index 90e7f3e..df2e9e5 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -669,6 +669,7 @@ if [ ! -r /dev/stdin ]; then ln -s /proc/self/fd/0 /dev/stdin; fi if [ ! -r /dev/stdout ]; then ln -s /proc/self/fd/1 /dev/stdout; fi if [ ! -r /dev/stderr ]; then ln -s /proc/self/fd/2 /dev/stderr; fi # Clean up +rm /finish.sh apt-get clean EOM sudo chmod a+x "$MNT"/finish.sh From 56220bdd23b79d2e8c94ee95115d03f4507c7ce0 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 25 Oct 2011 19:25:09 -0400 Subject: [PATCH 4/5] respect DEBOOTSTRAP_PROXY if set in environment or config file DEBOOTSTRAP_PROXY takes precedence over the larger scoped environment variable 'http_proxy'. --- mk-sbuild | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mk-sbuild b/mk-sbuild index df2e9e5..56a5646 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -459,6 +459,8 @@ if [ -n "$DEBOOTSTRAP_EXCLUDE" ] ; then fi # if http_proxy is set in the environment (even empty) set 'proxy' to it +[ "$proxy" = "_unset_" -a "${DEBOOTSTRAP_PROXY-xx}" = "xx" ] && + proxy=${DEBOOTSTRAP_PROXY} [ "$proxy" = "_unset_" -a "${http_proxy-xx}" = "xx" ] && proxy=${http_proxy} if [ "$proxy" = "_unset_" ]; then _out=$(apt-config shell x Acquire::HTTP::Proxy) && From 41319d506940ae021594173b1070d242baa1293a Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 25 Oct 2011 19:26:16 -0400 Subject: [PATCH 5/5] white space cleanup --- mk-sbuild | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mk-sbuild b/mk-sbuild index 56a5646..46f37d5 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -463,9 +463,9 @@ fi proxy=${DEBOOTSTRAP_PROXY} [ "$proxy" = "_unset_" -a "${http_proxy-xx}" = "xx" ] && proxy=${http_proxy} if [ "$proxy" = "_unset_" ]; then - _out=$(apt-config shell x Acquire::HTTP::Proxy) && - _out=$(sh -c 'eval $1 && echo $x' -- "$_out") && [ -n "$_out" ] && - proxy="$_out" + _out=$(apt-config shell x Acquire::HTTP::Proxy) && + _out=$(sh -c 'eval $1 && echo $x' -- "$_out") && [ -n "$_out" ] && + proxy="$_out" fi [ "$proxy" = "_unset_" ] && proxy=""