blob: 04c41b50cceaa2404d147bce03bf9fae27f03f4f [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
Brian White361822c2018-04-04 15:21:45 -04009CYGWIN=false
Robert Iannucci2188fe92016-12-02 11:15:57 -080010MYPATH=$(dirname "${BASH_SOURCE[0]}")
11
12: ${CIPD_CLIENT_VER:=`cat $MYPATH/cipd_client_version`}
13: ${CIPD_CLIENT_SRV:='https://chrome-infra-packages.appspot.com'}
14
15UNAME=`uname -s | tr '[:upper:]' '[:lower:]'`
16case $UNAME in
17 linux)
18 PLAT=linux
19 ;;
Brian White361822c2018-04-04 15:21:45 -040020 cygwin*)
21 PLAT=windows
22 CYGWIN=true
23 ;;
24 msys*|mingw*)
Robert Iannucci2188fe92016-12-02 11:15:57 -080025 PLAT=windows
26 ;;
27 darwin)
28 PLAT=mac
29 ;;
30 *)
Vasili Skurydzin179059f2018-06-19 20:00:41 +000031 echo "cipd not supported on $UNAME"
Robert Iannucci2188fe92016-12-02 11:15:57 -080032 exit 1
33esac
34
35UNAME=`uname -m | tr '[:upper:]' '[:lower:]'`
36case $UNAME in
37 x86_64|amd64)
38 ARCH=amd64
39 ;;
Robert Iannucciff2bf092017-09-11 16:27:26 -070040 s390x) # best-effort support for IBM s390x: crbug.com/764087
41 ARCH=s390x
42 ;;
Dan Jacques63421282017-10-16 15:05:59 -040043 ppc64) # best-effort support for 64-bit PowerPC: crbug.com/773857
44 ARCH=ppc64
45 ;;
Dan Jacques1e0b7a52017-10-17 11:19:18 -040046 ppc64le) # best-effort support for 64-bit PowerPC/LE: crbug.com/773857
Dan Jacques63421282017-10-16 15:05:59 -040047 ARCH=ppc64le
48 ;;
William Hesse6fd24842017-10-10 13:55:22 +020049 aarch64)
50 ARCH=arm64
51 ;;
Benjamin Pastenee346e412017-10-20 12:57:43 -070052 armv7l)
53 ARCH=armv6l
54 ;;
Robert Iannucci2188fe92016-12-02 11:15:57 -080055 arm*)
56 ARCH=$UNAME
57 ;;
58 *86)
59 ARCH=386
60 ;;
Wang Qing254538b2018-07-26 02:23:53 +000061 mips*)
62 ARCH=$UNAME
63 ;;
Robert Iannucci2188fe92016-12-02 11:15:57 -080064 *)
65 echo "UNKNOWN Machine architecture: $UNAME"
66 exit 1
67esac
68
69URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
70CLIENT="$MYPATH/.cipd_client"
71
72USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
73
74if [ ! -e "$CLIENT" ]; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020075 echo "Bootstrapping cipd client for ${PLAT}-${ARCH} from ${URL}..."
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000076
77 # Download the client into a temporary file, then move it into the final
78 # location atomically.
79 #
80 # This wonky tempdir method works on Linux and Mac.
81 CIPD_CLIENT_TMP=$(\
82 mktemp -p "$MYPATH" 2>/dev/null || \
83 mktemp "$MYPATH/.cipd_client.XXXXXXX")
84
Robert Iannucci2188fe92016-12-02 11:15:57 -080085 if hash curl 2> /dev/null ; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020086 curl "$URL" -s --show-error -f -A "$USER_AGENT" -L -o "$CIPD_CLIENT_TMP"
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000087 elif hash wget 2> /dev/null ; then
88 wget "$URL" -q -U "${USER_AGENT}" -O "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080089 else
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000090 echo Your platform is missing a supported fetch command. Please use your package
91 echo manager to install one before continuing:
92 echo
93 echo curl
94 echo wget
Robert Iannucci2188fe92016-12-02 11:15:57 -080095 echo
96 echo Alternately, manually download:
97 echo "$URL"
98 echo To $CLIENT, and then re-run this command.
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000099 rm "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -0800100 exit 1
101 fi
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +0000102
103 chmod +x "$CIPD_CLIENT_TMP"
104
105 set +e
106 mv "$CIPD_CLIENT_TMP" "$CLIENT"
107 set -e
Robert Iannucci2188fe92016-12-02 11:15:57 -0800108fi
109
110export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
Daniel Jacques9f9d82a2017-07-27 14:21:21 +0000111if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
Robert Iannucci2188fe92016-12-02 11:15:57 -0800112 echo -n "selfupdate failed: " 1>&2
113 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
114 echo "" 1>&2
115fi
116
Brian White361822c2018-04-04 15:21:45 -0400117# CygWin requires changing absolute paths to Windows form. Relative paths
118# are typically okay as Windows generally accepts both forward and back
119# slashes. This could possibly be constrained to only /tmp/ and /cygdrive/.
120if $CYGWIN; then
121 args=("$@")
122 for i in `seq 2 $#`; do
123 arg="${@:$i:1}"
124 if [ "${arg:0:1}" == "/" ]; then
125 last=$((i-1))
126 next=$((i+1))
127 set -- "${@:1:$last}" `cygpath -w "$arg"` "${@:$next}"
128 fi
129 done
130 echo "$CLIENT" "${@}"
131fi
132
Robert Iannucci2188fe92016-12-02 11:15:57 -0800133exec "$CLIENT" "${@}"