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