github.com/RedHatInsights/insights-content-service@v1.0.0/update_rules_content.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2020 Red Hat, Inc
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  
    17  
    18  # Updates the ./rules-content directory with the latest rules to test with
    19  
    20  set -exv
    21  
    22  function clean_up() {
    23      rm -rf "$CLONE_TEMP_DIR"
    24  }
    25  trap clean_up EXIT
    26  
    27  # Updated with every new ccx-rules-opc release.
    28  CCX_RULES_OCP_TAG="2023.07.13"
    29  
    30  RULES_REPO="https://gitlab.cee.redhat.com/ccx/ccx-rules-ocp.git"
    31  SCRIPT_DIR="$(dirname "$(realpath "$0")")"
    32  CONTENT_DIR="${SCRIPT_DIR}/rules-content"
    33  TUTORIAL_RULE_CONTENT_DIR="${SCRIPT_DIR}/rules/tutorial/content"
    34  TEST_RULE_CONTENT_DIR="${SCRIPT_DIR}/rules/test/content"
    35  
    36  CLONE_TEMP_DIR="${SCRIPT_DIR}/.tmp"
    37  RULES_CONTENT="${CLONE_TEMP_DIR}/content/"
    38  
    39  if [ $# -ne 0 ]
    40  then
    41      if [[ "$*" == *-test-rules-only* ]]
    42      then
    43          echo "Creating content dir with tutorial and test rules"
    44          mkdir -p "${CONTENT_DIR}/external/"
    45          mkdir -p "${CONTENT_DIR}/internal/"
    46          mkdir -p "${CONTENT_DIR}/ocs/"
    47          cp -R "${SCRIPT_DIR}/rules" "${CONTENT_DIR}/external/."
    48          cp "${TUTORIAL_RULE_CONTENT_DIR}/config.yaml" "${CONTENT_DIR}/."
    49          exit 0
    50     fi
    51  fi
    52  
    53  echo "Attempting to clone repository into ${CLONE_TEMP_DIR}"
    54  if ! git clone --depth=1 --branch "${CCX_RULES_OCP_TAG}" "${RULES_REPO}" "${CLONE_TEMP_DIR}"
    55  then
    56      echo "Couldn't clone rules repository"
    57      exit $?
    58  fi
    59  
    60  if ! rm -rf "${CONTENT_DIR}"
    61  then
    62      echo "Couldn't remove previous content"
    63      exit $?
    64  fi
    65  
    66  if ! mv "${RULES_CONTENT}" "${CONTENT_DIR}"
    67  then
    68      echo "Couldn't move rules content from cloned repository"
    69      exit $?
    70  fi
    71  
    72  rm -rf "${CLONE_TEMP_DIR}"
    73  
    74  cp -a "${TUTORIAL_RULE_CONTENT_DIR}/." "${CONTENT_DIR}/external/rules/"
    75  
    76  if [ $# -ne 0 ]
    77  then
    78      if [[ "$*" == *-include-test-rules* ]]
    79      then
    80          echo "Including test rules in served content"
    81          cp -a "${TEST_RULE_CONTENT_DIR}/." "${CONTENT_DIR}/external/rules/"
    82      fi
    83  fi
    84  
    85  echo "${CONTENT_DIR} updated with latest rules"
    86  exit 0