]>
Commit | Line | Data |
---|---|---|
ac37fd5e | 1 | #!/usr/bin/env bash |
85b00dcf VJ |
2 | # |
3 | # Script to setup a new decoder. | |
4 | # Written by Victor Julien <victor@inliniac.net> | |
5 | # | |
6 | ||
7 | set -e | |
8 | #set -x | |
9 | ||
10 | function Usage { | |
11 | echo | |
12 | echo "$(basename $0) -- script to provision a decoder. The script" | |
13 | echo "makes a copy of the decode-template, sets the name and updates" | |
14 | echo " the build system." | |
15 | echo | |
16 | echo "Call from the 'src' directory, with one argument: the decoder name." | |
17 | echo | |
18 | echo "E.g. inside 'src': ../scripts/$(basename $0) ipv7" | |
19 | echo | |
20 | } | |
21 | ||
22 | function Done { | |
23 | echo | |
24 | echo "Decoder $NR has been set up in $FILE_C and $FILE_H and the" | |
25 | echo "build system has been updated." | |
26 | echo | |
27 | echo "The decoder should now compile cleanly. Try running 'make'." | |
28 | echo | |
29 | echo "Next steps are to edit the files to implement the actual" | |
30 | echo "decoding of $NR." | |
31 | echo | |
32 | } | |
33 | ||
d1ac8393 JI |
34 | # Make sure we are running from the correct directory. |
35 | set_dir() { | |
36 | if [ -e ./suricata.c ]; then | |
37 | # Do nothing. | |
38 | true | |
39 | elif [ -e ./src/suricata.c ]; then | |
40 | cd src | |
41 | else | |
42 | echo "error: this does not appear to be a suricata source directory." | |
43 | exit 1 | |
44 | fi | |
45 | } | |
46 | ||
85b00dcf VJ |
47 | if [ $# -ne "1" ]; then |
48 | Usage | |
49 | echo "ERROR: call with one argument" | |
50 | exit 1 | |
51 | fi | |
52 | ||
53 | INPUT=$1 | |
54 | # lowercase | |
55 | LC=${INPUT,,} | |
56 | #echo $LC | |
57 | # UPPERCASE | |
58 | UC=${LC^^} | |
59 | #echo $UC | |
60 | # Normal | |
61 | NR=${LC^} | |
62 | #echo $NR | |
63 | ||
64 | FILE_C="decode-${LC}.c" | |
65 | FILE_H="decode-${LC}.h" | |
66 | #echo $FILE_C | |
67 | #echo $FILE_H | |
68 | ||
d1ac8393 JI |
69 | set_dir |
70 | ||
85b00dcf VJ |
71 | if [ ! -e decode-template.c ] || [ ! -e decode-template.h ]; then |
72 | Usage | |
73 | echo "ERROR: input files decode-template.c and/or decode-template.h are missing" | |
74 | exit 1 | |
75 | fi | |
76 | if [ -e $FILE_C ] || [ -e $FILE_H ]; then | |
77 | Usage | |
78 | echo "ERROR: file(s) $FILE_C and/or $FILE_H already exist, won't overwrite" | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | cp decode-template.c $FILE_C | |
83 | cp decode-template.h $FILE_H | |
84 | ||
85 | # search and replaces | |
86 | sed -i "s/TEMPLATE/${UC}/g" $FILE_C | |
87 | sed -i "s/TEMPLATE/${UC}/g" $FILE_H | |
88 | sed -i "s/Template/${NR}/g" $FILE_C | |
89 | sed -i "s/Template/${NR}/g" $FILE_H | |
90 | sed -i "s/template/${LC}/g" $FILE_C | |
91 | sed -i "s/template/${LC}/g" $FILE_H | |
92 | sed -i "s/decode-template.c decode-template.h \\\/decode-template.c decode-template.h \\\\\n${FILE_C} ${FILE_H} \\\/g" Makefile.am | |
93 | ||
499afaba VJ |
94 | ed -s decode.h > /dev/null <<EOF |
95 | /^int DecodeTEMPLATE | |
96 | t- | |
97 | s/DecodeTEMPLATE/Decode${UC}/g | |
98 | w | |
99 | EOF | |
100 | ||
101 | ||
85b00dcf VJ |
102 | Done |
103 | exit 0 |