blob: 821d2c63cf0f47bf4fddee38bfbc54c3ff4c377b [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
20dst="vst_venv"
21src="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
48 apply)
49 pushd "$dst" || { echo "pushd $dst failed"; exit 1; }
50 for fyl in "${fyls[@]}";
51 do
52 # Conditional install, jenkins may not support interpreter yet.
53 if [ ! -e "$fyl" ]; then
54 echo "[SKIP] No venv file to patch: $fyl"
55 continue
56 fi
57
58 echo "$fyl"
59 patch -R -p1 < "../$pat/$fyl/patch"
60 done
61 popd || { echo "popd $dst failed"; exit 1; }
62 ;;
63
64 backup)
65 mkdir ~/backups
66 pushd "$src" || { echo "pushd $dst failed"; exit 1; }
67 tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}"
68 popd || { echo "popd $dst failed"; exit 1; }
69 ;;
70
71 gather)
72 set -x
73 for fyl in "${fyls[@]}";
74 do
75 patchDir="$pat/$fyl"
76 mkdir -p "$patchDir"
77 diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch"
78 done
79 find "$pat" -print
80 set +x
81 ;;
82
83 *)
84 echo "ERROR: Unknown action [$opt]"
85 exit 1
86 ;;
87 esac
88done
89
90# [EOF]