Merge "Update releng/global-jjb repository information"
[releng/builder.git] / scripts / branch_cut / branch_cutter.sh
1 #!/bin/bash
2
3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2017 The Linux Foundation and others.
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Eclipse Public License v1.0
9 # which accompanies this distribution, and is available at
10 # http://www.eclipse.org/legal/epl-v10.html
11 #
12 ##############################################################################
13
14 # List of files exclude
15 declare -a excludes=("releng-defaults.yaml"
16                      "releng-macros.yaml")
17
18 TEMP="/tmp/tmp.yaml"
19 mod=0
20 count=0
21
22 function usage {
23     echo "Usage: $(basename $0) options (-n [next release]) (-c [current release]) (-p [previous release]) -h for help";
24     exit 1;
25 }
26
27 if ( ! getopts ":n:c:p:h" opt ); then
28     usage;
29 fi
30
31 while getopts ":n:c:p:h" opt; do
32     case $opt in
33         n)
34             new_reltag=$OPTARG
35             ;;
36         c)
37             curr_reltag=$OPTARG
38             ;;
39         p)
40             prev_reltag=$OPTARG
41             ;;
42         \?)
43             echo "Invalid option: -$OPTARG" >&2
44             exit 1
45             ;;
46         h)
47             usage
48             ;;
49         :)
50             echo "Option -$OPTARG requires an argument." >&2
51             exit 1
52             ;;
53     esac
54 done
55
56 echo "Start Branch Cutting:"
57
58 while IFS="" read -r y; do
59     found=0
60     for f in "${excludes[@]}"; do
61         if [[ $y =~ $f && $found -eq 0 ]]; then
62             found=1
63             break
64         fi
65     done
66     if [[ $found -eq 1 ]]; then
67         echo "Ignore file $y found in excludes list"
68     else
69         ./branch_cut.awk -v new_reltag="$new_reltag" -v curr_reltag="$curr_reltag" -v prev_reltag="$prev_reltag" "$y" > "$TEMP"
70         [[ ! -s "$TEMP" ]] && echo "$y: excluded"
71         [[ -s "$TEMP" ]] && mv "$TEMP" "$y" && echo "$y: Done" && let "mod++"
72         let "count++"
73     fi
74 done < <(find ../../jjb -name "*.yaml")
75
76 echo "Modified $mod out of $count files"
77 echo "Completed"