[go: nahoru, domu]

Skip to content

Commit

Permalink
Add support for specifying proxies with -P.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnschneid committed Apr 13, 2013
1 parent 7b5d363 commit ff03e84
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
14 changes: 12 additions & 2 deletions installer/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MIRROR86='http://archive.ubuntu.com/ubuntu/'
MIRRORARM='http://ports.ubuntu.com/ubuntu-ports/'
NAME=''
PREFIX='/usr/local'
PROXY='unspecified'
RELEASE='precise'
TARBALL=''
TARGETS=''
Expand Down Expand Up @@ -55,6 +56,8 @@ Options:
-n NAME Name of the chroot. Default is the release name.
-p PREFIX The root directory in which to install the bin and chroot
subdirectories and data. Default: $PREFIX
-P PROXY Set an HTTP proxy for the chroot; effectively sets http_proxy.
Specify an empty string to remove a proxy when updating.
-r RELEASE Name of the distribution release. Default: $RELEASE
-t TARGETS Comma-separated list of environment targets to install.
Specify help to print out potential targets.
Expand All @@ -79,7 +82,7 @@ error() {
}

# Process arguments
while getopts 'a:def:k:m:n:p:r:s:t:T:uV' f; do
while getopts 'a:def:k:m:n:p:P:r:s:t:T:uV' f; do
case "$f" in
a) ARCH="$OPTARG";;
d) DOWNLOADONLY='y';;
Expand All @@ -89,6 +92,7 @@ while getopts 'a:def:k:m:n:p:r:s:t:T:uV' f; do
m) MIRROR="$OPTARG";;
n) NAME="$OPTARG";;
p) PREFIX="`readlink -f "$OPTARG"`";;
P) PROXY="$OPTARG";;
r) RELEASE="$OPTARG";;
t) TARGETS="$TARGETS${TARGETS:+","}$OPTARG";;
T) TARGETFILE="$OPTARG";;
Expand Down Expand Up @@ -198,6 +202,11 @@ if [ -z "$DOWNLOADONLY" -a -n "$TARBALL" ]; then
fi
fi

# Set http_proxy if a proxy is specified.
if [ ! "$PROXY" = 'unspecified' ]; then
export http_proxy="$PROXY" https_proxy="$PROXY" ftp_proxy="$PROXY"
fi

# Done with parameter processing!
# Make sure we always have echo when this script exits
TRAP="stty echo 2>/dev/null || true; $TRAP"
Expand Down Expand Up @@ -326,7 +335,8 @@ mkdir -p "$CHROOT/usr/local/bin" "$CHROOT/etc/crouton"

# Create the setup script inside the chroot
echo 'Preparing chroot environment...' 1>&2
VAREXPAND="s #ARCH $ARCH ;s #MIRROR $MIRROR ;s #RELEASE $RELEASE ;s #VERSION $VERSION ;"
VAREXPAND="s #ARCH $ARCH ;s #MIRROR $MIRROR ;s #RELEASE $RELEASE ;"
VAREXPAND="${VAREXPAND}s #PROXY $PROXY ;s #VERSION $VERSION ;"
sed -e "$VAREXPAND" "$INSTALLERDIR/prepare.sh" > "$CHROOT/prepare.sh"
# Create a file for target deduplication
TARGETDEDUPFILE="`mktemp --tmpdir=/tmp "$APPLICATION.XXX"`"
Expand Down
10 changes: 8 additions & 2 deletions installer/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Usage: prepare.sh arch mirror release version
# Usage: prepare.sh arch mirror release proxy version
ARCH="${1:-"#ARCH"}"
MIRROR="${2:-"#MIRROR"}"
RELEASE="${3:-"#RELEASE"}"
VERSION="${4:-"#VERSION"}"
PROXY="${4:-"#PROXY"}"
VERSION="${5:-"#VERSION"}"

# noauto: For the specified packages, echos out "pkg-" for each package in the
# list that isn't already installed. Targets use this to avoid installing
Expand Down Expand Up @@ -47,6 +48,11 @@ compile() {
# We need all paths to do administrative things
export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'

# Apply the proxy for this script
if [ ! "$PROXY" = 'unspecified' -a "${PROXY#"#"}" = "$PROXY" ]; then
export http_proxy="$PROXY" https_proxy="$PROXY" ftp_proxy="$PROXY"
fi

# Run debootstrap second stage if it hasn't already happened
if [ -r /debootstrap ]; then
# Debootstrap doesn't like anything mounted under /sys or /var when it runs
Expand Down
37 changes: 37 additions & 0 deletions targets/core
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,48 @@ CHROOTBIN='brightness croutonversion host-dbus'
. "${TARGETSDIR:="$PWD"}/common"

### Append to prepare.sh:
echo 'Preparing environment...' 1>&2
if [ ! "$VERSION" = '#VERSION' ]; then
sed -i "s ^VERSION=.*\$ VERSION='$VERSION' " '/usr/local/bin/croutonversion'
fi

# Create the new environment file
oldenv='/etc/environment'
newenv='/etc/environment.new'
{
echo '### begin crouton-generated environment variables'
if [ "$PROXY" = 'unspecified' -o "$PROXY" = '#PROXY' ]; then
grep -i '^[a-z]*_proxy' "$oldenv" 2>/dev/null || true
elif [ -n "$PROXY" ]; then
for var in http_proxy HTTP_PROXY https_proxy HTTPS_PROXY \
ftp_proxy FTP_PROXY; do
echo "$var='$PROXY'"
done
for var in no_proxy NO_PROXY; do
echo "$var='localhost,127.0.0.1'"
done
fi
echo '### end crouton-generated environment variables'
# Copy in previous user-environment settings
if [ -r "$oldenv" ]; then
awk '/^### begin/{x=1}!x;/^### end/{x=0}' "$oldenv"
fi
} > "$newenv"
mv -f "$newenv" "$oldenv"

echo 'Preparing software sources...' 1>&2
if [ ! "$PROXY" = 'unspecified' -a ! "$PROXY" = '#PROXY' ]; then
aptproxy='/etc/apt/apt.conf.d/80croutonproxy'
if [ -z "$PROXY" ]; then
rm -f "$aptproxy"
else
cat > "$aptproxy" <<EOF
Acquire::http::proxy "$PROXY";
Acquire::ftp::proxy "$PROXY";
Acquire::https::proxy "$PROXY";
EOF
fi
fi
cat > /etc/apt/sources.list <<EOF
deb $MIRROR $RELEASE main restricted universe multiverse
deb-src $MIRROR $RELEASE main restricted universe multiverse
Expand Down

0 comments on commit ff03e84

Please sign in to comment.