Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / doc / helpers / headrify
blobc6e383b8b5e7bdb1897e7501eb5057f8c1b2d61e
1 #!/bin/bash
2 VERSION=$(sed -rn 's/^VERSION[[:space:]]*= *([0-9]+\.[0-9]+\.[0-9a-z]+).*/\1/p' < Makefile)
4 # figlet -f small macht einen kleinen Font
5 header ()
7 echo '+------------------------------------------------------------------+'
9 figlet -w 66 -c "Check_MK" | tr ' ' @ | sed '$d' | \
10 while read -r line
12 printf "|%-66s|\n" "${line//@/ }"
13 done
14 echo '| |'
15 echo '| Copyright Mathias Kettner 2014 mk@mathias-kettner.de |'
16 echo '+------------------------------------------------------------------+'
18 cat <<EOF
20 This file is part of Check_MK.
21 The official homepage is at http://mathias-kettner.de/check_mk.
23 check_mk is free software; you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by
25 the Free Software Foundation in version 2. check_mk is distributed
26 in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
27 out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
28 PARTICULAR PURPOSE. See the GNU General Public License for more de-
29 tails. You should have received a copy of the GNU General Public
30 License along with GNU Make; see the file COPYING. If not, write
31 to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
32 Boston, MA 02110-1301 USA.
33 EOF
34 if [ -n "$lastline" ] ; then
35 echo
36 echo "$lastline"
40 headrify ()
42 if [ ! -f "$file" ] ; then
43 echo "Skipping $file. It's not a file."
44 return
47 if [[ "${file##*/}" =~ ^[A-Z]+$ ]]; then
48 echo "skipping $file. It's a documentation file."
49 return
52 echo "$file..."
53 PERMISSIONS=$(stat -c %a "$file")
54 TMP=$(mktemp .headrify.new.XXXXXX)
55 suffix="${file##*.}"
56 suffix="${suffix##*/}"
57 headline="$(head -n1 $file)"
58 if [ "${headline:0:9}" = "#!/bin/sh" ] ; then
59 comment="# "
60 bangpath="#!/bin/sh"
61 elif [ "${headline:0:16}" = "#!/usr/bin/ksh93" ] ; then
62 comment="# "
63 bangpath="#!/usr/bin/ksh93"
64 elif [ "${headline:0:14}" = "#!/usr/bin/ksh" ] ; then
65 comment="# "
66 bangpath="#!/usr/bin/ksh"
67 elif [ "${headline:0:11}" = "#!/bin/bash" ] ; then
68 comment="# "
69 bangpath="#!/bin/bash"
70 elif [ "${headline:0:15}" = "#!/usr/bin/bash" ] ; then
71 comment="# "
72 bangpath="#!/usr/bin/bash"
73 elif [ "${headline:0:14}" = "#!/usr/bin/php" ] ; then
74 comment="# "
75 bangpath="#!/usr/bin/pnp"
76 else
77 bangpath=""
78 case "${file##*/}" in
79 *.openvms) comment='$!# ' ;;
80 *.php) comment="# " ; bangpath="<?php"; ;;
81 *.css) comment="" ; bangpath="/*"; lastline="*/" ;;
82 *.h|*.c|*.cc|*.h.in|*.js) comment="// " ;;
83 *.conf|*.cfg) comment="# " ;;
84 *.spec|Makefile*) comment="# " ;;
85 *.py|*) comment="# " ; bangpath="#!/usr/bin/env python
86 # -*- encoding: utf-8; py-indent-offset: 4 -*-"; ;;
87 esac
90 : > $TMP
91 if [ -n "$bangpath" ] ; then echo "$bangpath" > $TMP ; fi
92 header | sed "s@^@$comment@" | sed 's/ *$//' >> $TMP
93 echo >> $TMP
94 firstline="$(head -n1 < $file)"
95 secondline="$(sed -n 2p < $file)"
96 thirdline="$(sed -n 3p < $file)"
97 shouldbe="$comment+---------------------------------------------------"
98 endline='.*(Boston, MA 02110-1301 USA.|address provided at www.mathias-kettner.de)'
100 if [ -n "$lastline" ] ; then endline="${lastline//\//\/}" ; fi
101 if [ "${firstline:0:20}" = "${shouldbe:0:20}" \
102 -o "${secondline:0:20}" = "${shouldbe:0:20}" \
103 -o "${thirdline:0:20}" = "${shouldbe:0:20}" ] ; then
104 sed -r '0,/^'"$endline"'$/d' $file | sed 1d >> $TMP
105 else
106 cat $file >> $TMP
108 mv $TMP $file || rm -f $TMP
109 chmod $PERMISSIONS "$file"
112 echo "Headrifying to version $VERSION"
114 if [ "$#" -gt 0 ] ; then
115 for file in "$@"
117 headrify "$file"
118 done
119 else
120 { find -not -type l -and \
121 -not -name "jquery*" \
122 -not -name "*.rc" \
123 -not -name "*.rc.in" \
124 -not -name "ltmain.sh" \
125 -not -name "*.exe" \
126 -and \( \
127 -name "Makefile" -or \
128 -name "*.cfg" -or \
129 -name "Makefile.am" -or \
130 -name "configure.ac" -or \
131 -name "*.in" -or \
132 -name "*.h" -or \
133 -name "*.cc" -or \
134 -name "*.c" -or \
135 -name "*.js" -or \
136 -name "*.py" -or \
137 -name "*.php" -or \
138 -name "*.sh" -or \
139 -name "*.spec" \) ; \
140 rm -f checks/*~ ; ls checks/* ; \
141 echo agents/plugins/* agents/special/* agents/* \
142 | tr ' ' \\n \
143 | grep -vx agents/waitmax \
144 | fgrep -v windows \
145 | fgrep -v .exe \
146 | fgrep -v .deb \
147 | fgrep -v .rpm \
148 | fgrep -v windows/plugins ; \
149 ls agents/windows/*.cc ;
150 echo agents/windows/Makefile ;
152 | egrep -v 'livestatus/nagios4?/' \
153 | grep -v 'agents/cfg_examples' \
154 | grep -vx '' \
156 while read file
158 headrify "$file" &
159 done
161 sleep 0.1
162 wait