1#!/bin/bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2022 Intel Corporation 4# All rights reserved. 5# 6 7( 8 cat << 'END' 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * * Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * * Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * * Neither the name of __COMPANY__ nor the names of its 20 * contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35END 36) > /tmp/c.txt 37 38( 39 cat << 'END' 40# Redistribution and use in source and binary forms, with or without 41# modification, are permitted provided that the following conditions 42# are met: 43# 44# * Redistributions of source code must retain the above copyright 45# notice, this list of conditions and the following disclaimer. 46# * Redistributions in binary form must reproduce the above copyright 47# notice, this list of conditions and the following disclaimer in 48# the documentation and/or other materials provided with the 49# distribution. 50# * Neither the name of __COMPANY__ nor the names of its 51# contributors may be used to endorse or promote products derived 52# from this software without specific prior written permission. 53# 54# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 55# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 56# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 57# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 58# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 59# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 60# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 61# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 62# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 64# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65# 66END 67) > /tmp/makefile.txt 68 69function get_sha() { 70 sha= 71 start=$(cat -n $1 | grep "Redistribution and use" | awk '{print $1}') 72 end=$(cat -n $1 | grep "POSSIBILITY OF SUCH DAMAGE" | head -1 | awk '{print $1}') 73 if [ -z $start ] || [ -z $end ]; then 74 return 75 fi 76 count=$((end - start + 1)) 77 sha=$(sed -n "${start},+${count}p" $1 | sha1sum | awk '{print $1}') 78} 79 80intel_c_sha=$(sed 's/__COMPANY__/Intel Corporation/g' /tmp/c.txt | sha1sum | awk '{print $1}') 81nvidia_c_sha=$(sed 's/__COMPANY__/Nvidia Corporation/g' /tmp/c.txt | sha1sum | awk '{print $1}') 82samsung_c_sha=$(sed 's/__COMPANY__/Samsung Electronics Co., Ltd./g' /tmp/c.txt | sha1sum | awk '{print $1}') 83eideticom_c_sha=$(sed 's/__COMPANY__/Eideticom Inc/g' /tmp/c.txt | sha1sum | awk '{print $1}') 84generic_c_sha=$(sed 's/__COMPANY__/the copyright holder/g' /tmp/c.txt | sha1sum | awk '{print $1}') 85 86for f in $(git ls-files '**/*.c' '**/*.cpp' '**/*.h' '**/*.cc' '**/*.go'); do 87 get_sha $f 88 if [[ $sha == "$intel_c_sha" ]] \ 89 || [[ $sha == "$nvidia_c_sha" ]] \ 90 || [[ $sha == "$samsung_c_sha" ]] \ 91 || [[ $sha == "$eideticom_c_sha" ]] \ 92 || [[ $sha == "$generic_c_sha" ]]; then 93 echo $f 94 sed -i "$((start - 1)),+$((count))d" $f 95 sed -i '1,3d' $f 96 sed -i '1 i /* SPDX-License-Identifier: BSD-3-Clause' $f 97 fi 98 99done 100 101intel_makefile_sha=$(sed 's/__COMPANY__/Intel Corporation/g' /tmp/makefile.txt | sha1sum | awk '{print $1}') 102nvidia_makefile_sha=$(sed 's/__COMPANY__/Nvidia Corporation/g' /tmp/makefile.txt | sha1sum | awk '{print $1}') 103samsung_makefile_sha=$(sed 's/__COMPANY__/Samsung Electronics Co., Ltd./g' /tmp/makefile.txt | sha1sum | awk '{print $1}') 104eideticom_makefile_sha=$(sed 's/__COMPANY__/Eideticom Inc/g' /tmp/makefile.txt | sha1sum | awk '{print $1}') 105generic_makefile_sha=$(sed 's/__COMPANY__/the copyright holder/g' /tmp/makefile.txt | sha1sum | awk '{print $1}') 106 107for f in $(git ls-files CONFIG MAKEFILE '**/*.mk' '**/Makefile'); do 108 get_sha $f 109 if [[ $sha == "$intel_makefile_sha" ]] \ 110 || [[ $sha == "$nvidia_makefile_sha" ]] \ 111 || [[ $sha == "$samsung_makefile_sha" ]] \ 112 || [[ $sha == "$eideticom_makefile_sha" ]] \ 113 || [[ $sha == "$generic_makefile_sha" ]]; then 114 echo $f 115 sed -i "$((start - 1)),+$((count))d" $f 116 sed -i '1,3d' $f 117 sed -i "1 i \# SPDX-License-Identifier: BSD-3-Clause" $f 118 fi 119 120done 121