• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Author: Dodji Seketeli <dodji@redhat.com>
4
5from_license_id=
6to_license_id=
7input_file=
8prog=$0
9
10display_usage()
11{
12    echo "$prog: [options] --from <from-spdx-license-id> --to <to-spdx-license-id> <file>"
13    echo "  where options can be:"
14    echo "   -h|--h		display this help"
15}
16
17main()
18{
19    header=$(head --lines=5 $input_file | grep "SPDX-License-Identifier:")
20    if test "x$header" != x; then
21	license=$(echo "$header" | sed -r "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/")
22    fi
23
24    if test "x$license" != x -a "$license" = "$from_license_id"; then
25	sed -i -r "s/$from_license_id/$to_license_id/" $input_file
26	exit 0
27    fi
28
29    exit 1
30}
31
32# This program takes at least 5 arguments
33if test $# -lt 5; then
34    >&2 display_usage
35    exit 1
36fi
37
38# Parse parameters
39while test $# -gt 1; do
40    case "$1" in
41	-h|--h)
42	    display_usage
43	    exit 0
44	    ;;
45
46	-f|--from)
47	    from_license_id=$2
48	    shift
49	    ;;
50
51	-t|--to)
52	    to_license_id=$2
53	    shift
54	    ;;
55
56	-*)
57	    >&2 display_usage
58	    exit 1
59	    ;;
60
61	*)
62	    input_file="$1"
63	    ;;
64    esac
65    shift
66done
67
68if test $# -lt 1; then
69    >&2 display_usage
70    exit 1
71fi
72
73input_file=$1
74
75main
76