blob: e02a75c66896959fcf1ed35b12eb2c6784019a81 [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001#!/bin/bash
2# -----------------------------------------------------------------------
3# Copyright 2022 Open Networking Foundation
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
18set -euo pipefail
19
20dst="vst_venv"
21src="staging"
22pat="patches"
23
24## Update logic to: find . -name 'patch')
25declare -a fyls=()
26fyls+=('lib/python3.10/site-packages/robot/utils/normalizing.py')
27fyls+=('lib/python3.10/site-packages/robot/utils/robottypes3.py')
28fyls+=('lib/python3.10/site-packages/sphinx/util/typing.py')
29
30echo
31echo "==========================================================================="
32echo "CMD: $0"
33echo "PWD: $(/bin/pwd)"
34echo "ARGV: $*"
35echo "==========================================================================="
36
37if [ $# -eq 0 ]; then set -- apply; fi
38
39while [ $# -gt 0 ]; do
40 opt="$1"; shift
41 case "$opt" in
42
43 -*venv) dst="$1"; shift ;;
44
45 help)
46 cat <<EOH
47apply - generate patches from vault source.
48backup - Archive patch directory
49gather - collect potential python files to edit.
50EOH
51 ;;
52
53 apply)
54 pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; }
55 for fyl in "${fyls[@]}";
56 do
57 # Conditional install, jenkins may not support interpreter yet.
58 if [ ! -e "$fyl" ]; then
59 echo "[SKIP] $fyl"
60 continue
61 fi
62
63 echo "[APPLY] $fyl"
64 patch -R -p1 < "../$pat/$fyl/patch"
65 done
66 popd >/dev/null || { echo "popd $dst failed"; exit 1; }
67 ;;
68
69 backup)
70 mkdir ~/backups
71 pushd "$src" || { echo "pushd $dst failed"; exit 1; }
72 tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}"
73 popd || { echo "popd $dst failed"; exit 1; }
74 ;;
75
76 gather)
77 for fyl in "${fyls[@]}";
78 do
79 patchDir="$pat/$fyl"
80 mkdir -p "$patchDir"
81 diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch"
82 done
83 find "$pat" -print
84 ;;
85
86 *)
87 echo "ERROR: Unknown action [$opt]"
88 exit 1
89 ;;
90 esac
91done
92
93# [EOF]