states: Break on error, retry states up to 5 times
[fuel.git] / mcp / patches / patch.sh
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2017 Mirantis Inc., Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
11
12 if [ -r "$1" ]; then
13   while IFS=': ' read -r p_dest p_file; do
14     if [[ ! "${p_dest}" =~ '^#' ]] && [[ "${p_dest}" =~ $2 ]] && \
15       ! patch --dry-run -Rd "${p_dest}" -r - -s -p1 < \
16         "/root/fuel/mcp/patches/${p_file}" > /dev/null; then
17           patch -fd "${p_dest}" -p1 < "/root/fuel/mcp/patches/${p_file}"
18     fi
19   done < "$1"
20 fi