Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 8388b7f | 2023-01-23 11:20:04 -0500 | [diff] [blame] | 3 | # Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -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 | |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 18 | ##-------------------## |
| 19 | ##---] GLOBALS [---## |
| 20 | ##-------------------## |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 21 | set -euo pipefail |
| 22 | |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 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. |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 33 | |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 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 | ##----------------## |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 47 | declare dst='.venv' # "vst_venv" |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 48 | declare src="staging" |
| 49 | declare pat="patches" |
| 50 | |
| 51 | ## ----------------------- |
| 52 | ## Slurp available patches |
| 53 | ## ----------------------- |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 54 | pushd "$pat" >/dev/null |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 55 | readarray -t fyls < <(find . -name 'patch' -print) |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 56 | popd >/dev/null |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 57 | |
| 58 | if [ $# -eq 0 ]; then set -- apply; fi |
| 59 | |
| 60 | while [ $# -gt 0 ]; do |
| 61 | opt="$1"; shift |
| 62 | case "$opt" in |
| 63 | |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 64 | -*help) show_help ;; |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 65 | -*venv) dst="$1"; shift ;; |
| 66 | |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 67 | apply) |
| 68 | pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; } |
| 69 | for fyl in "${fyls[@]}"; |
| 70 | do |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 71 | path="${fyl%/*}" |
| 72 | |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 73 | # Conditional install, jenkins may not support interpreter yet. |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 74 | if [ ! -e "$path" ]; then |
| 75 | echo "[SKIP] $path" |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 76 | continue |
| 77 | fi |
| 78 | |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 79 | echo "[APPLY] $path" |
| 80 | patch -R -p1 < "../$pat/${path}/patch" |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 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 | ;; |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 101 | |
| 102 | help) show_help ;; |
| 103 | |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 104 | *) |
| 105 | echo "ERROR: Unknown action [$opt]" |
| 106 | exit 1 |
| 107 | ;; |
| 108 | esac |
Joey Armstrong | f88b738 | 2022-12-02 15:04:21 -0500 | [diff] [blame] | 109 | |
| 110 | echo |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 111 | done |
| 112 | |
| 113 | # [EOF] |