Joey Armstrong | 83874cc | 2022-11-26 09:40:08 -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 | |
| 24 | declare -a fyls=() |
| 25 | fyls+=('lib/python3.10/site-packages/robot/utils/normalizing.py') |
| 26 | fyls+=('lib/python3.10/site-packages/robot/utils/robottypes3.py') |
| 27 | |
| 28 | echo |
| 29 | echo "===========================================================================" |
| 30 | echo "CMD: $0" |
| 31 | echo "PWD: $(/bin/pwd)" |
| 32 | echo "ARGV: $*" |
| 33 | echo "===========================================================================" |
| 34 | |
| 35 | if [ $# -eq 0 ]; then set -- apply; fi |
| 36 | |
| 37 | while [ $# -gt 0 ]; do |
| 38 | opt="$1"; shift |
| 39 | case "$opt" in |
| 40 | help) |
| 41 | cat <<EOH |
| 42 | apply - generate patches from vault source. |
| 43 | backup - Archive patch directory |
| 44 | gather - collect potential python files to edit. |
| 45 | EOH |
| 46 | ;; |
| 47 | |
| 48 | apply) |
| 49 | pushd "$dst" || { echo "pushd $dst failed"; exit 1; } |
| 50 | for fyl in "${fyls[@]}"; |
| 51 | do |
| 52 | # Conditional install, jenkins may not support interpreter yet. |
| 53 | if [ ! -e "$fyl" ]; then |
| 54 | echo "[SKIP] No venv file to patch: $fyl" |
| 55 | continue |
| 56 | fi |
| 57 | |
| 58 | echo "$fyl" |
| 59 | patch -R -p1 < "../$pat/$fyl/patch" |
| 60 | done |
| 61 | popd || { echo "popd $dst failed"; exit 1; } |
| 62 | ;; |
| 63 | |
| 64 | backup) |
| 65 | mkdir ~/backups |
| 66 | pushd "$src" || { echo "pushd $dst failed"; exit 1; } |
| 67 | tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}" |
| 68 | popd || { echo "popd $dst failed"; exit 1; } |
| 69 | ;; |
| 70 | |
| 71 | gather) |
| 72 | set -x |
| 73 | for fyl in "${fyls[@]}"; |
| 74 | do |
| 75 | patchDir="$pat/$fyl" |
| 76 | mkdir -p "$patchDir" |
| 77 | diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch" |
| 78 | done |
| 79 | find "$pat" -print |
| 80 | set +x |
| 81 | ;; |
| 82 | |
| 83 | *) |
| 84 | echo "ERROR: Unknown action [$opt]" |
| 85 | exit 1 |
| 86 | ;; |
| 87 | esac |
| 88 | done |
| 89 | |
| 90 | # [EOF] |