Skip to content

Commit 6407c8d

Browse files
committed
ET#87293 [mysql-operator] port the build.sh script changes to 9.4.0 and trunk
adding the strict option checks and handle unknown args
1 parent a31384d commit 6407c8d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

build.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
#
66

7+
# Usage function
8+
print_usage() {
9+
cat <<EOF
10+
Usage: $0 -a <arch> -t <tag>
11+
12+
Options:
13+
-a Architecture (amd64,arm64)
14+
-t Image tag (e.g., mysql/community-operator, mysql/enterprise-operator)
15+
-h Show this help message
16+
EOF
17+
}
18+
19+
#Default values
720
ARCH='amd64'
821
IMG_TAG=$(./tag.sh)
922
MAJOR_VERSION=${IMG_TAG:0:3}
@@ -14,14 +27,30 @@ while getopts "a:f:t:h" opt; do
1427
a)
1528
# Set architecture from -a option
1629
ARCH="$OPTARG"
30+
if [[ -z "$ARCH" || ! "$ARCH" =~ ^(amd64|arm64)$ ]]; then
31+
echo "Error: Invalid architecture '$ARCH'" >&2
32+
exit 1
33+
fi
1734
;;
1835
f)
1936
# Set Dockerfile from -f option
2037
DOCKERFILE="$OPTARG"
38+
if [[ -z "$DOCKERFILE" ]]; then
39+
echo "Error: Docker file arg (-f) is required and cannot be empty." >&2
40+
exit 1
41+
fi
2142
;;
2243
t)
2344
# Set image tag from -t option
2445
TAG="$OPTARG"
46+
if [[ -z "$TAG" ]]; then
47+
echo "Error: Image tag (-t) is required and cannot be empty." >&2
48+
exit 1
49+
fi
50+
;;
51+
h)
52+
print_usage
53+
exit 0
2554
;;
2655
\?)
2756
# Unknown option handler
@@ -31,4 +60,12 @@ while getopts "a:f:t:h" opt; do
3160
esac
3261
done
3362

63+
#check if any unknown args passed to the script
64+
shift $((OPTIND - 1))
65+
if [[ $# -gt 0 ]]; then
66+
echo "Error: Unknown arguments: $*" >&2
67+
print_usage
68+
exit 1
69+
fi
70+
3471
docker build --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy} -f "${DOCKERFILE}" -t "${TAG}":${MAJOR_VERSION}-$ARCH .

0 commit comments

Comments
 (0)