blob: b141ac128c52fda460d36e7f816508099b00605b [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
Dan Jacqueseb1feb92017-07-28 13:04:28 +020052 echo "Bootstrapping cipd client for ${PLAT}-${ARCH} from ${URL}..."
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000053
54 # Download the client into a temporary file, then move it into the final
55 # location atomically.
56 #
57 # This wonky tempdir method works on Linux and Mac.
58 CIPD_CLIENT_TMP=$(\
59 mktemp -p "$MYPATH" 2>/dev/null || \
60 mktemp "$MYPATH/.cipd_client.XXXXXXX")
61
Robert Iannucci2188fe92016-12-02 11:15:57 -080062 if hash curl 2> /dev/null ; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020063 curl "$URL" -s --show-error -f -A "$USER_AGENT" -L -o "$CIPD_CLIENT_TMP"
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000064 elif hash wget 2> /dev/null ; then
65 wget "$URL" -q -U "${USER_AGENT}" -O "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080066 else
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000067 echo Your platform is missing a supported fetch command. Please use your package
68 echo manager to install one before continuing:
69 echo
70 echo curl
71 echo wget
Robert Iannucci2188fe92016-12-02 11:15:57 -080072 echo
73 echo Alternately, manually download:
74 echo "$URL"
75 echo To $CLIENT, and then re-run this command.
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000076 rm "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080077 exit 1
78 fi
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000079
80 chmod +x "$CIPD_CLIENT_TMP"
81
82 set +e
83 mv "$CIPD_CLIENT_TMP" "$CLIENT"
84 set -e
Robert Iannucci2188fe92016-12-02 11:15:57 -080085fi
86
87export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
Daniel Jacques9f9d82a2017-07-27 14:21:21 +000088if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
Robert Iannucci2188fe92016-12-02 11:15:57 -080089 echo -n "selfupdate failed: " 1>&2
90 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
91 echo "" 1>&2
92fi
93
94exec "$CLIENT" "${@}"