blob: b299157891fc19efed365d97e067fe45fdf635d9 [file] [log] [blame]
Robert Iannucci2188fe92016-12-02 11:15:57 -08001#!/bin/bash -e
2
3# Copyright (c) 2016 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Dan Jacquese82c0de2017-07-05 18:10:23 -07007set -e -o pipefail
8
Robert Iannucci2188fe92016-12-02 11:15:57 -08009MYPATH=$(dirname "${BASH_SOURCE[0]}")
10
11: ${CIPD_CLIENT_VER:=`cat $MYPATH/cipd_client_version`}
12: ${CIPD_CLIENT_SRV:='https://chrome-infra-packages.appspot.com'}
13
14UNAME=`uname -s | tr '[:upper:]' '[:lower:]'`
15case $UNAME in
16 linux)
17 PLAT=linux
18 ;;
19 cygwin*|msys*|mingw*)
20 PLAT=windows
21 ;;
22 darwin)
23 PLAT=mac
24 ;;
25 *)
26 echo "UNKNOWN OS: $UNAME"
27 exit 1
28esac
29
30UNAME=`uname -m | tr '[:upper:]' '[:lower:]'`
31case $UNAME in
32 x86_64|amd64)
33 ARCH=amd64
34 ;;
35 arm*)
36 ARCH=$UNAME
37 ;;
38 *86)
39 ARCH=386
40 ;;
41 *)
42 echo "UNKNOWN Machine architecture: $UNAME"
43 exit 1
44esac
45
46URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
47CLIENT="$MYPATH/.cipd_client"
48
49USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
50
51if [ ! -e "$CLIENT" ]; then
52 echo "Bootstrapping cipd client for ${PLAT}-${ARCH}..."
53 echo "From $URL"
54 if hash curl 2> /dev/null ; then
Dan Jacquese82c0de2017-07-05 18:10:23 -070055 curl "$URL" -f -A "$USER_AGENT" -L -o "$CLIENT"
Robert Iannucci2188fe92016-12-02 11:15:57 -080056 chmod +x "$CLIENT"
57 else
58 echo Your platform is missing the \`curl\` command. Please use your package
59 echo manager to install it before continuing.
60 echo
61 echo Alternately, manually download:
62 echo "$URL"
63 echo To $CLIENT, and then re-run this command.
64 exit 1
65 fi
66fi
67
68export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
69if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
70 echo -n "selfupdate failed: " 1>&2
71 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
72 echo "" 1>&2
73fi
74
75exec "$CLIENT" "${@}"