blob: 12d7ca83eebc2b1d59b9ff02b1f61888de1727f7 [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
Joey Armstrong36592e32022-11-28 09:00:28 -050024declare -a fyls=()
Joey Armstrongf88b7382022-12-02 15:04:21 -050025pushd "$pat" >/dev/null
26fyls+=( $(find . -name 'patch' -print) )
27popd >/dev/null
Joey Armstrong36592e32022-11-28 09:00:28 -050028
29if [ $# -eq 0 ]; then set -- apply; fi
30
31while [ $# -gt 0 ]; do
32 opt="$1"; shift
33 case "$opt" in
34
35 -*venv) dst="$1"; shift ;;
36
37 help)
38 cat <<EOH
39apply - generate patches from vault source.
40backup - Archive patch directory
41gather - collect potential python files to edit.
42EOH
43 ;;
44
45 apply)
46 pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; }
47 for fyl in "${fyls[@]}";
48 do
Joey Armstrongf88b7382022-12-02 15:04:21 -050049 path="${fyl%/*}"
50
Joey Armstrong36592e32022-11-28 09:00:28 -050051 # Conditional install, jenkins may not support interpreter yet.
Joey Armstrongf88b7382022-12-02 15:04:21 -050052 if [ ! -e "$path" ]; then
53 echo "[SKIP] $path"
Joey Armstrong36592e32022-11-28 09:00:28 -050054 continue
55 fi
56
Joey Armstrongf88b7382022-12-02 15:04:21 -050057 echo "[APPLY] $path"
58 patch -R -p1 < "../$pat/${path}/patch"
Joey Armstrong36592e32022-11-28 09:00:28 -050059 done
60 popd >/dev/null || { echo "popd $dst failed"; exit 1; }
61 ;;
62
63 backup)
64 mkdir ~/backups
65 pushd "$src" || { echo "pushd $dst failed"; exit 1; }
66 tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}"
67 popd || { echo "popd $dst failed"; exit 1; }
68 ;;
69
70 gather)
71 for fyl in "${fyls[@]}";
72 do
73 patchDir="$pat/$fyl"
74 mkdir -p "$patchDir"
75 diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch"
76 done
77 find "$pat" -print
78 ;;
79
80 *)
81 echo "ERROR: Unknown action [$opt]"
82 exit 1
83 ;;
84 esac
Joey Armstrongf88b7382022-12-02 15:04:21 -050085
86 echo
Joey Armstrong36592e32022-11-28 09:00:28 -050087done
88
89# [EOF]