]>
git.ipfire.org Git - people/ms/suricata.git/blob - scripts/setup-simple-detect2.sh
3 # Script to setup a new 'simple' detect module.
4 # Written by Victor Julien <victor@inliniac.net>
12 echo "$(basename $0) -- script to provision a detect module. The script"
13 echo "makes a copy of detect-template, sets the name and updates"
14 echo "the build system."
16 echo "Call from the 'src' directory, with one argument: the detect module"
19 echo "E.g. inside 'src': ../scripts/$(basename $0) helloworld"
25 echo "Detect module $NR has been set up in $FILE_C and $FILE_H"
26 echo "and the build system has been updated."
28 echo "The detect module should now compile cleanly. Try running 'make'."
30 echo "Next steps are to edit the files to implement the actual"
31 echo "detection logic of $NR."
35 # Make sure we are running from the correct directory.
37 if [ -e .
/suricata.c
]; then
40 elif [ -e .
/src
/suricata.c
]; then
43 echo "error: this does not appear to be a suricata source directory."
48 if [ $# -ne "1" ]; then
50 echo "ERROR: call with one argument"
65 FILE_C
="detect-${LC}.c"
66 FILE_H
="detect-${LC}.h"
70 if [ ! -e detect-template2.c
] ||
[ ! -e detect-template2.h
]; then
72 echo "ERROR: input files detect-template.c and/or detect-template.h are missing"
75 if [ -e $FILE_C ] ||
[ -e $FILE_H ]; then
77 echo "ERROR: file(s) $FILE_C and/or $FILE_H already exist, won't overwrite"
81 FILE_C
="tests/detect-${LC}.c"
82 if [ ! -e tests
/detect-template2.c
]; then
84 echo "ERROR: input file tests/detect-template.c is missing"
87 if [ -e $FILE_C ]; then
89 echo "ERROR: file $FILE_C already exist, won't overwrite"
93 FILE_C
="detect-${LC}.c"
94 FILE_H
="detect-${LC}.h"
95 cp detect-template2.c
$FILE_C
96 cp detect-template2.h
$FILE_H
99 sed -i "s/TEMPLATE2/${UC}/g" $FILE_C
100 sed -i "s/TEMPLATE2/${UC}/g" $FILE_H
101 sed -i "s/Template2/${NR}/g" $FILE_C
102 sed -i "s/Template2/${NR}/g" $FILE_H
103 sed -i "s/template2/${LC}/g" $FILE_C
104 sed -i "s/template2/${LC}/g" $FILE_H
106 sed -i "s/detect-template2.c detect-template2.h \\\/detect-template2.c detect-template2.h \\\\\n${FILE_C} ${FILE_H} \\\/g" Makefile.am
109 sed -i "s/DETECT_TEMPLATE2,/DETECT_TEMPLATE2,\\n DETECT_${UC},/g" detect-engine-register.h
111 # add include to detect-engine-register.c
112 sed -i "s/#include \"detect-template2.h\"/#include \"detect-template2.h\"\\n#include \"${FILE_H}\"/g" detect-engine-register.c
114 # add reg func to detect-engine-register.c
115 sed -i "s/DetectTemplate2Register();/DetectTemplate2Register();\\n Detect${NR}Register();/g" detect-engine-register.c
118 FILE_C
="tests/detect-${LC}.c"
119 cp tests
/detect-template2.c
$FILE_C
121 # search and replaces
122 sed -i "s/TEMPLATE2/${UC}/g" $FILE_C
123 sed -i "s/Template2/${NR}/g" $FILE_C
124 sed -i "s/template2/${LC}/g" $FILE_C