-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrun.sh
executable file
·78 lines (63 loc) · 1.5 KB
/
crun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#set -u # no uninitialized var usage.
ARGS_ARRAY=("${@}")
NUM_ARGS=${#ARGS_ARRAY[@]}
THISDIR=$(dirname $(readlink -e ${BASH_SOURCE[0]}))
THISPROG=$(basename $(readlink -e ${BASH_SOURCE[0]}))
usageText="
SYNTAX: $THISPROG [options]
Run the container.
OPTIONS:
-b = run bash instead of the normal entrypoint
-r = run as root (superuser)
EXAMPLES:
$THISPROG some-topic
$THISPROG -b [-r] # for bash
"
Syntax()
{
set +x
echo "$usageText"
exit 101
}
err()
{
set +x
set +u
>&2 echo
>&2 echo "ERROR - $1"
>&2 echo
>&2 echo "Type '$THISPROG -h' for help."
>&2 echo
CODE="$2"
[ -z "$CODE" ] && CODE=1
exit $CODE
}
# Parse the arguments.
runBash=false
useRoot=""
for (( ix = 0; ix < ${NUM_ARGS}; ix++ )); do
arg="${ARGS_ARRAY[${ix}]}"
if [[ $arg = "-h" || $arg = "--help" ]]; then
Syntax
elif [[ $arg = "-b" || $arg = "--bash" ]]; then
runBash=true
elif [[ $arg = "-r" || $arg = "--root" ]]; then
useRoot="--user root"
else # a regular param
err "unexpected argument: $arg"
fi
done
set -x
set -e
NAME=kstemplate
podName=mkafkaPod
netOpt=""
#netOpt="--hostname $NAME --network=network:kafkanet"
stdOpt=" --name $NAME $useRoot --pod=$podName"
podman rm --ignore -v $NAME
if $runBash; then
podman run -it -e KAFKA_HOST -e KAFKA_PORT $netOpt $stdOpt --entrypoint bash kstemplate:latest
else # normally:
podman run -it -e KAFKA_HOST -e KAFKA_PORT $netOpt $stdOpt kstemplate:latest "$topicName"
fi