|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +function is_available { |
| 4 | + command -v $1 >/dev/null 2>&1 || { echo >&2 "$1 is required but it's not installed. Aborting."; exit 1; } |
| 5 | +} |
| 6 | + |
| 7 | +function version { |
| 8 | + echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' |
| 9 | +} |
| 10 | + |
3 | 11 | if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then |
4 | 12 | PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container" |
5 | 13 | fi |
6 | 14 |
|
| 15 | +readonly commands=(podman) |
| 16 | +for cmd in ${commands[@]}; do is_available "$cmd"; done |
| 17 | + |
7 | 18 | UNSUPPORTED_PODMAN_VERSIONS="1.6 1.5" |
| 19 | +PODMAN_VERSION_STR=$(podman --version) |
8 | 20 | for i in ${UNSUPPORTED_PODMAN_VERSIONS}; do |
9 | 21 | # We add a space |
10 | | - if podman --version | grep -q -E "\b${i}"; then |
11 | | - 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" |
12 | 24 | podman --version |
13 | 25 | exit 1 |
14 | 26 | fi |
15 | 27 | done |
16 | 28 |
|
| 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 | + |
17 | 43 | if [ -n "$KUBECONFIG" ]; then |
18 | 44 | if [[ ! "${KUBECONFIG}" =~ ^$HOME* ]]; then |
19 | 45 | echo "${KUBECONFIG} is pointing outside of the HOME folder, this will make it unavailable from the container." |
|
25 | 51 | # $HOME is mounted as itself for any files that are referenced with absolute paths |
26 | 52 | # $HOME is mounted to /root because the UID in the container is 0 and that's where SSH looks for credentials |
27 | 53 |
|
28 | | -# Do not quote the ${KUBECONF_ENV} below, otherwise we will pass '' to podman |
29 | | -# which will be confused |
30 | 54 | podman run -it --rm --pull=newer \ |
31 | 55 | --security-opt label=disable \ |
32 | 56 | -e EXTRA_HELM_OPTS \ |
33 | 57 | -e KUBECONFIG \ |
34 | 58 | -v "${HOME}":"${HOME}" \ |
35 | 59 | -v "${HOME}":/pattern-home \ |
36 | | - -v "${HOME}":/root \ |
| 60 | + ${PODMAN_ARGS} \ |
37 | 61 | -w "$(pwd)" \ |
38 | 62 | "$PATTERN_UTILITY_CONTAINER" \ |
39 | 63 | $@ |
0 commit comments