---
apiVersion: v1
items:
- apiVersion: v1
  data:
    cnibincopy.sh: |-
      #!/bin/bash

      DESTINATION_DIRECTORY=/host/opt/cni/bin/

      # Perform validation of usage
      if [ -z "$RHEL7_SOURCE_DIRECTORY" ] ||
         [ -z "$RHEL8_SOURCE_DIRECTORY" ] ||
         [ -z "$DEFAULT_SOURCE_DIRECTORY" ]; then
        echo "FATAL ERROR: You must set env variables: RHEL7_SOURCE_DIRECTORY, RHEL8_SOURCE_DIRECTORY, DEFAULT_SOURCE_DIRECTORY"
        exit 1
      fi

      if [ ! -d "$DESTINATION_DIRECTORY" ]; then
        echo "FATAL ERROR: Destination directory ($DESTINATION_DIRECTORY) does not exist"
        exit 1
      fi

      # Collect host OS information
      . /host/etc/os-release
      rhelmajor=
      # detect which version we're using in order to copy the proper binaries
      case "${ID}" in
        rhcos) rhelmajor=8
        ;;
        rhel) rhelmajor=$(echo "${VERSION_ID}" | cut -f 1 -d .)
        ;;
        fedora)
          if [ "${VARIANT_ID}" == "coreos" ]; then
            rhelmajor=8
          else
            echo "FATAL ERROR: Unsupported Fedora variant=${VARIANT_ID}"
            exit 1
          fi
        ;;
        *) echo "FATAL ERROR: Unsupported OS ID=${ID}"; exit 1
        ;;
      esac

      # Set which directory we'll copy from, detect if it exists
      sourcedir=
      founddir=false
      case "${rhelmajor}" in
        7)
          if [ -d "${RHEL7_SOURCE_DIRECTORY}" ]; then
            sourcedir=${RHEL7_SOURCE_DIRECTORY}
            founddir=true
          fi
        ;;
        8)
          if [ -d "${RHEL8_SOURCE_DIRECTORY}" ]; then
            sourcedir=${RHEL8_SOURCE_DIRECTORY}
            founddir=true
          fi
        ;;
        *)
          echo "ERROR: RHEL Major Version Unsupported, rhelmajor=${rhelmajor}"
        ;;
      esac

      # When it doesn't exist, fall back to the original directory.
      if [ "$founddir" == false ]; then
        echo "Source directory unavailable for OS version: ${rhelmajor}"
        sourcedir=$DEFAULT_SOURCE_DIRECTORY
      fi

      cp -rf ${sourcedir}* $DESTINATION_DIRECTORY

      if [ $? -eq 0 ]; then
        echo "Successfully copied files in ${sourcedir} to $DESTINATION_DIRECTORY"
      else
        echo "Failed to copy files in ${sourcedir} to $DESTINATION_DIRECTORY"
        exit 1
      fi
  kind: ConfigMap
  metadata:
    annotations:
      kubernetes.io/description: |
        This is a script used to copy CNI binaries based on host OS
      release.openshift.io/version: 4.6.52
    creationTimestamp: "2022-03-08T10:38:07Z"
    managedFields:
    - apiVersion: v1
      fieldsType: FieldsV1
      fieldsV1:
        f:data:
          .: {}
          f:cnibincopy.sh: {}
        f:metadata:
          f:annotations:
            .: {}
            f:kubernetes.io/description: {}
            f:release.openshift.io/version: {}
          f:ownerReferences:
            .: {}
            k:{"uid":"b48e3238-e625-4cc0-acf5-5166b34864a9"}:
              .: {}
              f:apiVersion: {}
              f:blockOwnerDeletion: {}
              f:controller: {}
              f:kind: {}
              f:name: {}
              f:uid: {}
      manager: cluster-network-operator
      operation: Update
      time: "2022-03-08T10:38:07Z"
    name: cni-binary-copy-script
    namespace: openshift-multus
    ownerReferences:
    - apiVersion: operator.openshift.io/v1
      blockOwnerDeletion: true
      controller: true
      kind: Network
      name: cluster
      uid: b48e3238-e625-4cc0-acf5-5166b34864a9
    resourceVersion: "4834"
    selfLink: /api/v1/namespaces/openshift-multus/configmaps/cni-binary-copy-script
    uid: 011112fa-7746-4bb0-b31f-d8208d783f9c
kind: ConfigMapList
metadata:
  resourceVersion: "83068"
  selfLink: /api/v1/namespaces/openshift-multus/configmaps
