blob: 5155768348e0f34e67e8ec9d8a5e9c2c7237632e [file] [log] [blame]
Joey Armstrong6f63edf2024-01-12 11:30:08 -05001#!/bin/bash
2# -----------------------------------------------------------------------
Joey Armstronga9deb692023-06-30 18:13:01 -04003# Copyright 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong6f63edf2024-01-12 11:30:08 -05004#
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##-------------------##
21set -euo pipefail
22
23## -----------------------------------------------------------------------
24## Intent: Display script documentation.
25## -----------------------------------------------------------------------
26function show_help()
27{
28 cat <<EOH
29Usage: $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
37See Also
38 patches/README.md Howto create a patch file.
39
40EOH
41 exit 0
42}
43
44##----------------##
45##---] MAIN [---##
46##----------------##
47declare dst='.venv' # "vst_venv"
48declare src="staging"
49declare pat="patches"
50
51## -----------------------
52## Slurp available patches
53## -----------------------
54pushd "$pat" >/dev/null
55readarray -t fyls < <(find . -name 'patch' -print)
56popd >/dev/null
57
58if [ $# -eq 0 ]; then set -- apply; fi
59
60while [ $# -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
111done
112
113# [EOF] - 20231222: Ignore, this triage patch will be abandoned