mk-sbuild: better support apt http proxy (LP: #881654)

This commit is contained in:
Stefano Rivera 2011-10-26 20:11:44 +02:00
commit 2ad6ec42dd
2 changed files with 33 additions and 5 deletions

5
debian/changelog vendored
View File

@ -8,7 +8,10 @@ ubuntu-dev-tools (0.134) UNRELEASED; urgency=low
[ Benjamin Drung ] [ Benjamin Drung ]
* syncpackage: Catch user abort. * syncpackage: Catch user abort.
-- Benjamin Drung <bdrung@debian.org> Sat, 22 Oct 2011 23:09:56 +0200 [ Scott Moser ]
* mk-sbuild: better support apt http proxy (LP: #881654)
-- Scott Moser <smoser@brickies.net> Tue, 25 Oct 2011 16:10:00 -0400
ubuntu-dev-tools (0.133) unstable; urgency=low ubuntu-dev-tools (0.133) unstable; urgency=low

View File

@ -52,6 +52,7 @@ function usage()
echo " --debootstrap-mirror=URL Use URL as the debootstrap source" echo " --debootstrap-mirror=URL Use URL as the debootstrap source"
echo " --debootstrap-include=list Comma separated list of packages to include" echo " --debootstrap-include=list Comma separated list of packages to include"
echo " --debootstrap-exclude=list Comma separated list of packages to exclude" 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 " --distro=DISTRO Install specific distro:"
echo " 'ubuntu' or 'debian' " echo " 'ubuntu' or 'debian' "
echo " (defaults to determining from release name)" echo " (defaults to determining from release name)"
@ -70,6 +71,7 @@ function usage()
echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)" echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)"
echo " DEBOOTSTRAP_INCLUDE Included packages (same as --debootstrap-include)" echo " DEBOOTSTRAP_INCLUDE Included packages (same as --debootstrap-include)"
echo " DEBOOTSTRAP_EXCLUDE Excluded packages (same as --debootstrap-exclude)" 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_SOURCES A template for sources.list"
echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza" echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza"
if [ -z "$1" ]; then if [ -z "$1" ]; then
@ -82,12 +84,14 @@ function usage()
if [ -z "$1" ]; then if [ -z "$1" ]; then
usage usage
fi 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" eval set -- "$OPTS"
VG="" VG=""
DISTRO="" DISTRO=""
name="" name=""
proxy="_unset_"
while :; do while :; do
case "$1" in case "$1" in
--debug) --debug)
@ -134,6 +138,10 @@ while :; do
DEBOOTSTRAP_EXCLUDE="$2" DEBOOTSTRAP_EXCLUDE="$2"
shift 2 shift 2
;; ;;
--debootstrap-proxy)
proxy="$2"
shift 2
;;
--distro) --distro)
DISTRO="$2" DISTRO="$2"
shift 2 shift 2
@ -450,6 +458,17 @@ if [ -n "$DEBOOTSTRAP_EXCLUDE" ] ; then
debootstrap_opts="$debootstrap_opts --exclude=$DEBOOTSTRAP_EXCLUDE" debootstrap_opts="$debootstrap_opts --exclude=$DEBOOTSTRAP_EXCLUDE"
fi 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) &&
_out=$(sh -c 'eval $1 && echo $x' -- "$_out") && [ -n "$_out" ] &&
proxy="$_out"
fi
[ "$proxy" = "_unset_" ] && proxy=""
DEBOOTSTRAP_COMMAND=debootstrap DEBOOTSTRAP_COMMAND=debootstrap
# Use qemu-kvm-extras-static for foreign chroots # Use qemu-kvm-extras-static for foreign chroots
if [ "$CHROOT_ARCH" != "$HOST_ARCH" ] ; then if [ "$CHROOT_ARCH" != "$HOST_ARCH" ] ; then
@ -501,7 +520,7 @@ esac
sudo mkdir -p -m 0700 "$MNT"/root/.gnupg sudo mkdir -p -m 0700 "$MNT"/root/.gnupg
# debootstrap the chroot # 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 # Update the package sources
TEMP_SOURCES=`mktemp -t sources-XXXXXX` TEMP_SOURCES=`mktemp -t sources-XXXXXX`
@ -629,7 +648,13 @@ sudo bash -c "cat >> $MNT/finish.sh" <<EOM
#!/bin/bash #!/bin/bash
#set -x #set -x
set -e set -e
export http_proxy=${http_proxy} if [ -n "$proxy" ]; then
mkdir -p /etc/apt/apt.conf.d/
cat > /etc/apt/apt.conf.d/99mk-sbuild-proxy <<EOF
## proxy settings copied from mk-sbuild
Acquire { HTTP { Proxy "$proxy"; }; };
EOF
fi
# Reload package lists # Reload package lists
apt-get update || true apt-get update || true
# Pull down signature requirements # Pull down signature requirements
@ -646,8 +671,8 @@ 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/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 if [ ! -r /dev/stderr ]; then ln -s /proc/self/fd/2 /dev/stderr; fi
# Clean up # Clean up
apt-get clean
rm /finish.sh rm /finish.sh
apt-get clean
EOM EOM
sudo chmod a+x "$MNT"/finish.sh sudo chmod a+x "$MNT"/finish.sh