#!/bin/bash # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit set -o nounset set -o pipefail global KUBE_ROOT := $(KUBE_ROOT:-$(dirname "${BASH_SOURCE}")/..) # Detect the OS name/arch so that we can find our binary matchstr $[uname -s] { Darwin { global host_os := 'darwin' } Linux { global host_os := 'linux' } * { echo "Unsupported host OS. Must be Linux or Mac OS X." > !2 exit 1 } } matchstr $[uname -m] { x86_64* { global host_arch := 'amd64' } i?86_64* { global host_arch := 'amd64' } amd64* { global host_arch := 'amd64' } arm* { global host_arch := 'arm' } i?86* { global host_arch := '386' } s390x* { global host_arch := 's390x' } ppc64le* { global host_arch := 'ppc64le' } * { echo "Unsupported host arch. Must be x86_64, 386, arm, s390x or ppc64le." > !2 exit 1 } } # Get the absolute path of the directory component of a file, i.e. the # absolute path of the dirname of $1. proc get_absolute_dirname { echo $[cd $[dirname $1] && pwd] } proc get_bin { global bin := $(1:-) global srcdir := $(2:-) if [[ "${bin}" == "" ]] { echo "Binary name is required" exit 1 } if [[ "${srcdir}" == "" ]] { echo "Source directory path is required" exit 1 } global locations := '( "'${KUBE_ROOT}/_output/bin/${bin}" "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/${bin}" "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/${bin}" "${KUBE_ROOT}/bazel-bin/${srcdir}/${bin}" "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/${bin}" ) echo $[ shell {ls -t $(locations[@]) !2 >/dev/null || true} | head -1] } proc print_error { do { echo "It looks as if you don't have a compiled $(1:-) binary" echo echo "If you are running from a clone of the git repo, please run" echo "'./build/run.sh make cross'. Note that this requires having" echo "Docker installed." echo echo "If you are running from a binary release tarball, something is wrong. " echo "Look at http://kubernetes.io/ for information on how to contact the " echo "development team for help." } >&2 } (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [67 75] ) (Lit_Slash /) (..) } ) spids: [64 78] ) } spids: [63] ) ] spids: [63] ) (Case to_match: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-s)})]) left_token: spids: [87 91] ) ) } arms: [ (case_arm pat_list: [{(Darwin)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_os) op:Equal rhs:{(darwin)} spids:[101])] spids: [101] ) ] spids: [97 98 105 -1] ) (case_arm pat_list: [{(Linux)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_os) op:Equal rhs:{(linux)} spids:[112])] spids: [112] ) ] spids: [108 109 116 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Unsupported host OS. Must be Linux or Mac OS X."))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[129])] ) (C {(exit)} {(1)}) ] spids: [119 120 138 -1] ) ] spids: [84 94 140] ) (Case to_match: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-m)})]) left_token: spids: [146 150] ) ) } arms: [ (case_arm pat_list: [{(x86_64) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(amd64)} spids:[161])] spids: [161] ) ] spids: [156 158 165 -1] ) (case_arm pat_list: [{(i) (Lit_Other "?") (86_64) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(amd64)} spids:[175])] spids: [175] ) ] spids: [168 172 179 -1] ) (case_arm pat_list: [{(amd64) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(amd64)} spids:[187])] spids: [187] ) ] spids: [182 184 191 -1] ) (case_arm pat_list: [{(arm) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(arm)} spids:[199])] spids: [199] ) ] spids: [194 196 203 -1] ) (case_arm pat_list: [{(i) (Lit_Other "?") (86) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(386)} spids:[213])] spids: [213] ) ] spids: [206 210 217 -1] ) (case_arm pat_list: [{(s390x) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(s390x)} spids:[225])] spids: [225] ) ] spids: [220 222 229 -1] ) (case_arm pat_list: [{(ppc64le) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:host_arch) op:Equal rhs:{(ppc64le)} spids:[237])] spids: [237] ) ] spids: [232 234 241 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Unsupported host arch. Must be x86_64, 386, arm, s390x or ppc64le."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[254])] ) (C {(exit)} {(1)}) ] spids: [244 245 263 -1] ) ] spids: [143 153 265] ) (FuncDef name: get_absolute_dirname body: (BraceGroup children: [ (C {(echo)} { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ ($ VSub_Number "$1"))})] ) left_token: spids: [288 294] ) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [284 300] ) ) } ) ] spids: [278] ) spids: [274 277] ) (FuncDef name: get_bin body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:bin) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [317 320] ) ) } spids: [315] ) ] spids: [315] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:srcdir) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [326 329] ) ) } spids: [324] ) ] spids: [324] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{(DQ (${ VSub_Name bin))} right:{(DQ )}) ) terminator: ) ] action: [(C {(echo)} {(DQ ("Binary name is required"))}) (C {(exit)} {(1)})] spids: [-1 351] ) ] spids: [-1 366] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name srcdir))} right: {(DQ )} ) ) terminator: ) ] action: [(C {(echo)} {(DQ ("Source directory path is required"))}) (C {(exit)} {(1)})] spids: [-1 387] ) ] spids: [-1 402] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:locations) op: Equal rhs: { (ArrayLiteralPart words: [ {(DQ (${ VSub_Name KUBE_ROOT) (/_output/bin/) (${ VSub_Name bin))} { (DQ (${ VSub_Name KUBE_ROOT) (/_output/dockerized/bin/) (${ VSub_Name host_os) (/) (${ VSub_Name host_arch) (/) (${ VSub_Name bin) ) } { (DQ (${ VSub_Name KUBE_ROOT) (/_output/local/bin/) (${ VSub_Name host_os) (/) (${ VSub_Name host_arch) (/) (${ VSub_Name bin) ) } { (DQ (${ VSub_Name KUBE_ROOT) (/bazel-bin/) (${ VSub_Name srcdir) (/) (${ VSub_Name bin) ) } { (DQ (${ VSub_Name KUBE_ROOT) (/platforms/) (${ VSub_Name host_os) (/) (${ VSub_Name host_arch) (/) (${ VSub_Name bin) ) } ] ) } spids: [407] ) ] spids: [407] ) (C {(echo)} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (Subshell child: (AndOr children: [ (SimpleCommand words: [ {(ls)} {(-t)} { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [507 512] ) ) } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [515] ) ] ) (C {(true)}) ] op_id: Op_DPipe ) spids: [501 521] ) (C {(head)} {(-1)}) ] negated: False ) ] ) left_token: spids: [499 529] ) } ) ] spids: [312] ) spids: [306 311] ) (FuncDef name: print_error body: (BraceGroup children: [ (BraceGroup children: [ (C {(echo)} { (DQ ("It looks as if you don't have a compiled ") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [550 553] ) (" binary") ) } ) (C {(echo)}) (C {(echo)} {(DQ ("If you are running from a clone of the git repo, please run"))}) (C {(echo)} {(DQ ("'./build/run.sh make cross'. Note that this requires having"))}) (C {(echo)} {(DQ ("Docker installed."))}) (C {(echo)}) (C {(echo)} {(DQ ("If you are running from a binary release tarball, something is wrong. "))} ) (C {(echo)} {(DQ ("Look at http://kubernetes.io/ for information on how to contact the "))} ) (C {(echo)} {(DQ ("development team for help."))}) ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[608])] spids: [543] ) ] spids: [540] ) spids: [534 539] ) ] )