blob: 16a5f64c2d4f58d56aeddf86c6fee95bbba4c32d [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 *)
31 echo "UNKNOWN OS: $UNAME"
32 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 ;;
61 *)
62 echo "UNKNOWN Machine architecture: $UNAME"
63 exit 1
64esac
65
66URL="$CIPD_CLIENT_SRV/client?platform=${PLAT}-${ARCH}&version=$CIPD_CLIENT_VER"
67CLIENT="$MYPATH/.cipd_client"
68
69USER_AGENT="depot_tools/$(git -C $MYPATH rev-parse HEAD 2>/dev/null || echo "???")"
70
71if [ ! -e "$CLIENT" ]; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020072 echo "Bootstrapping cipd client for ${PLAT}-${ARCH} from ${URL}..."
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000073
74 # Download the client into a temporary file, then move it into the final
75 # location atomically.
76 #
77 # This wonky tempdir method works on Linux and Mac.
78 CIPD_CLIENT_TMP=$(\
79 mktemp -p "$MYPATH" 2>/dev/null || \
80 mktemp "$MYPATH/.cipd_client.XXXXXXX")
81
Robert Iannucci2188fe92016-12-02 11:15:57 -080082 if hash curl 2> /dev/null ; then
Dan Jacqueseb1feb92017-07-28 13:04:28 +020083 curl "$URL" -s --show-error -f -A "$USER_AGENT" -L -o "$CIPD_CLIENT_TMP"
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000084 elif hash wget 2> /dev/null ; then
85 wget "$URL" -q -U "${USER_AGENT}" -O "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080086 else
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000087 echo Your platform is missing a supported fetch command. Please use your package
88 echo manager to install one before continuing:
89 echo
90 echo curl
91 echo wget
Robert Iannucci2188fe92016-12-02 11:15:57 -080092 echo
93 echo Alternately, manually download:
94 echo "$URL"
95 echo To $CLIENT, and then re-run this command.
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000096 rm "${CIPD_CLIENT_TMP}"
Robert Iannucci2188fe92016-12-02 11:15:57 -080097 exit 1
98 fi
Pawel Hajdan, Jr8c8a0a52017-09-06 19:40:18 +000099
100 chmod +x "$CIPD_CLIENT_TMP"
101
102 set +e
103 mv "$CIPD_CLIENT_TMP" "$CLIENT"
104 set -e
Robert Iannucci2188fe92016-12-02 11:15:57 -0800105fi
106
107export CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT
Daniel Jacques9f9d82a2017-07-27 14:21:21 +0000108if ! "$CLIENT" selfupdate -version "$CIPD_CLIENT_VER" ; then
Robert Iannucci2188fe92016-12-02 11:15:57 -0800109 echo -n "selfupdate failed: " 1>&2
110 echo "run \`CIPD_HTTP_USER_AGENT_PREFIX=$USER_AGENT/manual $CLIENT selfupdate -version '$CIPD_CLIENT_VER'\` to diagnose" 1>&2
111 echo "" 1>&2
112fi
113
Brian White361822c2018-04-04 15:21:45 -0400114# CygWin requires changing absolute paths to Windows form. Relative paths
115# are typically okay as Windows generally accepts both forward and back
116# slashes. This could possibly be constrained to only /tmp/ and /cygdrive/.
117if $CYGWIN; then
118 args=("$@")
119 for i in `seq 2 $#`; do
120 arg="${@:$i:1}"
121 if [ "${arg:0:1}" == "/" ]; then
122 last=$((i-1))
123 next=$((i+1))
124 set -- "${@:1:$last}" `cygpath -w "$arg"` "${@:$next}"
125 fi
126 done
127 echo "$CLIENT" "${@}"
128fi
129
Robert Iannucci2188fe92016-12-02 11:15:57 -0800130exec "$CLIENT" "${@}"