-
Notifications
You must be signed in to change notification settings - Fork 16
/
giveheader
executable file
·61 lines (52 loc) · 1.63 KB
/
giveheader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash -e
function usage () {
cat <<EOF
Usage: giveheader AUTHOR MAINTAINER file1.cc file2.h ...
Example: giveheader "Mathias Kettner <kettner@suse.de>" "Harri Hirsch <harri@hirsch.to"
EOF
exit 5
}
AUTHOR="$1"
if [ -z "$AUTHOR" ] ; then
usage
fi
shift
MAINTAINER="$1"
if [ -z "$MAINTAINER" ] ; then
usage
fi
shift
for file in $*
do
TMPFILE=$(mktemp /tmp/giveheader.XXXXXX) || exit 1
if [ ! -r "$file" ] ; then
echo "$file: no such file" >&2
continue;
fi
echo -n "$file..." >&2
FILENAME=${file##*/}
cat <<EOF > $TMPFILE
/*---------------------------------------------------------------------\\
| |
| __ __ ____ _____ ____ |
| \ \ / /_ _/ ___|_ _|___ \ |
| \ V / _\` \___ \ | | __) | |
| | | (_| |___) || | / __/ |
| |_|\__,_|____/ |_| |_____| |
| |
| core system |
| (C) SuSE GmbH |
\\----------------------------------------------------------------------/
File: $FILENAME
Author: $AUTHOR
Maintainer: $MAINTAINER
/-*/
EOF
if fgrep -q '/-*/' $file ; then
sed '1,/\/-\*\//d' $file >> $TMPFILE
else
cat $file >> $TMPFILE
fi
cp $TMPFILE $file.new && mv $file.new $file && echo "OK" >&2
rm -f $TMPFILE
done