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