blob: 581b4b0bac7b7b16ef90ed95872be0b3668fa844 [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 ;;
Robert Iannucciff2bf092017-09-11 16:27:26 -070035 s390x) # best-effort support for IBM s390x: crbug.com/764087
36 ARCH=s390x
37 ;;
Dan Jacques63421282017-10-16 15:05:59 -040038 ppc64) # best-effort support for 64-bit PowerPC: crbug.com/773857
39 ARCH=ppc64
40 ;;
Dan Jacques1e0b7a52017-10-17 11:19:18 -040041 ppc64le) # best-effort support for 64-bit PowerPC/LE: crbug.com/773857
Dan Jacques63421282017-10-16 15:05:59 -040042 ARCH=ppc64le
43 ;;
William Hesse6fd24842017-10-10 13:55:22 +020044 aarch64)
45 ARCH=arm64
46 ;;
Benjamin Pastenee346e412017-10-20 12:57:43 -070047 armv7l)
48 ARCH=armv6l
49 ;;
Robert Iannucci2188fe92016-12-02 11:15:57 -080050 arm*)
51 ARCH=$UNAME
52 ;;
53 *86)
54 ARCH=386
55 ;;
56 *)
57 echo "UNKNOWN Machine architecture: $UNAME"
58 exit 1
59esac
60
61URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
62CLIENT="$MYPATH/.cipd_client"
63
64USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
65
66if [ ! -e "$CLIENT" ]; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020067 echo "Bootstrapping cipd client for ${PLAT}-${ARCH} from ${URL}..."
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000068
69 # Download the client into a temporary file, then move it into the final
70 # location atomically.
71 #
72 # This wonky tempdir method works on Linux and Mac.
73 CIPD_CLIENT_TMP=$(\
74 mktemp -p "$MYPATH" 2>/dev/null || \
75 mktemp "$MYPATH/.cipd_client.XXXXXXX")
76
Robert Iannucci2188fe92016-12-02 11:15:57 -080077 if hash curl 2> /dev/null ; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020078 curl "$URL" -s --show-error -f -A "$USER_AGENT" -L -o "$CIPD_CLIENT_TMP"
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000079 elif hash wget 2> /dev/null ; then
80 wget "$URL" -q -U "${USER_AGENT}" -O "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080081 else
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000082 echo Your platform is missing a supported fetch command. Please use your package
83 echo manager to install one before continuing:
84 echo
85 echo curl
86 echo wget
Robert Iannucci2188fe92016-12-02 11:15:57 -080087 echo
88 echo Alternately, manually download:
89 echo "$URL"
90 echo To $CLIENT, and then re-run this command.
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000091 rm "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080092 exit 1
93 fi
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000094
95 chmod +x "$CIPD_CLIENT_TMP"
96
97 set +e
98 mv "$CIPD_CLIENT_TMP" "$CLIENT"
99 set -e
Robert Iannucci2188fe92016-12-02 11:15:57 -0800100fi
101
102export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
Daniel Jacques9f9d82a2017-07-27 14:21:21 +0000103if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
Robert Iannucci2188fe92016-12-02 11:15:57 -0800104 echo -n "selfupdate failed: " 1>&2
105 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
106 echo "" 1>&2
107fi
108
109exec "$CLIENT" "${@}"