Joey Armstrong | 6f63edf | 2024-01-12 11:30:08 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | a9deb69 | 2023-06-30 18:13:01 -0400 | [diff] [blame] | 3 | # Copyright 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 6f63edf | 2024-01-12 11:30:08 -0500 | [diff] [blame] | 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 | ##-------------------## |
| 19 | ##---] GLOBALS [---## |
| 20 | ##-------------------## |
| 21 | set -euo pipefail |
| 22 | |
| 23 | ## ----------------------------------------------------------------------- |
| 24 | ## Intent: Display script documentation. |
| 25 | ## ----------------------------------------------------------------------- |
| 26 | function show_help() |
| 27 | { |
| 28 | cat <<EOH |
| 29 | Usage: $0 |
| 30 | apply Patch virtualenv python modules by version (3.10+). |
| 31 | backup Create a tarball for work-in-progress. |
| 32 | gather Display a list of potential source files to patch. |
| 33 | |
| 34 | --venv Installed venv directory to patch (override default) |
| 35 | --help This message |
| 36 | |
| 37 | See Also |
| 38 | patches/README.md Howto create a patch file. |
| 39 | |
| 40 | EOH |
| 41 | exit 0 |
| 42 | } |
| 43 | |
| 44 | ##----------------## |
| 45 | ##---] MAIN [---## |
| 46 | ##----------------## |
| 47 | declare dst='.venv' # "vst_venv" |
| 48 | declare src="staging" |
| 49 | declare pat="patches" |
| 50 | |
| 51 | ## ----------------------- |
| 52 | ## Slurp available patches |
| 53 | ## ----------------------- |
| 54 | pushd "$pat" >/dev/null |
| 55 | readarray -t fyls < <(find . -name 'patch' -print) |
| 56 | popd >/dev/null |
| 57 | |
| 58 | if [ $# -eq 0 ]; then set -- apply; fi |
| 59 | |
| 60 | while [ $# -gt 0 ]; do |
| 61 | opt="$1"; shift |
| 62 | case "$opt" in |
| 63 | |
| 64 | -*help) show_help ;; |
| 65 | -*venv) dst="$1"; shift ;; |
| 66 | |
| 67 | apply) |
| 68 | pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; } |
| 69 | for fyl in "${fyls[@]}"; |
| 70 | do |
| 71 | path="${fyl%/*}" |
| 72 | |
| 73 | # Conditional install, jenkins may not support interpreter yet. |
| 74 | if [ ! -e "$path" ]; then |
| 75 | echo "[SKIP] $path" |
| 76 | continue |
| 77 | fi |
| 78 | |
| 79 | echo "[APPLY] $path" |
| 80 | patch -R -p1 < "../$pat/${path}/patch" |
| 81 | done |
| 82 | popd >/dev/null || { echo "popd $dst failed"; exit 1; } |
| 83 | ;; |
| 84 | |
| 85 | backup) |
| 86 | mkdir ~/backups |
| 87 | pushd "$src" || { echo "pushd $dst failed"; exit 1; } |
| 88 | tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}" |
| 89 | popd || { echo "popd $dst failed"; exit 1; } |
| 90 | ;; |
| 91 | |
| 92 | gather) |
| 93 | for fyl in "${fyls[@]}"; |
| 94 | do |
| 95 | patchDir="$pat/$fyl" |
| 96 | mkdir -p "$patchDir" |
| 97 | diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch" |
| 98 | done |
| 99 | find "$pat" -print |
| 100 | ;; |
| 101 | |
| 102 | help) show_help ;; |
| 103 | |
| 104 | *) |
| 105 | echo "ERROR: Unknown action [$opt]" |
| 106 | exit 1 |
| 107 | ;; |
| 108 | esac |
| 109 | |
| 110 | echo |
| 111 | done |
| 112 | |
| 113 | # [EOF] - 20231222: Ignore, this triage patch will be abandoned |