]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
template scripts: allow to be called from top or src
authorJason Ish <ish@unx.ca>
Sun, 1 Oct 2017 09:41:29 +0000 (10:41 +0100)
committerJason Ish <ish@unx.ca>
Sun, 1 Oct 2017 09:41:29 +0000 (10:41 +0100)
Allow the template setup script to be called from the top source
directory or from ./src to unify where they can be executed
from.

scripts/setup-app-layer-detect.sh
scripts/setup-app-layer-logger.sh
scripts/setup-app-layer.sh
scripts/setup-decoder.sh
scripts/setup-simple-detect.sh

index c420e7086b54d3888ed34beafd1a0ef86e387407..abfa4978c568f2af0da0ec33d342936367f23b5f 100755 (executable)
@@ -4,6 +4,12 @@
 
 set -e
 
+# Fail if "ed" is not available.
+if ! which ed > /dev/null 2>&1; then
+    echo "error: the program \"ed\" is required for this script"
+    exit 1
+fi
+
 function usage() {
     cat <<EOF
 
@@ -21,6 +27,19 @@ Examples:
 EOF
 }
 
+# Make sure we are running from the correct directory.
+set_dir() {
+    if [ -e ./suricata.c ]; then
+       cd ..
+    elif [ -e ./src/suricata.c ]; then
+       # Do nothing.
+       true
+    else
+       echo "error: this does not appear to be a suricata source directory."
+       exit 1
+    fi
+}
+
 fail_if_exists() {
     path="$1"
     if test -e "${path}"; then
@@ -119,6 +138,8 @@ w
 EOF
 }
 
+set_dir
+
 protoname="$1"
 buffername="$2"
 
@@ -127,6 +148,26 @@ if [ "${protoname}" = "" ] || [ "${buffername}" = "" ]; then
     exit 1
 fi
 
+# Make sure the protocol name looks like a proper name (starts with a
+# capital letter).
+case "${protoname}" in
+
+    [[:upper:]]*)
+       # OK.
+       ;;
+
+    "")
+       usage
+       exit 1
+       ;;
+
+    *)
+       echo "error: protocol name must beging with an upper case letter"
+       exit 1
+       ;;
+
+esac
+
 protoname_lower=$(printf ${protoname} | tr '[:upper:]' '[:lower:]')
 protoname_upper=$(printf ${protoname} | tr '[:lower:]' '[:upper:]')
 buffername_lower=$(printf ${buffername} | tr '[:upper:]' '[:lower:]')
index f05be59a286756b75df2c8d20a35f105ef4d35e3..fb1070238e1943896b9c1c87f6d441d25c50049d 100755 (executable)
@@ -2,6 +2,12 @@
 
 set -e
 
+# Fail if "ed" is not available.
+if ! which ed > /dev/null 2>&1; then
+    echo "error: the program \"ed\" is required for this script"
+    exit 1
+fi
+
 function usage() {
     cat <<EOF
 
@@ -24,6 +30,19 @@ Examples:
 EOF
 }
 
+# Make sure we are running from the correct directory.
+set_dir() {
+    if [ -e ./suricata.c ]; then
+       cd ..
+    elif [ -e ./src/suricata.c ]; then
+       # Do nothing.
+       true
+    else
+       echo "error: this does not appear to be a suricata source directory."
+       exit 1
+    fi
+}
+
 fail_if_exists() {
     path="$1"
     if test -e "${path}"; then
@@ -115,12 +134,29 @@ w
 EOF
 }
 
+set_dir
+
 protoname="$1"
 
-if [ "${protoname}" = "" ]; then
-    usage
-    exit 1
-fi
+# Make sure the protocol name looks like a proper name (starts with a
+# capital letter).
+case "${protoname}" in
+
+    [[:upper:]]*)
+       # OK.
+       ;;
+
+    "")
+       usage
+       exit 1
+       ;;
+
+    *)
+       echo "error: protocol name must beging with an upper case letter"
+       exit 1
+       ;;
+
+esac
 
 protoname_lower=$(printf ${protoname} | tr '[:upper:]' '[:lower:]')
 protoname_upper=$(printf ${protoname} | tr '[:lower:]' '[:upper:]')
index 73cd89f5b8573335c12b425677f12b177f2ddd88..01df12d84c437f0a2ddce24e13136e354c9dbd38 100755 (executable)
@@ -29,6 +29,19 @@ Examples:
 EOF
 }
 
+# Make sure we are running from the correct directory.
+set_dir() {
+    if [ -e ./suricata.c ]; then
+       cd ..
+    elif [ -e ./src/suricata.c ]; then
+       # Do nothing.
+       true
+    else
+       echo "error: this does not appear to be a suricata source directory."
+       exit 1
+    fi
+}
+
 fail_if_exists() {
     path="$1"
     if test -e "${path}"; then
@@ -143,6 +156,10 @@ w
 EOF
 }
 
+# Main...
+
+set_dir
+
 protoname="$1"
 
 # Make sure the protocol name looks like a proper name (starts with a
index 9e60bdfc40558358d508564ba332235b63824965..e041226b6be1ca7d99dcee1ccfc62db2f7946a81 100755 (executable)
@@ -31,6 +31,19 @@ function Done {
     echo
 }
 
+# Make sure we are running from the correct directory.
+set_dir() {
+    if [ -e ./suricata.c ]; then
+       # Do nothing.
+       true
+    elif [ -e ./src/suricata.c ]; then
+       cd src
+    else
+       echo "error: this does not appear to be a suricata source directory."
+       exit 1
+    fi
+}
+
 if [ $# -ne "1" ]; then
     Usage
     echo "ERROR: call with one argument"
@@ -53,11 +66,8 @@ FILE_H="decode-${LC}.h"
 #echo $FILE_C
 #echo $FILE_H
 
-if [ ! -e ../configure.ac ] || [ ! -e Makefile.am ]; then
-    Usage
-    echo "ERROR: call from src/ directory"
-    exit 1
-fi
+set_dir
+
 if [ ! -e decode-template.c ] || [ ! -e decode-template.h ]; then
     Usage
     echo "ERROR: input files decode-template.c and/or decode-template.h are missing"
index 309b47cc296642c633b8ebe2822b7dbaa83b7e45..92e35ba2e5753701e1125206a6faf216e2bc05e0 100755 (executable)
@@ -32,6 +32,19 @@ function Done {
     echo
 }
 
+# Make sure we are running from the correct directory.
+set_dir() {
+    if [ -e ./suricata.c ]; then
+       # Do nothing.
+       true
+    elif [ -e ./src/suricata.c ]; then
+       cd src
+    else
+       echo "error: this does not appear to be a suricata source directory."
+       exit 1
+    fi
+}
+
 if [ $# -ne "1" ]; then
     Usage
     echo "ERROR: call with one argument"
@@ -54,11 +67,8 @@ FILE_H="detect-${LC}.h"
 #echo $FILE_C
 #echo $FILE_H
 
-if [ ! -e ../configure.ac ] || [ ! -e Makefile.am ]; then
-    Usage
-    echo "ERROR: call from src/ directory"
-    exit 1
-fi
+set_dir
+
 if [ ! -e detect-template.c ] || [ ! -e detect-template.h ]; then
     Usage
     echo "ERROR: input files detect-template.c and/or detect-template.h are missing"