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