11#! /bin/bash
2+
23function is_available {
34 command -v $1 > /dev/null 2>&1 || { echo >&2 " $1 is required but it's not installed. Aborting." ; exit 1; }
45}
56
7+ function version {
8+ echo " $@ " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
9+ }
10+
611if [ -z " $PATTERN_UTILITY_CONTAINER " ]; then
712 PATTERN_UTILITY_CONTAINER=" quay.io/hybridcloudpatterns/utility-container"
813fi
@@ -11,15 +16,30 @@ readonly commands=(podman)
1116for cmd in ${commands[@]} ; do is_available " $cmd " ; done
1217
1318UNSUPPORTED_PODMAN_VERSIONS=" 1.6 1.5"
19+ PODMAN_VERSION_STR=$( podman --version)
1420for i in ${UNSUPPORTED_PODMAN_VERSIONS} ; do
1521 # We add a space
16- if podman --version | grep -q -E " \b${i} " ; then
17- echo " Unsupported podman version. We recommend >= 4.2 .0"
22+ if echo " ${PODMAN_VERSION_STR} " | grep -q -E " \b${i} " ; then
23+ echo " Unsupported podman version. We recommend > 4.3 .0"
1824 podman --version
1925 exit 1
2026 fi
2127done
2228
29+ # podman --version outputs:
30+ # podman version 4.8.2
31+ PODMAN_VERSION=$( echo " ${PODMAN_VERSION_STR} " | awk ' { print $NF }' )
32+
33+ # podman < 4.3.0 do not support keep-id:uid=...
34+ if [ $( version " ${PODMAN_VERSION} " ) -lt $( version " 4.3.0" ) ]; then
35+ PODMAN_ARGS=" -v ${HOME} :/root"
36+ else
37+ # We do not rely on bash's $UID and $GID because on MacOSX $GID is not set
38+ MYUID=$( id -u)
39+ MYGID=$( id -g)
40+ PODMAN_ARGS=" --user ${MYUID} :${MYGID} --userns keep-id:uid=${MYUID} ,gid=${MYGID} "
41+ fi
42+
2343if [ -n " $KUBECONFIG " ]; then
2444 if [[ ! " ${KUBECONFIG} " =~ ^$HOME * ]]; then
2545 echo " ${KUBECONFIG} is pointing outside of the HOME folder, this will make it unavailable from the container."
3151# $HOME is mounted as itself for any files that are referenced with absolute paths
3252# $HOME is mounted to /root because the UID in the container is 0 and that's where SSH looks for credentials
3353
34- # We do not rely on bash's $UID and $GID because on MacOSX $GID is not set
35- MYUID=$( id -u)
36- MYGID=$( id -g)
3754podman run -it --rm --pull=newer \
3855 --security-opt label=disable \
39- --user " ${MYUID} :${MYGID} " \
40- --userns " keep-id:uid=${MYUID} ,gid=${MYGID} " \
4156 -e EXTRA_HELM_OPTS \
4257 -e KUBECONFIG \
4358 -v " ${HOME} " :" ${HOME} " \
4459 -v " ${HOME} " :/pattern-home \
60+ ${PODMAN_ARGS} \
4561 -w " $( pwd) " \
4662 " $PATTERN_UTILITY_CONTAINER " \
4763 $@
0 commit comments