Skip to content
File

Blob: tools/unix/fix-copyrights.sh

bash43 lines
1#!/bin/sh
2 
3# Copyright (c) ${date_range} Cloudflare, Inc.
4# Licensed under the Apache 2.0 license found in the LICENSE file or at:
5# https://opensource.org/licenses/Apache-2.0
6 
7SCRIPT_DIR=$(realpath $(dirname "$0"))/../..
8CURRENT_YEAR=$(date +"%Y")
9 
10function copyright() {
11 local source_file="$1"
12 local date_range="$2"
13 local wip_file=$(mktemp -t $(basename "${source_file}"))
14 cat <<EOF > "${wip_file}"
15// Copyright (c) ${date_range} Cloudflare, Inc.
16// Licensed under the Apache 2.0 license found in the LICENSE file or at:
17// https://opensource.org/licenses/Apache-2.0
18
19EOF
20 cat "${source_file}" >> "${wip_file}"
21 mv "${wip_file}" "${source_file}"
22}
23 
24cd "${SCRIPT_DIR}"
25for source_file in $(find . -name '*.c++' -o -name '*.h' -o -name '*.ts' -o -name '*.js') ; do
26 if grep -Liq copyright "${source_file}" ; then
27 continue
28 fi
29 if [[ "${source_file}" = *"node"* ]]; then
30 continue
31 fi
32 commit=$(git log --oneline --format="%as %h %s" --reverse ${source_file} | head -1)
33 commit_date=$(echo ${commit}| sed -e 's/ .*//')
34 commit_year=$(echo ${commit_date}| sed -e 's/-.*//')
35 if [ "${commit_date}" = "2022-09-13" -o "${commit_date}" = "2022-09-19" ]; then
36 copyright "${source_file}" "2017-2023"
37 elif [ "${commit_year}" = "${CURRENT_YEAR}" ]; then
38 copyright "${source_file}" "${CURRENT_YEAR}"
39 else
40 copyright "${source_file}" "${commit_year}-${CURRENT_YEAR}"
41 fi
42done