Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2022 Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ----------------------------------------------------------------------- |
| 17 | |
| 18 | set -euo pipefail |
| 19 | |
| 20 | dst="vst_venv" |
| 21 | src="staging" |
| 22 | pat="patches" |
| 23 | |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 24 | declare -a fyls=() |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame^] | 25 | pushd "$pat" >/dev/null |
| 26 | fyls+=( $(find . -name 'patch' -print) ) |
| 27 | popd >/dev/null |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 28 | |
| 29 | if [ $# -eq 0 ]; then set -- apply; fi |
| 30 | |
| 31 | while [ $# -gt 0 ]; do |
| 32 | opt="$1"; shift |
| 33 | case "$opt" in |
| 34 | |
| 35 | -*venv) dst="$1"; shift ;; |
| 36 | |
| 37 | help) |
| 38 | cat <<EOH |
| 39 | apply - generate patches from vault source. |
| 40 | backup - Archive patch directory |
| 41 | gather - collect potential python files to edit. |
| 42 | EOH |
| 43 | ;; |
| 44 | |
| 45 | apply) |
| 46 | pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; } |
| 47 | for fyl in "${fyls[@]}"; |
| 48 | do |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame^] | 49 | path="${fyl%/*}" |
| 50 | |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 51 | # Conditional install, jenkins may not support interpreter yet. |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame^] | 52 | if [ ! -e "$path" ]; then |
| 53 | echo "[SKIP] $path" |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 54 | continue |
| 55 | fi |
| 56 | |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame^] | 57 | echo "[APPLY] $path" |
| 58 | patch -R -p1 < "../$pat/${path}/patch" |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 59 | done |
| 60 | popd >/dev/null || { echo "popd $dst failed"; exit 1; } |
| 61 | ;; |
| 62 | |
| 63 | backup) |
| 64 | mkdir ~/backups |
| 65 | pushd "$src" || { echo "pushd $dst failed"; exit 1; } |
| 66 | tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}" |
| 67 | popd || { echo "popd $dst failed"; exit 1; } |
| 68 | ;; |
| 69 | |
| 70 | gather) |
| 71 | for fyl in "${fyls[@]}"; |
| 72 | do |
| 73 | patchDir="$pat/$fyl" |
| 74 | mkdir -p "$patchDir" |
| 75 | diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch" |
| 76 | done |
| 77 | find "$pat" -print |
| 78 | ;; |
| 79 | |
| 80 | *) |
| 81 | echo "ERROR: Unknown action [$opt]" |
| 82 | exit 1 |
| 83 | ;; |
| 84 | esac |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame^] | 85 | |
| 86 | echo |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 87 | done |
| 88 | |
| 89 | # [EOF] |