Michal Ptacek | 5a269d2 | 2019-01-28 13:03:16 +0000 | [diff] [blame] | 1 | #! /usr/bin/env bash |
| 2 | |
| 3 | # COPYRIGHT NOTICE STARTS HERE |
| 4 | # |
| 5 | # Copyright 2018 © Samsung Electronics Co., Ltd. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # COPYRIGHT NOTICE ENDS HERE |
| 20 | |
| 21 | # This simple script should be used during build / packaging process |
| 22 | # and it should be referenced in BuildGuide. |
| 23 | # Patching of helm charts is the only way for OOM charts to be compatible |
| 24 | # with this offline installer. This will become obsolete once native |
| 25 | # solution is implemented in charts themselves and which is tracked |
| 26 | # in OOM-1610 |
| 27 | |
| 28 | # fail fast |
| 29 | set -e |
| 30 | |
| 31 | # colours |
| 32 | _R='\033[0;31;1m' #Red |
| 33 | _G='\033[0;32;1m' #Green |
| 34 | _Y='\033[0;33;1m' #Yellow |
| 35 | C_='\033[0m' #Color off |
| 36 | |
| 37 | usage () { |
| 38 | echo "Usage:" |
| 39 | echo -e "./$(basename $0) <helm charts repo> <commit/tag/branch> <patchfile> <target_dir>\n" |
Michal Ptacek | b78bbf8 | 2019-05-29 14:56:50 +0000 | [diff] [blame] | 40 | echo "Example: ./$(basename $0) https://gerrit.onap.org/r/oom master /root/offline-installer/patches/onap.patch /root/offline-installer/ansible/application/helm_charts" |
Michal Ptacek | 5a269d2 | 2019-01-28 13:03:16 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | if [ "$#" -ne 4 ]; then |
| 44 | echo "This script should get exactly 4 arguments!" |
| 45 | echo -e "Wrong number of parameters provided\n" |
| 46 | usage |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | # main |
| 51 | # git and patch tools are preconditions for this to work |
| 52 | CURR=1 |
| 53 | TOTAL=5 |
Milan Verespej | c9ea08f | 2019-02-06 12:29:00 +0100 | [diff] [blame] | 54 | PATCH_FILE=$(realpath "${3}") |
Michal Ptacek | 5a269d2 | 2019-01-28 13:03:16 +0000 | [diff] [blame] | 55 | |
| 56 | echo -e "${_G}[Step $((CURR++))/${TOTAL} cloning repo with charts to be patched]${C_}" |
root | b4110df | 2019-05-31 14:03:05 +0200 | [diff] [blame^] | 57 | git clone --recurse-submodules "${1}" "${4}" |
Michal Ptacek | 5a269d2 | 2019-01-28 13:03:16 +0000 | [diff] [blame] | 58 | |
| 59 | echo -e "${_G}[Step $((CURR++))/${TOTAL} setting working dir to ${4}]${C_}" |
| 60 | pushd "${4}" |
| 61 | |
| 62 | echo -e "${_G}[Step $((CURR++))/${TOTAL} git-checkout to correct base]${C_}" |
| 63 | git checkout "${2}" |
| 64 | |
| 65 | echo -e "${_G}[Step $((CURR++))/${TOTAL} patching charts]${C_}" |
Milan Verespej | c9ea08f | 2019-02-06 12:29:00 +0100 | [diff] [blame] | 66 | git apply "${PATCH_FILE}" |
Michal Ptacek | 5a269d2 | 2019-01-28 13:03:16 +0000 | [diff] [blame] | 67 | |
| 68 | echo -e "${_G}[Step $((CURR++))/${TOTAL} returning to original working directory]${C_}" |
| 69 | popd |
| 70 | |