blob: 608249af2709762b473059b9db47ecbafe4c7446 [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001#!/bin/bash
2# -----------------------------------------------------------------------
Joey Armstrong8388b7f2023-01-23 11:20:04 -05003# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong36592e32022-11-28 09:00:28 -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 Armstronga8bc8e12022-12-04 07:06:59 -050018##-------------------##
19##---] GLOBALS [---##
20##-------------------##
Joey Armstrong36592e32022-11-28 09:00:28 -050021set -euo pipefail
22
Joey Armstronga8bc8e12022-12-04 07:06:59 -050023## -----------------------------------------------------------------------
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 Armstrong36592e32022-11-28 09:00:28 -050033
Joey Armstronga8bc8e12022-12-04 07:06:59 -050034 --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="vst_venv"
48declare src="staging"
49declare pat="patches"
50
51## -----------------------
52## Slurp available patches
53## -----------------------
Joey Armstrongf88b7382022-12-02 15:04:21 -050054pushd "$pat" >/dev/null
Joey Armstronga8bc8e12022-12-04 07:06:59 -050055readarray -t fyls < <(find . -name 'patch' -print)
Joey Armstrongf88b7382022-12-02 15:04:21 -050056popd >/dev/null
Joey Armstrong36592e32022-11-28 09:00:28 -050057
58if [ $# -eq 0 ]; then set -- apply; fi
59
60while [ $# -gt 0 ]; do
61 opt="$1"; shift
62 case "$opt" in
63
Joey Armstronga8bc8e12022-12-04 07:06:59 -050064 -*help) show_help ;;
Joey Armstrong36592e32022-11-28 09:00:28 -050065 -*venv) dst="$1"; shift ;;
66
Joey Armstrong36592e32022-11-28 09:00:28 -050067 apply)
68 pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; }
69 for fyl in "${fyls[@]}";
70 do
Joey Armstrongf88b7382022-12-02 15:04:21 -050071 path="${fyl%/*}"
72
Joey Armstrong36592e32022-11-28 09:00:28 -050073 # Conditional install, jenkins may not support interpreter yet.
Joey Armstrongf88b7382022-12-02 15:04:21 -050074 if [ ! -e "$path" ]; then
75 echo "[SKIP] $path"
Joey Armstrong36592e32022-11-28 09:00:28 -050076 continue
77 fi
78
Joey Armstrongf88b7382022-12-02 15:04:21 -050079 echo "[APPLY] $path"
80 patch -R -p1 < "../$pat/${path}/patch"
Joey Armstrong36592e32022-11-28 09:00:28 -050081 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 Armstronga8bc8e12022-12-04 07:06:59 -0500101
102 help) show_help ;;
103
Joey Armstrong36592e32022-11-28 09:00:28 -0500104 *)
105 echo "ERROR: Unknown action [$opt]"
106 exit 1
107 ;;
108 esac
Joey Armstrongf88b7382022-12-02 15:04:21 -0500109
110 echo
Joey Armstrong36592e32022-11-28 09:00:28 -0500111done
112
113# [EOF]