blob: 33d330d0a418e801f94a37d110a18952fbd403b6 [file] [log] [blame]
Joey Armstronge6a99912023-09-15 14:47:51 -04001#!/bin/bash
2# -----------------------------------------------------------------------
Joey Armstrongdc04c932024-04-01 12:14:21 -04003# Copyright 2022-2024 Open Networking Foundation Contributors
Joey Armstronge6a99912023-09-15 14:47:51 -04004#
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 Armstrongdc04c932024-04-01 12:14:21 -04009# http:#www.apache.org/licenses/LICENSE-2.0
Joey Armstronge6a99912023-09-15 14:47:51 -040010#
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 Armstrongdc04c932024-04-01 12:14:21 -040017# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Intent:
21# -----------------------------------------------------------------------
Joey Armstronge6a99912023-09-15 14:47:51 -040022
23##-------------------##
24##---] GLOBALS [---##
25##-------------------##
26set -euo pipefail
27
28## -----------------------------------------------------------------------
29## Intent: Display script documentation.
30## -----------------------------------------------------------------------
31function show_help()
32{
33 cat <<EOH
34Usage: $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
42See Also
43 patches/README.md Howto create a patch file.
44
45EOH
46 exit 0
47}
48
49##----------------##
50##---] MAIN [---##
51##----------------##
52declare dst='.venv' # "vst_venv"
53declare src="staging"
54declare pat="patches"
55
56## -----------------------
57## Slurp available patches
58## -----------------------
59pushd "$pat" >/dev/null
60readarray -t fyls < <(find . -name 'patch' -print)
61popd >/dev/null
62
63if [ $# -eq 0 ]; then set -- apply; fi
64
65while [ $# -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
116done
117
118# [EOF]