template scripts: allow to be called from top or src

Allow the template setup script to be called from the top source
directory or from ./src to unify where they can be executed
from.
pull/2921/head
Jason Ish 8 years ago
parent ea2ef1b51a
commit d1ac839333

@ -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:]')

@ -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:]')

@ -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

@ -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"

@ -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"

Loading…
Cancel
Save