#!/usr/bin/env sh

set -ex
export "CGO_ENABLED"="1"
export "COMMIT"="7ea35edd817fbf1c3e86051bfd890c1abd110679"
export "FORCE_HOST_GO"="true"
export "GOEXPERIMENT"="systemcrypto"
export "GOPROXY"="direct"
export "KUBE_GIT_TREE_STATE"="clean"
export "TARGET_ARCH"="amd64"
export "TARGET_OS"="linux"
export "VERSION"="v1.30.100"

(
cd kubernetes
major="$(echo ${VERSION} | grep -Po "(?<=v)[0-9]+")"
minor="$(echo ${VERSION} | grep -Po "(?<=v${major}.)[0-9]+")"
cat <<EOF >version-file
KUBE_GIT_COMMIT='${COMMIT}'
KUBE_GIT_TREE_STATE='clean'
KUBE_GIT_VERSION='${VERSION}'
KUBE_GIT_MAJOR='${major}'
KUBE_GIT_MINOR='${minor}'
EOF
KUBE_VERBOSE=3 KUBE_GIT_VERSION_FILE=version-file  WHAT=cmd/kubelet KUBE_CGO_OVERRIDES=kubelet DBG=1 make
KUBE_BUILD_PLATFORMS=${TARGET_OS}/${TARGET_ARCH} KUBE_VERBOSE=3 KUBE_GIT_VERSION_FILE=version-file  WHAT=cmd/kubelet KUBE_CGO_OVERRIDES=kubelet DBG=1 make
if [ "$TARGET_OS" = "windows" ]; then
  mkdir -p _output/bin/
  cp -f _output/local/bin/${TARGET_OS}/${TARGET_ARCH}/kubelet* _output/bin/
fi

)
