Skip to content

Commit 468115e

Browse files
committed
refactor OS X sed check into a util
1 parent 02c4f7a commit 468115e

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

scripts/update-client.sh

+4-17
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ set -o pipefail
2424
# The openapi-generator version used by this client
2525
export OPENAPI_GENERATOR_COMMIT="v4.3.0"
2626

27-
# OS X sed doesn't support "--version". This way we can tell if OS X sed is
28-
# used.
29-
if ! sed --version &>/dev/null; then
30-
# OS X sed and GNU sed aren't compatible with backup flag "-i". Namely
31-
# sed -i ... - does not work on OS X
32-
# sed -i'' ... - does not work on certain OS X versions
33-
# sed -i '' ... - does not work on GNU
34-
echo ">>> OS X sed detected, which may be incompatible with this script. Please install and use GNU sed instead:
35-
$ brew install gnu-sed
36-
$ brew info gnu-sed
37-
# Find the path to the installed gnu-sed and add it to your PATH. The default
38-
# is:
39-
# PATH=\"/Users/\$USER/homebrew/opt/gnu-sed/libexec/gnubin:\$PATH\""
40-
exit 1
41-
fi
42-
4327
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
4428
CLIENT_ROOT="${SCRIPT_ROOT}/../kubernetes"
4529
CLIENT_VERSION=$(python "${SCRIPT_ROOT}/constants.py" CLIENT_VERSION)
@@ -50,11 +34,14 @@ pushd "${SCRIPT_ROOT}" > /dev/null
5034
SCRIPT_ROOT=`pwd`
5135
popd > /dev/null
5236

37+
source ${SCRIPT_ROOT}/util/common.sh
38+
util::common::check_sed
39+
5340
pushd "${CLIENT_ROOT}" > /dev/null
5441
CLIENT_ROOT=`pwd`
5542
popd > /dev/null
5643

57-
TEMP_FOLDER=$(mktemp -d)
44+
TEMP_FOLDER=$(mktemp -d)
5845
trap "rm -rf ${TEMP_FOLDER}" EXIT SIGINT
5946

6047
SETTING_FILE="${TEMP_FOLDER}/settings"

scripts/update-submodule.sh

+3-15
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,15 @@ set -o errexit
3131
set -o nounset
3232
set -o pipefail
3333

34-
# OS X sed doesn't support "--version". This way we can tell if OS X sed is
35-
# used.
36-
if ! sed --version &>/dev/null; then
37-
# OS X sed and GNU sed aren't compatible with backup flag "-i". Namely
38-
# sed -i ... - does not work on OS X
39-
# sed -i'' ... - does not work on certain OS X versions
40-
# sed -i '' ... - does not work on GNU
41-
echo ">>> OS X sed detected, which may be incompatible with this script. Please install and use GNU sed instead:
42-
$ brew install gnu-sed
43-
$ brew info gnu-sed
44-
# Find the path to the installed gnu-sed and add it to your PATH. The default
45-
# is:
46-
# PATH=\"/Users/\$USER/homebrew/opt/gnu-sed/libexec/gnubin:\$PATH\""
47-
exit 1
48-
fi
4934

5035
repo_root="$(git rev-parse --show-toplevel)"
5136
declare -r repo_root
5237
cd "${repo_root}"
5338

5439
source scripts/util/changelog.sh
40+
source scripts/util/common.sh
41+
42+
util::common::check_sed
5543
go get k8s.io/release/cmd/release-notes
5644

5745
TARGET_RELEASE=${TARGET_RELEASE:-"v$(grep "^CLIENT_VERSION = \"" scripts/constants.py | sed "s/CLIENT_VERSION = \"//g" | sed "s/\"//g")"}

scripts/util/common.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# check_sed returns an error and suggests installing GNU sed, if OS X sed is
18+
# detected.
19+
function util::common::check_sed {
20+
# OS X sed doesn't support "--version". This way we can tell if OS X sed is
21+
# used.
22+
if ! sed --version &>/dev/null; then
23+
# OS X sed and GNU sed aren't compatible with backup flag "-i". Namely
24+
# sed -i ... - does not work on OS X
25+
# sed -i'' ... - does not work on certain OS X versions
26+
# sed -i '' ... - does not work on GNU
27+
echo ">>> OS X sed detected, which may be incompatible with this script. Please install and use GNU sed instead:
28+
$ brew install gnu-sed
29+
$ brew info gnu-sed
30+
# Find the path to the installed gnu-sed and add it to your PATH. The default
31+
# is:
32+
# PATH=\"/Users/\$USER/homebrew/opt/gnu-sed/libexec/gnubin:\$PATH\""
33+
exit 1
34+
fi
35+
}

0 commit comments

Comments
 (0)