Skip to content

Commit 8a000b0

Browse files
author
Mario Valderrama
committed
Fixes for update-vendor.sh on OSX and zsh
The update-vendor.sh script needed some fixes to work with zsh on OSX. Various binaries are expected to be GNU utils, which are not installed by default on OSX. I've added suggestions to install ported binaries using homebrew if they are not found in PATH. Skip `shopt -s lastpipe` when `$BASH` is not defined.
1 parent f18b65a commit 8a000b0

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

cluster-autoscaler/hack/update-vendor.sh

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33
set -o errexit
44
set -o pipefail
55
set -o nounset
6-
shopt -s lastpipe
6+
if [[ -n "${BASH}" ]]; then
7+
shopt -s lastpipe
8+
fi
9+
10+
SED=sed
11+
GREP=grep
12+
XARGS=xargs
13+
GETOPT=getopt
14+
if [[ "$(uname)" == "Darwin" ]]; then
15+
SED=gsed
16+
GREP=ggrep
17+
XARGS=gxargs
18+
GETOPT="$(brew --prefix gnu-getopt)/bin/getopt"
19+
command -v $SED >/dev/null || {
20+
echo "$SED not installed. Try: brew install gnu-sed" >&2;
21+
exit 1;
22+
}
23+
command -v $XARGS >/dev/null || {
24+
echo "$XARGS not installed. Try: brew install findutils" >&2;
25+
exit 1;
26+
}
27+
command -v $GETOPT >/dev/null || {
28+
echo "$GETOPT not installed. Try: brew install gnu-getopt" >&2;
29+
exit 1;
30+
}
31+
command -v $GREP >/dev/null || {
32+
echo "$GREP not installed. Try: brew install grep" >&2;
33+
exit 1;
34+
}
35+
fi
736

837
if [[ $(basename $(pwd)) != "cluster-autoscaler" ]];then
938
echo "The script must be run in cluster-autoscaler directory"
@@ -109,8 +138,8 @@ set +o errexit
109138
cp $K8S_REPO/go.mod .
110139

111140
# Check go version
112-
REQUIRED_GO_VERSION=$(cat go.mod |grep '^go ' |tr -s ' ' |cut -d ' ' -f 2)
113-
USED_GO_VERSION=$(go version |sed 's/.*go\([0-9]\+\.[0-9]\+\).*/\1/')
141+
REQUIRED_GO_VERSION=$(cat go.mod | $GREP '^go ' |tr -s ' ' |cut -d ' ' -f 2)
142+
USED_GO_VERSION=$(go version | $SED 's/.*go\([0-9]\+\.[0-9]\+\).*/\1/')
114143

115144

116145
if [[ "${REQUIRED_GO_VERSION}" != "${USED_GO_VERSION}" ]];then
@@ -122,8 +151,8 @@ set +o errexit
122151
fi
123152

124153
# Fix module name and staging modules links
125-
sed -i "s#module k8s.io/kubernetes#module ${TARGET_MODULE}#" go.mod
126-
sed -i "s#\\./staging#${K8S_REPO}/staging#" go.mod
154+
$SED -i "s#module k8s.io/kubernetes#module ${TARGET_MODULE}#" go.mod
155+
$SED -i "s#\\./staging#${K8S_REPO}/staging#" go.mod
127156

128157
function list_dependencies() {
129158
local_tmp_dir=$(mktemp -d "${WORK_DIR}/list_dependencies.XXXX")
@@ -160,10 +189,10 @@ set +o errexit
160189
# Add dependencies from go.mod-extra to go.mod
161190
# Propagate require entries to both require and replace
162191
for go_mod_extra in ${GO_MOD_EXTRA_FILES}; do
163-
go mod edit -json ${go_mod_extra} | jq -r '.Require[]? | "-require \(.Path)@\(.Version)"' | xargs -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
164-
go mod edit -json ${go_mod_extra} | jq -r '.Require[]? | "-replace \(.Path)=\(.Path)@\(.Version)"' | xargs -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
192+
go mod edit -json ${go_mod_extra} | jq -r '.Require[]? | "-require \(.Path)@\(.Version)"' | $XARGS -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
193+
go mod edit -json ${go_mod_extra} | jq -r '.Require[]? | "-replace \(.Path)=\(.Path)@\(.Version)"' | $XARGS -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
165194
# And add explicit replace entries
166-
go mod edit -json ${go_mod_extra} | jq -r '.Replace[]? | "-replace \(.Old.Path)=\(.New.Path)@\(.New.Version)"' | sed "s/@null//g" |xargs -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
195+
go mod edit -json ${go_mod_extra} | jq -r '.Replace[]? | "-replace \(.Old.Path)=\(.New.Path)@\(.New.Version)"' | $SED "s/@null//g" | $XARGS -t -r go mod edit >&${BASH_XTRACEFD} 2>&1
167196
done
168197
# Add k8s.io/kubernetes dependency
169198
go mod edit -require k8s.io/[email protected]
@@ -176,7 +205,7 @@ set +o errexit
176205

177206
IMPLICIT_FOUND="false"
178207
set +o pipefail
179-
diff -u ${WORK_DIR}/packages-before-tidy ${WORK_DIR}/packages-after-tidy | grep -v '\+\+\+ ' | grep '^\+' | cut -b 2- |while read line; do
208+
diff -u ${WORK_DIR}/packages-before-tidy ${WORK_DIR}/packages-after-tidy | $GREP -v '\+\+\+ ' | $GREP '^\+' | cut -b 2- |while read line; do
180209
IMPLICIT_FOUND="true"
181210
echo "Implicit dependency found: ${line}"
182211
done

0 commit comments

Comments
 (0)