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 | |
Joey Armstrong | 04cdd9f | 2023-06-09 15:18:23 -0400 | [diff] [blame] | 20 | dst="vst_venv" # rename to .venv |
Joey Armstrong | 83874cc | 2022-11-26 09:40:08 -0500 | [diff] [blame] | 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 | |
Joey Armstrong | 04cdd9f | 2023-06-09 15:18:23 -0400 | [diff] [blame] | 48 | --venv) dst="$1"; shift ;; |
| 49 | |
Joey Armstrong | 83874cc | 2022-11-26 09:40:08 -0500 | [diff] [blame] | 50 | apply) |
| 51 | pushd "$dst" || { echo "pushd $dst failed"; exit 1; } |
| 52 | for fyl in "${fyls[@]}"; |
| 53 | do |
| 54 | # Conditional install, jenkins may not support interpreter yet. |
| 55 | if [ ! -e "$fyl" ]; then |
| 56 | echo "[SKIP] No venv file to patch: $fyl" |
| 57 | continue |
| 58 | fi |
| 59 | |
| 60 | echo "$fyl" |
| 61 | patch -R -p1 < "../$pat/$fyl/patch" |
| 62 | done |
| 63 | popd || { echo "popd $dst failed"; exit 1; } |
| 64 | ;; |
| 65 | |
| 66 | backup) |
| 67 | mkdir ~/backups |
| 68 | pushd "$src" || { echo "pushd $dst failed"; exit 1; } |
| 69 | tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}" |
| 70 | popd || { echo "popd $dst failed"; exit 1; } |
| 71 | ;; |
| 72 | |
| 73 | gather) |
| 74 | set -x |
| 75 | for fyl in "${fyls[@]}"; |
| 76 | do |
| 77 | patchDir="$pat/$fyl" |
| 78 | mkdir -p "$patchDir" |
| 79 | diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch" |
| 80 | done |
| 81 | find "$pat" -print |
| 82 | set +x |
| 83 | ;; |
| 84 | |
| 85 | *) |
| 86 | echo "ERROR: Unknown action [$opt]" |
| 87 | exit 1 |
| 88 | ;; |
| 89 | esac |
| 90 | done |
| 91 | |
| 92 | # [EOF] |