blob: fc8de1a9ef8e5dd7117436251847e0b3787dc221 [file] [log] [blame]
#!/bin/bash -e
# Copyright (c) 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e -o pipefail
MYPATH=$(dirname "${BASH_SOURCE[0]}")
: ${CIPD_CLIENT_VER:=`cat $MYPATH/cipd_client_version`}
: ${CIPD_CLIENT_SRV:='https://chrome-infra-packages.appspot.com'}
UNAME=`uname -s | tr '[:upper:]' '[:lower:]'`
case $UNAME in
linux)
PLAT=linux
;;
cygwin*|msys*|mingw*)
PLAT=windows
;;
darwin)
PLAT=mac
;;
*)
echo "UNKNOWN OS: $UNAME"
exit 1
esac
UNAME=`uname -m | tr '[:upper:]' '[:lower:]'`
case $UNAME in
x86_64|amd64)
ARCH=amd64
;;
arm*)
ARCH=$UNAME
;;
*86)
ARCH=386
;;
*)
echo "UNKNOWN Machine architecture: $UNAME"
exit 1
esac
URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
CLIENT="$MYPATH/.cipd_client"
USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
if [ ! -e "$CLIENT" ]; then
echo "Bootstrapping cipd client for ${PLAT}-${ARCH}..."
echo "From $URL"
if hash curl 2> /dev/null ; then
# Download the client into a temporary file, then move it into the final
# location atomically.
#
# This wonky tempdir method works on Linux and Mac.
CIPD_CLIENT_TMP=$(\
mktemp -p "$MYPATH" 2>/dev/null || \
mktemp "$MYPATH/.cipd_client.XXXXXXX")
curl "$URL" -f -A "$USER_AGENT" -L -o "$CIPD_CLIENT_TMP"
chmod +x "$CIPD_CLIENT_TMP"
set +e
mv "$CIPD_CLIENT_TMP" "$CLIENT"
set -e
else
echo Your platform is missing the \`curl\` command. Please use your package
echo manager to install it before continuing.
echo
echo Alternately, manually download:
echo "$URL"
echo To $CLIENT, and then re-run this command.
exit 1
fi
fi
export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
echo -n "selfupdate failed: " 1>&2
echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
echo "" 1>&2
fi
exec "$CLIENT" "${@}"