blob: b522caa675595472bb8622f1f9327757de64bdda [file] [log] [blame]
Joey Armstrong83874cc2022-11-26 09:40:08 -05001#!/bin/bash
2# -----------------------------------------------------------------------
Joey Armstrong9fadcbe2024-01-17 19:00:37 -05003# Copyright 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong83874cc2022-11-26 09:40: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
Joey Armstronga5278142023-06-28 16:56:54 -040018##-------------------##
19##---] GLOBALS [---##
20##-------------------##
Joey Armstrong83874cc2022-11-26 09:40:08 -050021set -euo pipefail
22
Joey Armstronga5278142023-06-28 16:56:54 -040023## -----------------------------------------------------------------------
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.
Joey Armstrong83874cc2022-11-26 09:40:08 -050033
Joey Armstronga5278142023-06-28 16:56:54 -040034 --venv Installed venv directory to patch (override default)
35 --help This message
Joey Armstrong83874cc2022-11-26 09:40:08 -050036
Joey Armstronga5278142023-06-28 16:56:54 -040037See 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
Joey Armstrong83874cc2022-11-26 09:40:08 -050057
58if [ $# -eq 0 ]; then set -- apply; fi
59
60while [ $# -gt 0 ]; do
61 opt="$1"; shift
62 case "$opt" in
Joey Armstrong83874cc2022-11-26 09:40:08 -050063
Joey Armstronga5278142023-06-28 16:56:54 -040064 -*help) show_help ;;
65 -*venv) dst="$1"; shift ;;
66
Joey Armstrong83874cc2022-11-26 09:40:08 -050067 apply)
Joey Armstronga5278142023-06-28 16:56:54 -040068 pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; }
Joey Armstrong83874cc2022-11-26 09:40:08 -050069 for fyl in "${fyls[@]}";
70 do
Joey Armstronga5278142023-06-28 16:56:54 -040071 path="${fyl%/*}"
72
Joey Armstrong83874cc2022-11-26 09:40:08 -050073 # Conditional install, jenkins may not support interpreter yet.
Joey Armstronga5278142023-06-28 16:56:54 -040074 if [ ! -e "$path" ]; then
75 echo "[SKIP] $path"
Joey Armstrong83874cc2022-11-26 09:40:08 -050076 continue
77 fi
78
Joey Armstronga5278142023-06-28 16:56:54 -040079 echo "[APPLY] $path"
80 patch -R -p1 < "../$pat/${path}/patch"
Joey Armstrong83874cc2022-11-26 09:40:08 -050081 done
Joey Armstronga5278142023-06-28 16:56:54 -040082 popd >/dev/null || { echo "popd $dst failed"; exit 1; }
Joey Armstrong83874cc2022-11-26 09:40:08 -050083 ;;
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)
Joey Armstrong83874cc2022-11-26 09:40:08 -050093 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
Joey Armstrong83874cc2022-11-26 09:40:08 -0500100 ;;
Joey Armstronga5278142023-06-28 16:56:54 -0400101
102 help) show_help ;;
103
Joey Armstrong83874cc2022-11-26 09:40:08 -0500104 *)
105 echo "ERROR: Unknown action [$opt]"
106 exit 1
107 ;;
108 esac
Joey Armstronga5278142023-06-28 16:56:54 -0400109
110 echo
Joey Armstrong83874cc2022-11-26 09:40:08 -0500111done
112
113# [EOF]