blob: 5030437b7af0332a515714ac33c8adbc5b800650 [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
7MYPATH=$(dirname "${BASH_SOURCE[0]}")
8
9: ${CIPD_CLIENT_VER:=`cat $MYPATH/cipd_client_version`}
10: ${CIPD_CLIENT_SRV:='https://chrome-infra-packages.appspot.com'}
11
12UNAME=`uname -s | tr '[:upper:]' '[:lower:]'`
13case $UNAME in
14 linux)
15 PLAT=linux
16 ;;
17 cygwin*|msys*|mingw*)
18 PLAT=windows
19 ;;
20 darwin)
21 PLAT=mac
22 ;;
23 *)
24 echo "UNKNOWN OS: $UNAME"
25 exit 1
26esac
27
28UNAME=`uname -m | tr '[:upper:]' '[:lower:]'`
29case $UNAME in
30 x86_64|amd64)
31 ARCH=amd64
32 ;;
33 arm*)
34 ARCH=$UNAME
35 ;;
36 *86)
37 ARCH=386
38 ;;
39 *)
40 echo "UNKNOWN Machine architecture: $UNAME"
41 exit 1
42esac
43
44URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
45CLIENT="$MYPATH/.cipd_client"
46
47USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
48
49if [ ! -e "$CLIENT" ]; then
50 echo "Bootstrapping cipd client for ${PLAT}-${ARCH}..."
51 echo "From $URL"
52 if hash curl 2> /dev/null ; then
53 curl "$URL" -A "$USER_AGENT" -L -o "$CLIENT"
54 chmod +x "$CLIENT"
55 else
56 echo Your platform is missing the \`curl\` command. Please use your package
57 echo manager to install it before continuing.
58 echo
59 echo Alternately, manually download:
60 echo "$URL"
61 echo To $CLIENT, and then re-run this command.
62 exit 1
63 fi
64fi
65
66export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
67if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
68 echo -n "selfupdate failed: " 1>&2
69 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
70 echo "" 1>&2
71fi
72
73exec "$CLIENT" "${@}"