Skip to content

Commit

Permalink
New license headers: Remaining enterprise/ and docker/ + script updat…
Browse files Browse the repository at this point in the history
…e (CMK-1073)

Change-Id: I6e45d87845de6f51f4c486b7241ae4d2077cf139
  • Loading branch information
oKenneth committed Mar 6, 2020
1 parent 96fd491 commit 3cf8eb2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
44 changes: 31 additions & 13 deletions doc/helpers/headrify
Expand Up @@ -16,8 +16,12 @@ header ()

headrify ()
{
if [[ ! -f "$file" || -L "$file" ]]; then
echo "Skipping $file. It's not a file / It is a symlink."
if [ ! -f "$file" ]; then
echo "Skipping $file. It's not a file."
return
fi
if [ -L "$file" ]; then
echo "Skipping $file. It's a symlink."
return
fi

Expand All @@ -31,6 +35,9 @@ headrify ()
if [ "${headline:0:9}" = "#!/bin/sh" ] ; then
comment="# "
bangpath="#!/bin/sh"
if [ "${headline:9}" != "" ] ; then
bangpath="$bangpath${headline:9}"
fi
elif [ "${headline:0:16}" = "#!/usr/bin/ksh93" ] ; then
comment="# "
bangpath="#!/usr/bin/ksh93"
Expand All @@ -40,12 +47,15 @@ headrify ()
elif [ "${headline:0:11}" = "#!/bin/bash" ] ; then
comment="# "
bangpath="#!/bin/bash"
if [ "${headline:11}" != "" ] ; then
bangpath="$bangpath${headline:11}"
fi
elif [ "${headline:0:15}" = "#!/usr/bin/bash" ] ; then
comment="# "
bangpath="#!/usr/bin/bash"
elif [ "${headline:0:14}" = "#!/usr/bin/php" ] ; then
elif [ "${headline:0:5}" = "<?php" ] ; then
comment="# "
bangpath="#!/usr/bin/php"
bangpath="<?php"
elif [[ "${headline:0:22}" = "#!/usr/bin/env python3" || "${headline:0:18}" = "#!/usr/bin/python3" ]] ; then
comment="# "
bangpath="#!/usr/bin/env python3
Expand All @@ -69,8 +79,10 @@ headrify ()
*.sh) comment="# " ;;
*.py) comment="# " ; bangpath="#!/usr/bin/env python
# -*- coding: utf-8 -*-"; ;;
*) echo "Skipping $file. No shebang or suffix match for Python, C/C++, JS, (S)CSS or Shell Script nor a Makefile." ;
return ;;
*) if [ "$force" = false ]; then
echo "Skipping $file. No shebang or suffix match for Python, C/C++, JS, (S)CSS or Shell Script nor a Makefile."
return
fi ;;
esac
fi

Expand All @@ -79,9 +91,9 @@ headrify ()
suffix="${file##*.}"
if ! [[ $suffix == "py" || $suffix == "h" || $suffix == "c" || $suffix == "cc" || \
$suffix == "js" || $suffix == "scss" || $suffix == "css" || $file == *"Makefile" || \
$suffix == "sh" || $suffix == "cfg" ]];
$suffix == "sh" || $suffix == "cfg" || $suffix == "php" ]];
then
echo "Skipping $file. It's not a source code file in Python, C/C++, JS, (S)CSS or Shell Script nor a Makefile."
echo "Skipping $file. It's not a source code file in Python, C/C++, JS, (S)CSS, PHP or Shell Script nor a Makefile."
return
fi
fi
Expand All @@ -93,8 +105,11 @@ headrify ()
TMP=$(mktemp .headrify.new.XXXXXX)
chmod --reference=$file $TMP
: > $TMP
if [ -n "$bangpath" ]; then echo "$bangpath" > $TMP ; fi
if [[ $file == "enterprise/"* || $file == "managed/"* ]]; then
if [[ "$(head -n1 $file | sed -n "/^\xEF\xBB\xBF/ p")" ]]; then
printf "\xEF\xBB\xBF" > $TMP
fi
if [ -n "$bangpath" ]; then echo "$bangpath" >> $TMP ; fi
if [[ "$(realpath $file)" == *"/enterprise/"* || "$(realpath $file)" == *"/managed/"* ]]; then
header $CEE_LICENSE_NAME | sed "s@^@$comment@" | sed 's/ *$//' >> $TMP
else
header $CRE_LICENSE_NAME | sed "s@^@$comment@" | sed 's/ *$//' >> $TMP
Expand All @@ -104,18 +119,19 @@ headrify ()
count=0
tmpwritten=false
while read line; do
if [[ "$line" == *"$up2dateline"* || "$line" == *"$figletline"* ]]; then
if [[ ("$line" == *"$up2dateline"* || "$line" == *"$figletline"*) && "$(sed -rn "/$endline/I p" $file)" ]]; then
# Delete all lines until and including $endline, then also remove all
# leading # blank lines as well as a possible multiline comment ending
# tag '*/' from the beginning of $file and append the result to $TMP
sed -i "1s/^\xEF\xBB\xBF//" $file
sed -r '0,/^'"$endline"'$/Id' $file | sed '/./,$!d' | sed '1{/^\*\/$/d}' | sed '/./,$!d' >> $TMP
tmpwritten=true
break
elif [[ "$(echo "$line" | sed -n '/tribe29/ !p' | sed -n '/copyright/I p')" ]]; then
elif [[ "$(echo "$line" | sed -n '/copyright/I p' | sed -n '/tribe29/ !p')" ]]; then
echo "Skipping $file because it seems to hold a non tribe29 copyright notice already."
rm -f $TMP
return
elif [[ ( $count == $bangpathlines ) && ( "$bangpath" == *"$line"* || "$line" = *"coding: utf-8"* ) ]]; then
elif [[ ( $count == $bangpathlines ) && ( "$bangpath" == *"$line"* || "$line" = *"coding: utf-8"* || "$line" = "#!/usr/bin/python"* ) ]]; then
let bangpathlines=bangpathlines+1
fi

Expand All @@ -128,8 +144,10 @@ headrify ()
if [ "$tmpwritten" = false ]; then
if [ $bangpathlines -gt 0 ]; then
let tailindex=bangpathlines+1
sed -i "1s/^\xEF\xBB\xBF//" $file
tail -n +$tailindex "$file" >> $TMP
else
sed -i "1s/^\xEF\xBB\xBF//" $file
cat $file >> $TMP
fi
fi
Expand Down
27 changes: 4 additions & 23 deletions docker/Makefile
@@ -1,26 +1,7 @@
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

#

include ../defines.make
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-entrypoint.sh
@@ -1,4 +1,8 @@
#!/bin/bash
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

set -e -o pipefail

HOOKROOT=/docker-entrypoint.d
Expand Down

0 comments on commit 3cf8eb2

Please sign in to comment.