# tclConfig.sh --
#
# This shell script (for sh) is generated automatically by Tcl's
# configure script.  It will create shell variables for most of
# the configuration options discovered by the configure script.
# This script is intended to be included by the configure scripts
# for Tcl extensions so that they don't have to figure this all
# out for themselves.
#
# The information in this file is specific to a single platform.

# Tcl's version number.
TCL_VERSION='8.6'
TCL_MAJOR_VERSION='8'
TCL_MINOR_VERSION='6'
TCL_PATCH_LEVEL='.8'

# C compiler to use for compilation.
TCL_CC='gcc'

# -D flags for use with the C compiler.
TCL_DEFS='-DPACKAGE_NAME=\"tcl\" -DPACKAGE_TARNAME=\"tcl\" -DPACKAGE_VERSION=\"8.6\" -DPACKAGE_STRING=\"tcl\ 8.6\" -DPACKAGE_BUGREPORT=\"\" -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DNO_VALUES_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_PTHREAD_ATFORK=1 -DTCL_THREADS=1 -DTCL_CFGVAL_ENCODING=\"iso8859-1\" -DHAVE_ZLIB=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -DHAVE_HIDDEN=1 -DMAC_OSX_TCL=1 -DHAVE_COREFOUNDATION=1 -DHAVE_CAST_TO_UNION=1 -DTCL_SHLIB_EXT=\".dylib\" -DNDEBUG=1 -DTCL_CFG_OPTIMIZED=1 -DTCL_TOMMATH=1 -DMP_PREC=4 -DTCL_WIDE_INT_IS_LONG=1 -DHAVE_GETCWD=1 -DHAVE_MKSTEMP=1 -DHAVE_OPENDIR=1 -DHAVE_STRTOL=1 -DHAVE_WAITPID=1 -DHAVE_GETNAMEINFO=1 -DHAVE_GETADDRINFO=1 -DHAVE_FREEADDRINFO=1 -DHAVE_GAI_STRERROR=1 -DHAVE_STRUCT_ADDRINFO=1 -DHAVE_STRUCT_IN6_ADDR=1 -DHAVE_STRUCT_SOCKADDR_IN6=1 -DHAVE_STRUCT_SOCKADDR_STORAGE=1 -DHAVE_GETPWUID_R_5=1 -DHAVE_GETPWUID_R=1 -DHAVE_GETPWNAM_R_5=1 -DHAVE_GETPWNAM_R=1 -DHAVE_GETGRGID_R_5=1 -DHAVE_GETGRGID_R=1 -DHAVE_GETGRNAM_R_5=1 -DHAVE_GETGRNAM_R=1 -DHAVE_MTSAFE_GETHOSTBYNAME=1 -DHAVE_MTSAFE_GETHOSTBYADDR=1 -DHAVE_TERMIOS_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_GMTIME_R=1 -DHAVE_LOCALTIME_R=1 -DHAVE_MKTIME=1 -DHAVE_TM_GMTOFF=1 -DHAVE_STRUCT_STAT_ST_BLOCKS=1 -DHAVE_STRUCT_STAT_ST_BLKSIZE=1 -DHAVE_BLKCNT_T=1 -DHAVE_INTPTR_T=1 -DHAVE_UINTPTR_T=1 -DHAVE_SIGNED_CHAR=1 -DHAVE_PUTENV_THAT_COPIES=1 -DHAVE_LANGINFO=1 -DHAVE_CHFLAGS=1 -DHAVE_MKSTEMPS=1 -DHAVE_GETATTRLIST=1 -DHAVE_COPYFILE_H=1 -DHAVE_COPYFILE=1 -DHAVE_LIBKERN_OSATOMIC_H=1 -DHAVE_OSSPINLOCKLOCK=1 -DUSE_VFORK=1 -DTCL_DEFAULT_ENCODING=\"utf-8\" -DTCL_LOAD_FROM_MEMORY=1 -DTCL_WIDE_CLICKS=1 -DHAVE_AVAILABILITYMACROS_H=1 -DHAVE_WEAK_IMPORT=1 -D_DARWIN_C_SOURCE=1 -DHAVE_FTS=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_FILIO_H=1 -DTCL_UNLOAD_DLLS=1 -DHAVE_CPUID=1 '

# TCL_DBGX used to be used to distinguish debug vs. non-debug builds.
# This was a righteous pain so the core doesn't do that any more.
TCL_DBGX=

# Default flags used in an optimized and debuggable build, respectively.
TCL_CFLAGS_DEBUG='-g'
TCL_CFLAGS_OPTIMIZE='-Os'

# Default linker flags used in an optimized and debuggable build, respectively.
TCL_LDFLAGS_DEBUG=''
TCL_LDFLAGS_OPTIMIZE=''

# Flag, 1: we built a shared lib, 0 we didn't
TCL_SHARED_BUILD=1

# The name of the Tcl library (may be either a .a file or a shared library):
TCL_LIB_FILE='libtcl8.6.dylib'

# Additional libraries to use when linking Tcl.
TCL_LIBS=' -lz  -lpthread -framework CoreFoundation '

# Top-level directory in which Tcl's platform-independent files are
# installed.
TCL_PREFIX='/usr/local'

# Top-level directory in which Tcl's platform-specific files (e.g.
# executables) are installed.
TCL_EXEC_PREFIX='/usr/local'

# Flags to pass to cc when compiling the components of a shared library:
TCL_SHLIB_CFLAGS='-fno-common'

# Flags to pass to cc to get warning messages
TCL_CFLAGS_WARNING='-Wall'

# Extra flags to pass to cc:
TCL_EXTRA_CFLAGS='-arch x86_64 -I/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/libraries/usr/local/include -pipe   -mmacosx-version-min=10.9 '

# Base command to use for combining object files into a shared library:
TCL_SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS} -Wl,-single_module'

# Base command to use for combining object files into a static library:
TCL_STLIB_LD='${AR} cr'

# Either '$LIBS' (if dependent libraries should be included when linking
# shared libraries) or an empty string.  See Tcl's configure.in for more
# explanation.
TCL_SHLIB_LD_LIBS='${LIBS}'

# Suffix to use for the name of a shared library.
TCL_SHLIB_SUFFIX='.dylib'

# Library file(s) to include in tclsh and other base applications
# in order to provide facilities needed by DLOBJ above.
TCL_DL_LIBS=''

# Flags to pass to the compiler when linking object files into
# an executable tclsh or tcltest binary.
TCL_LD_FLAGS=' -headerpad_max_install_names -Wl,-search_paths_first '

# Flags to pass to cc/ld, such as "-R /usr/local/tcl/lib", that tell the
# run-time dynamic linker where to look for shared libraries such as
# libtcl.so.  Used when linking applications.  Only works if there
# is a variable "LIB_RUNTIME_DIR" defined in the Makefile.
TCL_CC_SEARCH_FLAGS=''
TCL_LD_SEARCH_FLAGS=''

# Additional object files linked with Tcl to provide compatibility
# with standard facilities from ANSI C or POSIX.
TCL_COMPAT_OBJS=' strstr.o strtoul.o strtod.o'

# Name of the ranlib program to use.
TCL_RANLIB='ranlib'

# -l flag to pass to the linker to pick up the Tcl library
TCL_LIB_FLAG='-ltcl8.6'

# String to pass to linker to pick up the Tcl library from its
# build directory.
TCL_BUILD_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix -ltcl8.6'

# String to pass to linker to pick up the Tcl library from its
# installed directory.
TCL_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib -ltcl8.6'

# String to pass to the compiler so that an extension can
# find installed Tcl headers.
TCL_INCLUDE_SPEC='-I/usr/local/include'

# Indicates whether a version numbers should be used in -l switches
# ("ok" means it's safe to use switches like -ltcl7.5;  "nodots" means
# use switches like -ltcl75).  SunOS and FreeBSD require "nodots", for
# example.
TCL_LIB_VERSIONS_OK='ok'

# String that can be evaluated to generate the part of a shared library
# name that comes after the "libxxx" (includes version number, if any,
# extension, and anything else needed).  May depend on the variables
# VERSION and SHLIB_SUFFIX.  On most UNIX systems this is
# ${VERSION}${SHLIB_SUFFIX}.
TCL_SHARED_LIB_SUFFIX='${VERSION}.dylib'

# String that can be evaluated to generate the part of an unshared library
# name that comes after the "libxxx" (includes version number, if any,
# extension, and anything else needed).  May depend on the variable
# VERSION.  On most UNIX systems this is ${VERSION}.a.
TCL_UNSHARED_LIB_SUFFIX='${VERSION}.a'

# Location of the top-level source directory from which Tcl was built.
# This is the directory that contains a README file as well as
# subdirectories such as generic, unix, etc.  If Tcl was compiled in a
# different place than the directory containing the source files, this
# points to the location of the sources, not the location where Tcl was
# compiled.
TCL_SRC_DIR='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8'

# List of standard directories in which to look for packages during
# "package require" commands.  Contains the "prefix" directory plus also
# the "exec_prefix" directory, if it is different.
TCL_PACKAGE_PATH='/Library/Frameworks/Python.framework/Versions/3.7/lib /usr/local/lib '

# Tcl supports stub.
TCL_SUPPORTS_STUBS=1

# The name of the Tcl stub library (.a):
TCL_STUB_LIB_FILE='libtclstub8.6.a'

# -l flag to pass to the linker to pick up the Tcl stub library
TCL_STUB_LIB_FLAG='-ltclstub8.6'

# String to pass to linker to pick up the Tcl stub library from its
# build directory.
TCL_BUILD_STUB_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix -ltclstub8.6'

# String to pass to linker to pick up the Tcl stub library from its
# installed directory.
TCL_STUB_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib -ltclstub8.6'

# Path to the Tcl stub library in the build directory.
TCL_BUILD_STUB_LIB_PATH='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/libtclstub8.6.a'

# Path to the Tcl stub library in the install directory.
TCL_STUB_LIB_PATH='/Library/Frameworks/Python.framework/Versions/3.7/lib/libtclstub8.6.a'

# Flag, 1: we built Tcl with threads enabled, 0 we didn't
TCL_THREADS=1


# tclooConfig.sh --
#
# This shell script (for sh) is generated automatically by TclOO's configure
# script, or would be except it has no values that we substitute. It will
# create shell variables for most of the configuration options discovered by
# the configure script. This script is intended to be included by TEA-based
# configure scripts for TclOO extensions so that they don't have to figure
# this all out for themselves.
#
# The information in this file is specific to a single platform.

# These are mostly empty because no special steps are ever needed from Tcl 8.6
# onwards; all libraries and include files are just part of Tcl.
TCLOO_LIB_SPEC=""
TCLOO_STUB_LIB_SPEC=""
TCLOO_INCLUDE_SPEC=""
TCLOO_PRIVATE_INCLUDE_SPEC=""
TCLOO_CFLAGS=""
TCLOO_VERSION=1.1.0


# tkConfig.sh --
#
# This shell script (for sh) is generated automatically by Tk's
# configure script.  It will create shell variables for most of
# the configuration options discovered by the configure script.
# This script is intended to be included by the configure scripts
# for Tk extensions so that they don't have to figure this all
# out for themselves.  This file does not duplicate information
# already provided by tclConfig.sh, so you may need to use that
# file in addition to this one.
#
# The information in this file is specific to a single platform.

# Tk's version number.
TK_VERSION='8.6'
TK_MAJOR_VERSION='8'
TK_MINOR_VERSION='6'
TK_PATCH_LEVEL='.8'

# -D flags for use with the C compiler.
TK_DEFS='-DPACKAGE_NAME=\"tk\" -DPACKAGE_TARNAME=\"tk\" -DPACKAGE_VERSION=\"8.6\" -DPACKAGE_STRING=\"tk\ 8.6\" -DPACKAGE_BUGREPORT=\"\" -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_PTHREAD_ATFORK=1 -DTCL_THREADS=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -DHAVE_HIDDEN=1 -DMAC_OSX_TCL=1 -DHAVE_COREFOUNDATION=1 -DHAVE_CAST_TO_UNION=1 -DTCL_SHLIB_EXT=\".dylib\" -DNDEBUG=1 -DTCL_CFG_OPTIMIZED=1 -DTCL_WIDE_INT_IS_LONG=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_INTPTR_T=1 -DHAVE_UINTPTR_T=1 -DHAVE_PW_GECOS=1 -DHAVE_AVAILABILITYMACROS_H=1 -DHAVE_WEAK_IMPORT=1 -D_DARWIN_C_SOURCE=1 -DMAC_OSX_TK=1 '

# Flag, 1: we built a shared lib, 0 we didn't
TK_SHARED_BUILD=1

# TK_DBGX used to be used to distinguish debug vs. non-debug builds.
# This was a righteous pain so the core doesn't do that any more.
TK_DBGX=

# The name of the Tk library (may be either a .a file or a shared library):
TK_LIB_FILE='libtk8.6.dylib'

# Additional libraries to use when linking Tk.
TK_LIBS='   -lpthread -framework CoreFoundation -framework Cocoa -framework Carbon -framework IOKit  -lz  -lpthread -framework CoreFoundation '

# Top-level directory in which Tk's platform-independent files are
# installed.
TK_PREFIX='/usr/local'

# Top-level directory in which Tk's platform-specific files (e.g.
# executables) are installed.
TK_EXEC_PREFIX='/usr/local'

# -I switch(es) to use to make all of the X11 include files accessible:
TK_XINCLUDES=''

# Linker switch(es) to use to link with the X11 library archive.
TK_XLIBSW=''

# -l flag to pass to the linker to pick up the Tk library
TK_LIB_FLAG='-ltk8.6'

# String to pass to linker to pick up the Tk library from its
# build directory.
TK_BUILD_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tk8.6.8/unix -ltk8.6'

# String to pass to linker to pick up the Tk library from its
# installed directory.
TK_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib -ltk8.6'

# String to pass to the compiler so that an extension can
# find installed Tk headers.
TK_INCLUDE_SPEC='-I/usr/local/include'

# Location of the top-level source directory from which Tk was built.
# This is the directory that contains a README file as well as
# subdirectories such as generic, unix, etc.  If Tk was compiled in a
# different place than the directory containing the source files, this
# points to the location of the sources, not the location where Tk was
# compiled.
TK_SRC_DIR='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tk8.6.8'

# Needed if you want to make a 'fat' shared library library
# containing tk objects or link a different wish.
TK_CC_SEARCH_FLAGS=''
TK_LD_SEARCH_FLAGS=''

# The name of the Tk stub library (.a):
TK_STUB_LIB_FILE='libtkstub8.6.a'

# -l flag to pass to the linker to pick up the Tk stub library
TK_STUB_LIB_FLAG='-ltkstub8.6'

# String to pass to linker to pick up the Tk stub library from its
# build directory.
TK_BUILD_STUB_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tk8.6.8/unix -ltkstub8.6'

# String to pass to linker to pick up the Tk stub library from its
# installed directory.
TK_STUB_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib -ltkstub8.6'

# Path to the Tk stub library in the build directory.
TK_BUILD_STUB_LIB_PATH='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tk8.6.8/unix/libtkstub8.6.a'

# Path to the Tk stub library in the install directory.
TK_STUB_LIB_PATH='/Library/Frameworks/Python.framework/Versions/3.7/lib/libtkstub8.6.a'


# itclConfig.sh --
#
# This shell script (for sh) is generated automatically by Itcl's
# configure script.  It will create shell variables for most of
# the configuration options discovered by the configure script.
# This script is intended to be included by the configure scripts
# for Itcl extensions so that they don't have to figure this all
# out for themselves.  This file does not duplicate information
# already provided by tclConfig.sh, so you may need to use that
# file in addition to this one.
#
# The information in this file is specific to a single platform.

# Itcl's version number.
itcl_VERSION='4.1.1'
ITCL_VERSION='4.1.1'

# The name of the Itcl library (may be either a .a file or a shared library):
itcl_LIB_FILE=libitcl4.1.1.dylib
ITCL_LIB_FILE=libitcl4.1.1.dylib

# String to pass to linker to pick up the Itcl library from its
# build directory.
itcl_BUILD_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1 -litcl4.1.1'
ITCL_BUILD_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1 -litcl4.1.1'

# String to pass to linker to pick up the Itcl library from its
# installed directory.
itcl_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1 -litcl4.1.1'
ITCL_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1 -litcl4.1.1'

# The name of the Itcl stub library (a .a file):
itcl_STUB_LIB_FILE=libitclstub4.1.1.a
ITCL_STUB_LIB_FILE=libitclstub4.1.1.a

# String to pass to linker to pick up the Itcl stub library from its
# build directory.
itcl_BUILD_STUB_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1 -litclstub4.1.1'
ITCL_BUILD_STUB_LIB_SPEC='-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1 -litclstub4.1.1'

# String to pass to linker to pick up the Itcl stub library from its
# installed directory.
itcl_STUB_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1 -litclstub4.1.1'
ITCL_STUB_LIB_SPEC='-L/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1 -litclstub4.1.1'

# String to pass to linker to pick up the Itcl stub library from its
# build directory.
itcl_BUILD_STUB_LIB_PATH='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1/libitclstub4.1.1.a'
ITCL_BUILD_STUB_LIB_PATH='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/itcl4.1.1/libitclstub4.1.1.a'

# String to pass to linker to pick up the Itcl stub library from its
# installed directory.
itcl_STUB_LIB_PATH='/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1/libitclstub4.1.1.a'
ITCL_STUB_LIB_PATH='/Library/Frameworks/Python.framework/Versions/3.7/lib/itcl4.1.1/libitclstub4.1.1.a'

# Location of the top-level source directories from which [incr Tcl]
# was built.  This is the directory that contains generic, unix, etc.
# If [incr Tcl] was compiled in a different place than the directory
# containing the source files, this points to the location of the sources,
# not the location where [incr Tcl] was compiled.
itcl_SRC_DIR='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/itcl4.1.1'
ITCL_SRC_DIR='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/itcl4.1.1'

# String to pass to the compiler so that an extension can
# find installed Itcl headers.
itcl_INCLUDE_SPEC='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/itcl4.1.1/generic'
ITCL_INCLUDE_SPEC='/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/itcl4.1.1/generic'


# tdbcConfig.sh --
#
# This shell script (for sh) is generated automatically by TDBC's configure
# script. It will create shell variables for most of the configuration options
# discovered by the configure script. This script is intended to be included
# by the configure scripts for TDBC extensions so that they don't have to
# figure this all out for themselves.
#
# The information in this file is specific to a single platform.
#
# RCS: @(#) $Id$

# TDBC's version number
tdbc_VERSION=1.0.6
TDBC_VERSION=1.0.6

# Name of the TDBC library - may be either a static or shared library
tdbc_LIB_FILE=libtdbc1.0.6.dylib
TDBC_LIB_FILE=libtdbc1.0.6.dylib

# String to pass to the linker to pick up the TDBC library from its build dir
tdbc_BUILD_LIB_SPEC="-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6 -ltdbc1.0.6"
TDBC_BUILD_LIB_SPEC="-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6 -ltdbc1.0.6"

# String to pass to the linker to pick up the TDBC library from its installed
# dir.
tdbc_LIB_SPEC="-L/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6 -ltdbc1.0.6"
TDBC_LIB_SPEC="-L/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6 -ltdbc1.0.6"

# Name of the TBDC stub library
tdbc_STUB_LIB_FILE="libtdbcstub1.0.6.a"
TDBC_STUB_LIB_FILE="libtdbcstub1.0.6.a"

# String to pass to the linker to pick up the TDBC stub library from its
# build directory
tdbc_BUILD_STUB_LIB_SPEC="-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6 -ltdbcstub1.0.6"
TDBC_BUILD_STUB_LIB_SPEC="-L/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6 -ltdbcstub1.0.6"

# String to pass to the linker to pick up the TDBC stub library from its
# installed directory
tdbc_STUB_LIB_SPEC="-L/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6 -ltdbcstub1.0.6"
TDBC_STUB_LIB_SPEC="-L/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6 -ltdbcstub1.0.6"

# Path name of the TDBC stub library in its build directory
tdbc_BUILD_STUB_LIB_PATH="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6/libtdbcstub1.0.6.a"
TDBC_BUILD_STUB_LIB_PATH="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/unix/pkgs/tdbc1.0.6/libtdbcstub1.0.6.a"

# Path name of the TDBC stub library in its installed directory
tdbc_STUB_LIB_PATH="/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6/libtdbcstub1.0.6.a"
TDBC_STUB_LIB_PATH="/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6/libtdbcstub1.0.6.a"

# Location of the top-level source directories from which TDBC was built.
# This is the directory that contains doc/, generic/ and so on.  If TDBC
# was compiled in a directory other than the source directory, this still
# points to the location of the sources, not the location where TDBC was
# compiled.
tdbc_SRC_DIR="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6"
TDBC_SRC_DIR="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6"

# String to pass to the compiler so that an extension can find installed TDBC
# headers
tdbc_INCLUDE_SPEC="-I/usr/local/include"
TDBC_INCLUDE_SPEC="-I/usr/local/include"

# String to pass to the compiler so that an extension can find TDBC headers
# in the source directory
tdbc_BUILD_INCLUDE_SPEC="-I/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6/generic"
TDBC_BUILD_INCLUDE_SPEC="-I/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6/generic"

# Path name where .tcl files in the tdbc package appear at run time.
tdbc_LIBRARY_PATH="/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6"
TDBC_LIBRARY_PATH="/Library/Frameworks/Python.framework/Versions/3.7/lib/tdbc1.0.6"

# Path name where .tcl files in the tdbc package appear at build time.
tdbc_BUILD_LIBRARY_PATH="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6/library"
TDBC_BUILD_LIBRARY_PATH="/Volumes/Lumberyard/lumberyard_p4/lyengine/3rdPartySource/python/darwin_x64/temp/python_build/_bld/tcl8.6.8/pkgs/tdbc1.0.6/library"

# Additional flags that must be passed to the C compiler to use tdbc
tdbc_CFLAGS=
TDBC_CFLAGS=


# tclConfig.sh --
#
# This shell script (for sh) is generated automatically by Tcl's
# configure script.  It will create shell variables for most of
# the configuration options discovered by the configure script.
# This script is intended to be included by the configure scripts
# for Tcl extensions so that they don't have to figure this all
# out for themselves.
#
# The information in this file is specific to a single platform.

TCL_DLL_FILE="tcl86t.dll"

# Tcl's version number.
TCL_VERSION='8.6'
TCL_MAJOR_VERSION='8'
TCL_MINOR_VERSION='6'
TCL_PATCH_LEVEL='8.6.9'

# C compiler to use for compilation.
TCL_CC='cl'

# -D flags for use with the C compiler.
TCL_DEFS='-nologo -c /D_ATL_XP_TARGETING /DUNICODE /D_UNICODE  -W3 -wd4311 -wd4312 -wd4311 -wd4312 -FpC:\_work\11\b\tcl-core-8.6.9.0\win\Release_AMD64_VC13\tcl_ThreadedDynamic\  -fp:strict -O2 -GS -GL -MD -I"C:\_work\11\b\tcl-core-8.6.9.0\win\..\win" -I"C:\_work\11\b\tcl-core-8.6.9.0\win\..\generic"  -I"C:\_work\11\b\tcl-core-8.6.9.0\win\..\libtommath"  -DTCL_TOMMATH -DMP_PREC=4 -Dinline=__inline -DHAVE_ZLIB=1 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DTCL_CFGVAL_ENCODING=\"cp1252\" -DSTDC_HEADERS -DTCL_THREADS=1 -DUSE_THREAD_ALLOC=1 -DNDEBUG -DTCL_CFG_OPTIMIZED -DTCL_CFG_DO64BIT   -DBUILD_tcl'

# If TCL was built with debugging symbols, generated libraries contain
# this string at the end of the library name (before the extension).
TCL_DBGX=t

# Default flags used in an optimized and debuggable build, respectively.
TCL_CFLAGS_DEBUG='-nologo -c -W3 -YX -FpC:\_work\11\b\tcl-core-8.6.9.0\win\Release_AMD64_VC13\tcl_ThreadedDynamic\ -MDd'
TCL_CFLAGS_OPTIMIZE='-nologo -c -W3 -YX -FpC:\_work\11\b\tcl-core-8.6.9.0\win\Release_AMD64_VC13\tcl_ThreadedDynamic\ -MD'

# Default linker flags used in an optimized and debuggable build, respectively.
TCL_LDFLAGS_DEBUG='-nologo -machine:AMD64 -debug -debugtype:cv'
TCL_LDFLAGS_OPTIMIZE='-nologo -machine:AMD64 -release -opt:ref -opt:icf,3'

# Flag, 1: we built a shared lib, 0 we didn't
TCL_SHARED_BUILD=1

# The name of the Tcl library (may be either a .a file or a shared library):
TCL_LIB_FILE='tcl86t.lib'

# Flag to indicate whether shared libraries need export files.
TCL_NEEDS_EXP_FILE=

# String that can be evaluated to generate the part of the export file
# name that comes after the "libxxx" (includes version number, if any,
# extension, and anything else needed).  May depend on the variables
# VERSION.  On most UNIX systems this is ${VERSION}.exp.
TCL_EXPORT_FILE_SUFFIX='86t.lib'

# Additional libraries to use when linking Tcl.
TCL_LIBS='kernel32.lib advapi32.lib netapi32.lib user32.lib userenv.lib ws2_32.lib ucrt.lib netapi32.lib user32.lib userenv.lib ws2_32.lib'

# Top-level directory in which Tcl's platform-independent files are
# installed.
TCL_PREFIX='C:\_work\11\b\tcltk-8.6.9.0\amd64'

# Top-level directory in which Tcl's platform-specific files (e.g.
# executables) are installed.
TCL_EXEC_PREFIX='C:\_work\11\b\tcltk-8.6.9.0\amd64\bin'

# Flags to pass to cc when compiling the components of a shared library:
TCL_SHLIB_CFLAGS=''

# Flags to pass to cc to get warning messages
TCL_CFLAGS_WARNING='-W3'

# Extra flags to pass to cc:
TCL_EXTRA_CFLAGS='-YX'

# Base command to use for combining object files into a shared library:
TCL_SHLIB_LD='link -nologo -machine:AMD64  -ltcg -release -opt:ref -opt:icf,3 -nodefaultlib:libucrt.lib -dll'

# Base command to use for combining object files into a static library:
TCL_STLIB_LD='lib -nologo'

# Either '$LIBS' (if dependent libraries should be included when linking
# shared libraries) or an empty string.  See Tcl's configure.in for more
# explanation.
TCL_SHLIB_LD_LIBS='kernel32.lib advapi32.lib netapi32.lib user32.lib userenv.lib ws2_32.lib ucrt.lib netapi32.lib user32.lib userenv.lib ws2_32.lib'

# Suffix to use for the name of a shared library.
TCL_SHLIB_SUFFIX='.dll'

# Library file(s) to include in tclsh and other base applications
# in order to provide facilities needed by DLOBJ above.
TCL_DL_LIBS=''

# Flags to pass to the compiler when linking object files into
# an executable tclsh or tcltest binary.
TCL_LD_FLAGS=''

# Flags to pass to cc/ld, such as "-R /usr/local/tcl/lib", that tell the
# run-time dynamic linker where to look for shared libraries such as
# libtcl.so.  Used when linking applications.  Only works if there
# is a variable "LIB_RUNTIME_DIR" defined in the Makefile.
TCL_CC_SEARCH_FLAGS=''
TCL_LD_SEARCH_FLAGS=''

# Additional object files linked with Tcl to provide compatibility
# with standard facilities from ANSI C or POSIX.
TCL_COMPAT_OBJS=''

# Name of the ranlib program to use.
TCL_RANLIB=''

# -l flag to pass to the linker to pick up the Tcl library
TCL_LIB_FLAG=''

# String to pass to linker to pick up the Tcl library from its
# build directory.
TCL_BUILD_LIB_SPEC=''

# String to pass to linker to pick up the Tcl library from its
# installed directory.
TCL_LIB_SPEC='C:\_work\11\b\tcltk-8.6.9.0\amd64\lib\tcl86t.lib'

# String to pass to the compiler so that an extension can
# find installed Tcl headers.
TCL_INCLUDE_SPEC='-IC:\_work\11\b\tcltk-8.6.9.0\amd64\include'

# Indicates whether a version numbers should be used in -l switches
# ("ok" means it's safe to use switches like -ltcl7.5;  "nodots" means
# use switches like -ltcl75).  SunOS and FreeBSD require "nodots", for
# example.
TCL_LIB_VERSIONS_OK=''

# String that can be evaluated to generate the part of a shared library
# name that comes after the "libxxx" (includes version number, if any,
# extension, and anything else needed).  May depend on the variables
# VERSION and SHLIB_SUFFIX.  On most UNIX systems this is
# ${VERSION}${SHLIB_SUFFIX}.
TCL_SHARED_LIB_SUFFIX='86t.dll'

# String that can be evaluated to generate the part of an unshared library
# name that comes after the "libxxx" (includes version number, if any,
# extension, and anything else needed).  May depend on the variable
# VERSION.  On most UNIX systems this is ${VERSION}.a.
TCL_UNSHARED_LIB_SUFFIX='86t.lib'

# Location of the top-level source directory from which Tcl was built.
# This is the directory that contains a README file as well as
# subdirectories such as generic, unix, etc.  If Tcl was compiled in a
# different place than the directory containing the source files, this
# points to the location of the sources, not the location where Tcl was
# compiled.
TCL_SRC_DIR='C:\_work\11\b\tcl-core-8.6.9.0\win\..'

# List of standard directories in which to look for packages during
# "package require" commands.  Contains the "prefix" directory plus also
# the "exec_prefix" directory, if it is different.
TCL_PACKAGE_PATH=''

# Tcl supports stub.
TCL_SUPPORTS_STUBS=1

# The name of the Tcl stub library (.a):
TCL_STUB_LIB_FILE='tclstub86.lib'

# -l flag to pass to the linker to pick up the Tcl stub library
TCL_STUB_LIB_FLAG='tclstub86.lib'

# String to pass to linker to pick up the Tcl stub library from its
# build directory.
TCL_BUILD_STUB_LIB_SPEC='-LC:\_work\11\b\tcl-core-8.6.9.0\win\Release_AMD64_VC13 tclstub86.lib'

# String to pass to linker to pick up the Tcl stub library from its
# installed directory.
TCL_STUB_LIB_SPEC='-LC:\_work\11\b\tcltk-8.6.9.0\amd64\lib tclstub86.lib'

# Path to the Tcl stub library in the build directory.
TCL_BUILD_STUB_LIB_PATH='C:\_work\11\b\tcl-core-8.6.9.0\win\Release_AMD64_VC13\tclstub86.lib'

# Path to the Tcl stub library in the install directory.
TCL_STUB_LIB_PATH='C:\_work\11\b\tcltk-8.6.9.0\amd64\lib\tclstub86.lib'

# Flag, 1: we built Tcl with threads enabled, 0 we didn't
TCL_THREADS=1


#!/bin/bash -e

jar=$(find . -name neptune-export-*-all.jar -print -quit)
java -jar ${jar} "$@"


#!/bin/bash

FD_FILE='/proc/sys/fs/file-nr'
SOCKET_FILE='/proc/net/sockstat'

SOCKET=`cat $SOCKET_FILE | grep sockets | awk '{print $3}'`
FD=`cat $FD_FILE | awk '{print $1}'`

echo -e "file descriptors - $FD\nsockets - $SOCKET\n"

gmetric -tuint8 -x180 -n"file_descriptors" -v$FD
gmetric -tuint8 -x180 -n"sockets_in_use" -v$SOCKET


#!/usr/bin/env bash

#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
DEBUG=0
PROGRAM_NAME=$(basename $0)
PROGRAM_VERSION="1.1"

PGCLI=$(which psql)
PGFLAGS_DML="--quiet --no-align --tuples-only"
PGFLAGS_QRY="--quiet"

version() {
  cat <<VERSION_EOF

${PROGRAM_NAME} ${PROGRAM_VERSION}

VERSION_EOF
}

usage() {
  cat <<USAGE_EOF

${PROGRAM_NAME} ${PROGRAM_VERSION}
Manage local extension in PostgreSQL using pg_tle

USAGE:

  Install:
    ${PROGRAM_NAME} \\
      --action install \\
      --connection "postgresql://postgres@localhost:5432/postgres?sslmode=prefer" \\
      --name <ExtensionName> \\
      --extpath <ExtensionPath>

  Remove:
    ${PROGRAM_NAME} \\
      --action uninstall \\
      --connection "postgresql://postgres@localhost:5432/postgres?sslmode=prefer" \\
      --name <ExtensionName>

  List:
    ${PROGRAM_NAME} \\
      --action list \\
      --connection "postgresql://postgres@localhost:5432/postgres?sslmode=prefer"

  List Versions along wtih Extensions:
    ${PROGRAM_NAME} \\
      --action list-versions \\
      --connection "postgresql://postgres@localhost:5432/postgres?sslmode=prefer"

OPTIONS:

    -a, --action <action name>
          A required parameter.
          install - install extension
          update - update extension
          uninstall - uninstall extension
          list - list extension
          list-versions - list extension along with available versions

    -c, --connection <PG Connection>
          A required parameter.
          PostgreSQL connection string (URI or "Name=Value Name1=V1" format)

    -n, --name <Extension Name>
          A required parameter for install and uninstall actions.
          Name of the extension

    -p, --extpath <Extension Path>
          A required parameter for install action.
          Local path of the extension

    -h, --help
          Print help information

    -V, --version
          Print version information

    -m, --runmake
          Run make to generate SQL file

    -s, --sqldir <subdir where SQL is present>
          set subdir where extension SQL files are

EXIT_CODES:
  1 - PostgreSQL command line tool psql is missing
  2 - Missing argument or Invalid arguments value
  3 - Extension source code folder (--extpath) not found
  4 - Error running conencting to PostgreSQL or error executiong SQL query
  9 - Unsupported OS

* Long Options are not supported on MACOS

USAGE_EOF
}

RUN_PGSQL(){
  if [[ "$1" = "" ]]; then
    PG_OUTPUT=$(psql ${pgConn} ${PGFLAGS} --command="${SQL_QUERY}" 2>&1)
  else
    PG_OUTPUT=$(psql ${pgConn} ${PGFLAGS} -f "${1}" 2>&1)
  fi
  PG_EXIT=$?
}
OS_TYPE=$(uname)
if [ "${OS_TYPE}" = "Linux" ]; then
  SUPPORTED_ARGS=$(getopt -o c:a:p:n:s:mhvd --long connection:,action:,extpath:,name:,sqldir:,runmake,help,version,debug -- "$@")
  EX=$?
elif [ "${OS_TYPE}" = "Darwin" ]; then
  SUPPORTED_ARGS=$(getopt c:a:p:n:s:mhvd $*)
  EX=$?
else
  echo "Unsupport OS"
  exit 9
fi
if [ $EX -gt 0 ]; then
  printf "\nError parsing argument(s)\n" >&2
  if [ "${OS_TYPE}" = "Darwin" ]; then
    printf "\nLong arguments are not supported on MACOS\n" >&2
  fi
  usage >&2
  exit 2
fi

RUNMAKE=0
SQLDir=""
eval set -- "$SUPPORTED_ARGS"
while true; do
  case "$1" in
    -c | --connection)
        pgConn=$2
        shift 2
        continue
        ;;
    -n | --name)
        ExtName=$2
        shift 2
        continue
        ;;
    -p | --extpath)
        ExtPath=$2
        shift 2
        continue
        ;;
    -a | --action)
        Action=$2
        shift 2
        continue
        ;;
    -m | --runmake)
        RUNMAKE=1
        shift 1
        continue
        ;;
    -s | --sqldir)
        SQLDir=$2
        shift 2
        continue
        ;;
    -d | --debug)
        DEBUG=1
        shift 1
        continue
        ;;
    -h | --help)
        usage
        exit 0
        ;;
    -v | --version)
        version
        exit 0
        ;;
    --) shift;
        break
        ;;
  esac
done

if [ $# -gt 0 ]; then
  printf "\nExtra argument(s) passed, %s\n" "$@" >&2
  usage >&2
  exit 2
fi

if [ -z "${PGCLI}" ] ; then
  printf "\nPostgreSQL command line client 'psql' not found in PATH\n" >&2
  exit 1
fi

if [ -z "${Action}" ] ; then
  printf "\nMissing argument(s) --action is required\n" >&2
  usage >&2
  exit 2
fi

if [ -z "${pgConn}" ] ; then
  printf "\nMissing argument(s) --connection is required\n" >&2
  usage >&2
  exit 2
fi

case "$Action" in
  install|update)
    if [ -z "${ExtName}" ] || [ -z "${ExtPath}" ] ; then
      printf "\nMissing argument(s) --name --extpath are required for install\n" >&2
      usage >&2
      exit 2
    fi
    if [ ! -d ${ExtPath} ] ; then
      printf "\nFATAL: Extension path %s is missing.\n" ${ExtPath} >&2
      exit 3
    fi
    if [ ${RUNMAKE} -gt 0 ]; then
      pushd ${ExtPath}
      make
      popd
    fi
    ExtControl="${ExtPath}/${ExtName}.control"
    ExtSQL_Template="${ExtPath}/${SQLDir}/${ExtName}--%s.sql"
    if [ ! -f "${ExtControl}" ] ; then
      printf "\nFATAL: Extension control file %s is missing.\n" ${ExtControl} >&2
      exit 3
    fi
    ExtensionsList=""
    printf -v ExtSQL "${ExtSQL_Template}" "*"
    for file in ${ExtSQL}
    do
      if [ "${file}" = "${ExtSQL}" ]; then
        break
      fi
      parsed=$(sed -e "s:.*${ExtName}--::g;s:.sql::g;s:--:,:g; s:$:,${file}:g" <<< ${file} )
      ExtensionsList="${ExtensionsList} ${parsed}"
    done
    if [ -z "${ExtensionsList}" ] ; then
      printf "\nFATAL: Extension SQL files %s are missing.\n" ${ExtSQL} >&2
      exit 3
    fi
    if [ ${Action} == "update" ]; then
      printf "\nUpdating ${ExtName} from ${ExtPath} in ${pgConn}\n"
    else
      printf "\nInstalling ${ExtName} from ${ExtPath} in ${pgConn}\n"
    fi
    PGFLAGS=${PGFLAGS_DML}
    DefaultRev="$(sed -ne "s/ //g;s/^default_version=\(.*\)/\1/p" < ${ExtControl})"
    if [ -z "${DefaultRev}" ]; then
      printf "\nFATAL: default_version not defined in %s.\n" ${ExtControl} >&2
      exit 3
    fi
    printf -v DefaultSQL "${ExtSQL_Template}" ${DefaultRev//\'/}
    [ ${DEBUG} -gt 0 ] && echo "\$DefaultSQL is ${DefaultSQL}"
    for revs in $ExtensionsList
    do
      [ ${DEBUG} -gt 0 ] && echo "Working on ${revs}"
      IFS=, read -r v1 v2 v3 <<< "${revs}"
      if [ -z "${v3}" ]; then
        if [ "${DefaultSQL}" != "${v2}" ]; then
          [ "${DEBUG}" -gt 0 ] && echo "Skip loading: ${v2}"
          continue
        fi
        SUFLAG="$(sed -ne "s/ //g;s/^trusted=\(.*\)/\1/p" < ${ExtControl})"
        SUFLAG=${SUFLAG:-false}
        if [ ${Action} == "update" ]; then
          SQL_WHERE=" WHERE NOT EXISTS (SELECT pg_proc.proname FROM pg_catalog.pg_proc WHERE pg_proc.proname LIKE '${ExtName}.control'::pg_catalog.name AND pg_proc.pronamespace OPERATOR(pg_catalog.=) 'pgtle'::regnamespace::oid)"
        else
          SQL_WHERE=""
        fi
        SQL_QUERY="SELECT FROM pgtle.install_extension('${ExtName}', '${v1}', '"$(sed -ne "s/^comment.*=.*'\(.*\)'/\1/p" < ${ExtControl})"', \$_PG_TLE_SQL_\$$(cat ${v2})\$_PG_TLE_SQL_\$) ${SQL_WHERE};"
      else
        if [ ${Action} == "update" ]; then
          SQL_WHERE=" WHERE NOT EXISTS (SELECT pg_proc.proname FROM pg_catalog.pg_proc WHERE pg_proc.proname LIKE '${ExtName}--${v1}--${v2}.sql'::pg_catalog.name AND pg_proc.pronamespace OPERATOR(pg_catalog.=) 'pgtle'::regnamespace::oid)"
        else
          SQL_WHERE=""
        fi
        SQL_QUERY="SELECT FROM pgtle.install_update_path('${ExtName}', '${v1}', '${v2}', \$_PG_TLE_SQL_\$$(cat ${v3})\$_PG_TLE_SQL_\$) ${SQL_WHERE};"
      fi
      SQL_FILE=$(mktemp .$$.XXXXXXXXXXXXXXXXXXX.sql)
      (echo "\\set ON_ERROR_STOP true";echo "${SQL_QUERY}") >${SQL_FILE}
      RUN_PGSQL ${SQL_FILE}
      [ ${DEBUG} -eq 0 ] && rm -f ${SQL_FILE}
      if [ ${PG_EXIT} -gt 0 ]; then
        echo "Failed to run SQL from ${SQL_FILE}"
        break
      fi
    done
    if [ ${PG_EXIT} -eq 0 ]; then
      SQL_QUERY="SELECT FROM pgtle.set_default_version('${ExtName}', ${DefaultRev}::text);"
      RUN_PGSQL
    fi
    ;;
  uninstall)
    if [ -z "${ExtName}" ] ; then
      printf "\nMissing argument(s) --name is required for uninstall\n" >&2
      usage >&2
      exit 2
    fi
    printf "\nRemoving ${ExtName} from ${pgConn}\n"
    PGFLAGS=${PGFLAGS_DML}
    SQL_QUERY="SELECT FROM pgtle.uninstall_extension('${ExtName}');"
    RUN_PGSQL
    ;;
  list|list-versions)
    printf "\nList pg_tle installed extension(s) from ${pgConn}\n"
    PGFLAGS=${PGFLAGS_QRY}
    if [ $Action = "list" ] ; then
      SQL_QUERY='SELECT * FROM pgtle.available_extensions();'
    else
      SQL_QUERY='SELECT * FROM pgtle.available_extension_versions();'
    fi
    RUN_PGSQL
    ;;
  *)
    printf "\nInvalid Action requested, %s\n" "${Action}" >&2
    usage >&2
    exit 2
    ;;
esac
if [ "${PG_EXIT}" -eq 0 ] ; then
  if [ $Action == "list" ] || [ $Action == "list-versions" ] ; then
    if [[ "${PG_OUTPUT}" == *"(0 rows)"* ]] ; then
      printf "\nNo pg_tle managed extension(s) available in ${pgConn}\n"
    else
      printf "\n${PG_OUTPUT}\n"
    fi
  else
    printf "\n$Action completed successfully.\n"
  fi
  exit 0
else
  printf "\nExecution Failed\nExit code (psql): ${PG_EXIT}\nError (psql): ${PG_OUTPUT}\n" >&2
  exit 4
fi


#!/bin/bash

source ./test-helpers.sh

# This script tests container image build and runs a couple of
# tests against the generated image.

if [ -d ".venv" ]; then
    mv .venv .venv_temp
fi

docker build -t porting-advisor .
if [ $? -ne 0 ]; then
    echo "**ERROR**: building container image" && exit 1
fi

echo "Running container on samples to console"
docker run --rm -v $(pwd)/sample-projects:/source porting-advisor /source > console_test.txt
test_report 'console' 'console_test.txt' "${lines_to_find[@]}"
if [ $? -ne 0 ]; then
    echo "**ERROR**: running container to console" && exit 1
fi
rm console_test.txt

echo "Running container on samples to HTML report"
docker run --rm -v $(pwd):/source porting-advisor /source/sample-projects --output /source/test.html
test_report 'html' 'test.html' "${lines_to_find[@]}"
if [ $? -ne 0 ]; then
    echo "**ERROR**: running container to html report" && exit 1
fi
rm -f test.html

if [ -d ".venv_temp" ]; then
    mv .venv_temp .venv
fi

exit 0


#!/bin/bash

# get binary name
OS_SUFFIX="Other"
case "$(uname -s)" in
    Darwin)
        OS_SUFFIX="macosx"
        ;;

    Linux)
        OS_SUFFIX="linux"
        ;;
esac

if [ $OS_SUFFIX = "Other" ]
then
    echo "**ERROR**: Unsupported platform" && exit 1
fi

PROCESSOR_SUFFIX=`uname -m`
FILE_NAME="porting-advisor-$OS_SUFFIX-$PROCESSOR_SUFFIX"
echo $FILE_NAME


#!/bin/bash

source ./test-helpers.sh

FILE_NAME=`./getBinaryName.sh`
chmod +x ./dist/$FILE_NAME

echo "Running samples to console"
./dist/$FILE_NAME ./sample-projects/ > console_test.txt
test_report 'console' 'console_test.txt' "${lines_to_find[@]}"
rm console_test.txt

echo "Running samples to HTML report"
./dist/$FILE_NAME ./sample-projects/ --output test.html
test_report 'html' 'test.html' "${lines_to_find[@]}"
rm test.html

echo "Running samples to Dependency Report"
declare -a dependencies=("<si><t>component</t></si><si><t>version</t></si><si><t>origin</t></si><si><t>filename</t></si>"
                        "<si><t>junit</t></si><si><t>4.8.2</t></si>"
                        "<si><t>zstd-jni</t></si><si><t>1.1.0</t></si>"
                        "<si><t>snappy-java</t></si><si><t>1.1.3</t></si>"
                        "<si><t>lz4-java</t></si><si><t>1.4.0</t></si>"
                        "<si><t>hadoop-lzo</t></si><si><t>0.4.17</t></si>"
                        "<si><t>leveldbjni-all</t></si><si><t>1.8</t></si>"
                        "<si><t>CommandLineParser</t></si><si><t>2.8.0</t></si>"
                        "<si><t>Microsoft.Build.Utilities.Core</t></si><si><t>17.1.0</t></si>"
                        "<si><t>Microsoft.Extensions.Logging.Console</t></si><si><t>6.0.0</t></si>"
                        "<si><t>Microsoft.NET.Test.Sdk</t></si><si><t>16.5.0</t></si>"
                        "<si><t>Microsoft.VisualStudio.Setup.Configuration.Interop</t></si><si><t>3.1.2196</t></si>"
                        "<si><t>System.Linq.Async</t></si><si><t>6.0.1</t></si>"
                        "<si><t>xunit</t></si><si><t>2.4.1</t></si>"
                        "<si><t>coverlet.collector</t></si><si><t>1.2.0</t></si>"
                        "<si><t>SciPy</t></si>"
                        "<si><t>NumPy</t></si>"
                        "<si><t>FakeDependency</t></si><si><t>1.2.3</t></si>"
                        "<si><t>cors</t></si><si><t>2.8.5</t></si>"
                        "<si><t>express</t></si><si><t>4.18.1</t></si>"
                        "<si><t>rxjs</t></si><si><t>7.5.6</t></si>"
                        "<si><t>socket.io</t></si><si><t>4.5.1</t></si>"
                        "<si><t>@codechecks/client</t></si><si><t>0.1.12</t></si>"
                        "<si><t>@commitlint/cli</t></si><si><t>17.0.3</t></si>"
                        "<si><t>eslint</t></si><si><t>7.32.0</t></si>"
                        "<si><t>typescript</t></si><si><t>4.7.4</t></si>"
                        "<si><t>github.com/aws/aws-sdk-go</t></si>"
                        "<si><t>github.com/golang/snappy</t></si>"
                        "<si><t>rails</t></si><si><t>6.1.6.1</t></si>"
                        "<si><t>rake</t></si><si><t>11.1</t></si>"
                        "<si><t>actionpack</t></si>"
                        "<si><t>bcrypt</t></si><si><t>3.1</t></si>"
                        "<si><t>cucumber</t></si><si><t>4.1</t></si>"
                        "<si><t>gc_tracer</t></si>"
                        "<si><t>gssapi</t></si>"
                        "<si><t>mail</t></si>"
                        "<si><t>turbo-rails</t></si>"
                        "<si><t>httpclient</t></si>"
                        "<si><t>jruby-openssl</t></si>"
                    )
./dist/$FILE_NAME ./sample-projects/ --output test.xlsx --output-format dependencies
# xlsx files are compressed files, so we need to unzip them and then compare them
mkdir ./temp
unzip -q ./test.xlsx -d ./temp
test_report 'dependencies' './temp/xl/sharedStrings.xml' "${dependencies[@]}"
rm test.xlsx
rm -rf ./temp

echo "--- Running negative tests ---"

echo "Running missing arguments test"
./dist/$FILE_NAME 2>&1 | tee missing_arguments_test.txt
if diff "./tests-baseline/missing_arguments_test.txt" "missing_arguments_test.txt"; then
    echo "**PASSED** missing arguments test"
else
    echo "**FAILED**: missing arguments test" && exit 1
fi
rm missing_arguments_test.txt

echo "Running directory not found test"
./dist/$FILE_NAME unexisting_directory 2>&1 | tee directory_not_found_test.txt
if diff "./tests-baseline/directory_not_found_test.txt" "directory_not_found_test.txt"; then
    echo "**PASSED** directory not found test"
else
    echo "**FAILED**: directory not found test" && exit 1
fi
rm directory_not_found_test.txt


#!/bin/bash

FILE_NAME=`./getBinaryName.sh`
chmod +x ./dist/$FILE_NAME

git clone https://github.com/pytorch/pytorch.git
time ./dist/$FILE_NAME pytorch
rm -rf pytorch


#!/bin/bash

function test_line() {
    reportType=$1
    result_filename=$2
    pattern=$3
    if grep --quiet "$3" "$result_filename"
    then
        echo "**PASS** $reportType report has: $pattern"
    else
        echo "**FAILED** $reportType report is missing: $pattern" && exit 1
    fi
}

function test_report() {
    report_type=$1
    shift
    result_filename=$1
    shift
    patterns=("$@")
    for line in "${patterns[@]}";
    do
        test_line $report_type $result_filename "${line[@]}"
    done
}

declare -a lines_to_find=("detected java code. we recommend using Corretto"
    "detected python code. min version 3.7.5 is required"
    "detected python code. if you need pip, version 19.3 or above is recommended"
    "dependency library numpy is present. min version 1.19.0 is required"
    "detected java code. min version 8 is required. version 11 or above is recommended"
    "using dependency library snappy-java version 1.1.3. upgrade to at least version 1.1.4"
    "using dependency library hadoop-lzo. this library requires a manual build"
    "dependency library: leveldbjni-all is not supported on Graviton"
    "detected go code. min version 1.16 is required. version 1.18 or above is recommended"
    "using dependency library github.com/golang/snappy version 0.0.1. upgrade to at least version 0.0.2"
)


#!/bin/sh -e
rm -rf ./commit-hook-tests
dotnet test --settings scripts/coverlet.runsettings tests/PortingAssistant.Client.UnitTests/PortingAssistant.Client.UnitTests.csproj -r ./commit-hook-tests
for f in ./commit-hook-tests/**/*.xml
do
  echo ""
  echo "Code Coverage Check: $f"

  coverage=`cat $f | grep "<coverage" | cut -d" " -f 2 | cut -d"=" -f 2 | cut -d"\"" -f 2`
  if [[ (($coverage < 0.20)) ]]
  then
    echo "Code coverage requirement not met. Expected: > 0.20, Actual: $coverage"
    exit 1
  fi
  echo "Code coverage: $coverage"
done


#!/bin/bash -e
rm -rf ./netcore_build/
mkdir ./netcore_build/
(dotnet publish ../csharp/PortingAssistant/PortingAssistant.Api/PortingAssistant.Api.csproj -c Release -f net6.0 -o ./netcore_build/)
(dotnet publish ../csharp/PortingAssistant/PortingAssistant.Telemetry/PortingAssistant.Telemetry.csproj -c Release -f net6.0 -o ./netcore_build/)


#!/bin/bash -e
rm -rf react_build
mkdir react_build
rsync -r --copy-links node_modules/@porting-assistant/react/build/* react_build/


set -xe

echo 'Executing custom build script'

current_package_name=$(brazil-path pkg.name)
package_build_dir=$(brazil-path package-build-root)

# copy assets to app folder
# rsync -avz --exclude 'app' --exclude 'brazil*' --exclude 'private' $package_build_dir/. $package_build_dir/app

echo 'Contents of Build folder'
ls -lhtr $package_build_dir

rm -Rf dist && mkdir -p dist

cp -R $package_build_dir/. dist/

cd dist && rm -Rf brazil* && rm -Rf private

cd ../ && mkdir -p $package_build_dir/app && cp -R dist/. $package_build_dir/app/


#!/bin/bash -e -x
tsc
aws s3 cp s3://portingAssistant-test-solutions/test-solutions.zip .
unzip -o test-solutions.zip
mkdir ../electron/test_store


#!/bin/bash
set -e
echo "bucket_name: $BUCKET_NAME"
echo "simple_replay_extract_overwrite_s3_path: $SIMPLE_REPLAY_EXTRACT_OVERWRITE_S3_PATH"
echo "simple_replay_log_location: $SIMPLE_REPLAY_LOG_LOCATION"
echo "redshift_user_name: $REDSHIFT_USER_NAME"
echo "what_if_timestamp: $WHAT_IF_TIMESTAMP"
echo "simple_replay_extract_start_time: $SIMPLE_REPLAY_EXTRACT_START_TIME"
echo "simple_replay_extract_end_time: $SIMPLE_REPLAY_EXTRACT_END_TIME"
echo "extract_prefix: $EXTRACT_PREFIX"
echo "script_prefix: $SCRIPT_PREFIX"

yum update -y
yum -y install git
yum -y install python3
yum -y install python3-pip
yum -y install aws-cfn-bootstrap
yum -y install gcc gcc-c++ python3 python3-devel unixODBC unixODBC-devel
mkdir amazonutils
cd amazonutils
git clone https://github.com/aws/redshift-test-drive.git
cd redshift-test-drive
make setup
if [[ "$SIMPLE_REPLAY_EXTRACT_OVERWRITE_S3_PATH" != "N/A" ]]; then
  aws s3 cp $SIMPLE_REPLAY_EXTRACT_OVERWRITE_S3_PATH config/replay.yaml
fi
WORKLOAD_LOCATION="s3://${BUCKET_NAME}/${EXTRACT_PREFIX}/${WHAT_IF_TIMESTAMP}"
sed -i "s#master_username: \".*\"#master_username: \"$REDSHIFT_USER_NAME\"#g" config/extract.yaml
sed -i "s#log_location: \".*\"#log_location: \"$SIMPLE_REPLAY_LOG_LOCATION\"#g" config/extract.yaml
sed -i "s#workload_location: \".*\"#workload_location: \"$WORKLOAD_LOCATION\"#g" config/extract.yaml
sed -i "s#start_time: \".*\"#start_time: \"$SIMPLE_REPLAY_EXTRACT_START_TIME\"#g" config/extract.yaml
sed -i "s#end_time: \".*\"#end_time: \"$SIMPLE_REPLAY_EXTRACT_END_TIME\"#g" config/extract.yaml
aws s3 cp config/extract.yaml s3://$BUCKET_NAME/$SCRIPT_PREFIX/
make extract


#!/bin/sh
# This script bootstraps a base amazonlinux image to run the Redshift
# Node Config concurrency test.
# 1. Install the AWS CLI, Python3, and necessary Python libraries.
# 2. Copy Python program source for concurrency test
# 3. Execute that Python program
# We expect all configuration to be defined as environment variables
# for the Batch job.

set -eu

yum install -y awscli python3
pip3 install boto3 psycopg2-binary pandas sqlalchemy

aws s3 cp "$PYTHON_SCRIPT" ./script.py

# This Python program requires these environment variables to be set:
# `$SQL_SCRIPT_S3_PATH`, `$REDSHIFT_CLUSTER_ENDPOINT`,
# `$REDSHIFT_IAM_ROLE`, `$BUCKET_NAME`, `$REDSHIFT_USER_NAME`
python3 ./script.py


#!/bin/bash
set -e
echo "bucket_name: $BUCKET_NAME"
echo "simple_replay_overwrite_s3_path: $SIMPLE_REPLAY_OVERWRITE_S3_PATH"
echo "redshift_user_name: $REDSHIFT_USER_NAME"
echo "what_if_timestamp: $WHAT_IF_TIMESTAMP"
echo "extract_prefix: $EXTRACT_PREFIX"
echo "replay_prefix: $REPLAY_PREFIX"
echo "script_prefix: $SCRIPT_PREFIX"
echo "redshift_iam_role: $REDSHIFT_IAM_ROLE"
echo "workload_location: $WORKLOAD_LOCATION"
echo "cluster_endpoint: $CLUSTER_ENDPOINT"
echo "cluster_identifier: $CLUSTER_IDENTIFIER"
echo "execute_unload_statements: $SIMPLE_REPLAY_UNLOAD_STATEMENTS"
echo "snapshot_account_id: $SNAPSHOT_ACCOUNT_ID"
account_id=`aws sts get-caller-identity --query Account --output text`
echo "account_id: $account_id"
echo "endpoint_type: $ENDPOINT_TYPE"
TARGET_CLUSTER_REGION=$(echo $CLUSTER_ENDPOINT | cut -f3 -d'.')
##region = os.environ['AWS_REGION']
yum update -y
yum -y install git
yum -y install python3
yum -y install python3-pip
yum -y install aws-cfn-bootstrap
yum -y install gcc gcc-c++ python3 python3-devel unixODBC unixODBC-devel
mkdir amazonutils
cd amazonutils
git clone https://github.com/aws/redshift-test-drive.git
cd redshift-test-drive
make setup
if [[ "$SIMPLE_REPLAY_OVERWRITE_S3_PATH" != "N/A" ]]; then
  aws s3 cp $SIMPLE_REPLAY_OVERWRITE_S3_PATH replay.yaml
fi

sed -i "s#master_username: \".*\"#master_username: \"$REDSHIFT_USER_NAME\"#g" config/replay.yaml
sed -i "s#unload_iam_role: \".*\"#unload_iam_role: \"$REDSHIFT_IAM_ROLE\"#g" config/replay.yaml
sed -i "s#workload_location: \".*\"#workload_location: \"$WORKLOAD_LOCATION\"#g" config/replay.yaml
sed -i "s#target_cluster_endpoint: \".*\"#target_cluster_endpoint: \"$CLUSTER_ENDPOINT\"#g" config/replay.yaml
sed -i "s#target_cluster_region: \".*\"#target_cluster_region: \"$TARGET_CLUSTER_REGION\"#g" config/replay.yaml
sed -i "s#analysis_iam_role: \".*\"#analysis_iam_role: \"$REDSHIFT_IAM_ROLE\"#g" config/replay.yaml
sed -i "s#analysis_output: \".*\"#analysis_output: \"$WORKLOAD_LOCATION\"#g" config/replay.yaml

if [ "$SIMPLE_REPLAY_UNLOAD_STATEMENTS" == "true" ]; then
    sed -i "s#unload_iam_role: \".*\"#unload_iam_role: \"$REDSHIFT_IAM_ROLE\"#g" config/replay.yaml
    sed -i "s#replay_output: \".*\"#replay_output: \"s3://$BUCKET_NAME/$REPLAY_PREFIX/$WHAT_IF_TIMESTAMP/$CLUSTER_IDENTIFIER\"#g" config/replay.yaml
fi

if [[ "$account_id" == "$SNAPSHOT_ACCOUNT_ID" ]]; then
   sed -i "s#execute_copy_statements: \"false\"#execute_copy_statements: \"true\"#g" config/replay.yaml
   aws s3 cp $WORKLOAD_LOCATION/copy_replacements.csv . || true
   sed -z -i "s#,,\n#,,$REDSHIFT_IAM_ROLE\n#g" copy_replacements.csv || true
   aws s3 cp copy_replacements.csv $WORKLOAD_LOCATION/copy_replacements.csv || true
fi
aws s3 cp config/replay.yaml s3://$BUCKET_NAME/$SCRIPT_PREFIX/replay_$CLUSTER_IDENTIFIER.yaml
make replay
if [[ $ENDPOINT_TYPE == 'SERVERLESS' ]]; then
  aws s3 cp s3://$BUCKET_NAME/$SCRIPT_PREFIX/system_config.json .
  aws s3 cp s3://$BUCKET_NAME/$SCRIPT_PREFIX/create_external_schema.py .
  python3 tools/NodeConfigCompare/python_scripts/create_external_schema.py
fi


#!/bin/bash

# Simple script to generate key/digest permutations for testing
# keys are shared across certificates with the same algorithm,
# but different digests

ec_digests="sha1 sha256 sha384 sha512"
ec_curves="prime256v1 secp384r1"

rsa_digests="md5 sha1 sha256 sha384 sha512"
rsa_key_lengths="1024 2048 4096"

script=$(readlink -f "$0")
basedir=$(dirname "$script")

for c in $ec_curves; do
	key_file="${basedir}/tst/certs/ec-${c}-key.pem"
	openssl ecparam -name $c -genkey -out $key_file
	for d in $ec_digests; do
		cert_file="${basedir}/tst/certs/ec-${c}-${d}-cert.pem"
		openssl req -x509 -new \
			-key $key_file \
			-out $cert_file \
			-days 365 \
			-subj "/CN=roles-anywhere-${c}-${d}" \
			-${d}
        openssl pkcs8 -topk8 -inform PEM -outform PEM \
            -in ${basedir}/tst/certs/ec-${c}-key.pem \
            -out ${basedir}/tst/certs/ec-${c}-key-pkcs8.pem \
            -nocrypt
	done;
done;

for l in $rsa_key_lengths; do
	key_file="${basedir}/tst/certs/rsa-${l}-key.pem"
	openssl genrsa -out $key_file $l
	for d in $rsa_digests; do
		cert_file="${basedir}/tst/certs/rsa-${l}-${d}-cert.pem"
		openssl req -x509 -new \
			-key $key_file \
			-out $cert_file \
			-days 365 \
			-subj "/CN=roles-anywhere-rsa-${l}"
        openssl pkcs8 -topk8 -inform PEM -outform PEM \
            -in ${basedir}/tst/certs/rsa-${l}-key.pem \
            -out ${basedir}/tst/certs/rsa-${l}-key-pkcs8.pem \
            -nocrypt
	done;
done;

# Create certificate bundle
cp ${basedir}/tst/certs/rsa-2048-sha256-cert.pem ${basedir}/tst/certs/cert-bundle.pem
cat ${basedir}/tst/certs/ec-prime256v1-sha256-cert.pem >> ${basedir}/tst/certs/cert-bundle.pem


#!/bin/bash

# Simple script to generate a CA certificate/private key
# and end-entity certificate/private key for use with
# Roles Anywhere

set -exuo pipefail

script=$(readlink -f "$0")
basedir=$(dirname "$script")
data_folder=${basedir}/credential-process-data

# Create root CA config file
cat > ${data_folder}/root.conf << EOF
[ req ]
distinguished_name = req_distinguished_name
prompt = no

[ req_distinguished_name ]
CN = TEST ROOT

[ v3 ]
basicConstraints = critical,CA:TRUE,pathlen:1
subjectKeyIdentifier = hash
keyUsage = critical, cRLSign, digitalSignature, keyCertSign
authorityKeyIdentifier = keyid:always,issuer:always
EOF

# Create root CA certificate and RSA private key
openssl req -config ${data_folder}/root.conf -days 365 -extensions v3 -keyout ${data_folder}/root-key.pem -newkey rsa:2048 -nodes -out ${data_folder}/root-cert.pem -set_serial 1 -sha256 -x509

# Create client certificate config file
cat > ${data_folder}/client.conf <<EOF
[ req ]
distinguished_name = req_distinguished_name
prompt = no
default_bits = 2048
default_md = sha256

[ req_distinguished_name ]
CN = TEST CLIENT

[ v3 ]
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
EOF

# Create client certificate and RSA private key
openssl req -nodes -new -keyout ${data_folder}/client-key.pem -out ${data_folder}/client-csr.pem -config ${data_folder}/client.conf
openssl x509 -req -in ${data_folder}/client-csr.pem -CA ${data_folder}/root-cert.pem -CAkey ${data_folder}/root-key.pem -set_serial 2 -out ${data_folder}/client-cert.pem -days 365 -sha256 -extfile ${data_folder}/client.conf -extensions v3


# immediately bail if any command fails
set -e

echo "generating CA private key and certificate"
openssl req -nodes -new -x509 -keyout ca-key.pem -out ca-cert.pem -days 65536 -config config/ca.cnf

# secp384r1 is an arbitrarily chosen curve that is supported by the default
# security policy in s2n-tls.
# https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#chart-security-policy-version-to-supported-curvesgroups
echo "generating server private key and CSR"
openssl req  -new -nodes -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout server-key.pem -out server.csr -config config/server.cnf

echo "generating client private key and CSR"
openssl req  -new -nodes -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout client-key.pem -out client.csr -config config/client.cnf

echo "generating server certificate and signing it"
openssl x509 -days 65536 -req -in server.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extensions req_ext -extfile config/server.cnf

echo "generating client certificate and signing it"
openssl x509 -days 65536 -req -in client.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out client-cert.pem -extensions req_ext -extfile config/client.cnf

echo "verifying generated certificates"
openssl verify -CAfile ca-cert.pem server-cert.pem
openssl verify -CAfile ca-cert.pem client-cert.pem

echo "cleaning up temporary files"
rm server.csr
rm client.csr
rm ca-key.pem


#!/usr/bin/env bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

# immediately exit if an error occurs.
set -e

ARTIFACT_FOLDER="target/release"
NETBENCH_ARTIFACT_FOLDER="target/netbench"

# the run_trial function will run the request-response scenario
# with the driver passed in as the first argument
run_trial() {
    # e.g. request-response
    SCENARIO=$1
    # e.g. s2n-quic
    DRIVER=$2
    echo "running the $SCENARIO scenario with $DRIVER"

    # make a directory to hold the collected statistics
    mkdir -p $NETBENCH_ARTIFACT_FOLDER/results/$SCENARIO/$DRIVER

    # run the server while collecting metrics.
    echo "  running the server"
    ./$ARTIFACT_FOLDER/netbench-collector \
    ./$ARTIFACT_FOLDER/netbench-driver-$DRIVER-server \
    --scenario ./$NETBENCH_ARTIFACT_FOLDER/$SCENARIO.json \
    > $NETBENCH_ARTIFACT_FOLDER/results/$SCENARIO/$DRIVER/server.json &
    # store the server process PID. $! is the most recently spawned child pid
    SERVER_PID=$!

    # sleep for a small amount of time to allow the server to startup before the
    # client
    sleep 1

    # run the client. Port 4433 is the default for the server.
    echo "  running the client"
    SERVER_0=localhost:4433 ./$ARTIFACT_FOLDER/netbench-collector \
     ./$ARTIFACT_FOLDER/netbench-driver-$DRIVER-client \
     --scenario ./$NETBENCH_ARTIFACT_FOLDER/$SCENARIO.json \
     > $NETBENCH_ARTIFACT_FOLDER/results/$SCENARIO/$DRIVER/client.json

    # cleanup server processes. The collector PID (which is the parent) is stored in
    # SERVER_PID. The collector forks the driver process. The following incantation
    # kills the child processes as well.
    echo "  killing the server"
    kill $(ps -o pid= --ppid $SERVER_PID)
}

# build all tools in the netbench workspace
cargo build --release

# generate the scenario files. This will generate .json files that can be found
# in the netbench/target/netbench directory. Config for all scenarios is done
# through this binary.
./$ARTIFACT_FOLDER/netbench-scenarios --request_response.response_size=8GiB --connect.connections 42

run_trial request_response s2n-quic
run_trial request_response s2n-tls

run_trial connect s2n-quic
run_trial connect s2n-tls

echo "generating the report"
./$ARTIFACT_FOLDER/netbench-cli report-tree $NETBENCH_ARTIFACT_FOLDER/results $NETBENCH_ARTIFACT_FOLDER/report


#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -e
set -o pipefail

# Set up the routing needed for the simulation
/setup.sh

# The following variables are available for use:
# - ROLE contains the role of this execution context, client or server
# - SERVER_PARAMS contains user-supplied command line parameters
# - CLIENT_PARAMS contains user-supplied command line parameters

LOG_DIR=/logs
LOG=$LOG_DIR/logs.txt

QNS_BIN="perf_client"

CERT_ARGS=""

if [ -d "/certs" ]; then
    CERT_ARGS="--private-key /certs/priv.key --certificate /certs/cert.pem"
fi

# Wait for the simulator to start up.
/wait-for-it.sh sim:57832 -s -t 30
$QNS_BIN  \
  --download-size "$DOWNLOAD_B" \
  --upload-size "$UPLOAD_B" \
  --duration "$DURATION" \
  --json "$LOG_DIR/perf_client.json" \
  server4:443  2>&1 | tee $LOG


#!/bin/bash

#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

./setup.sh
./wait-for-it.sh sim:57832 -s -t 10

if [ "$ROLE" == "server" ]; then
  iperf3 -s
else
   ./wait-for-it.sh $SERVER:5201 -s -t 10
  iperf3 -c $SERVER -t $DURATION -i 1 -R -C $IPERF_CONGESTION --json > /logs/iperf.json
fi


#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -e
set -o pipefail

export RUST_LOG="debug"
export RUST_BACKTRACE="1"

# Set up the routing needed for the simulation
/setup.sh

# The following variables are available for use:
# - ROLE contains the role of this execution context, client or server
# - SERVER_PARAMS contains user-supplied command line parameters
# - CLIENT_PARAMS contains user-supplied command line parameters

LOG_DIR=/logs
LOG=$LOG_DIR/logs.txt

QNS_BIN="s2n-quic-qns"
QNS_MODE=${QNS_MODE:-interop}
TLS=${TLS:-s2n-tls}

# Disable GSO as it does not work with Docker
SERVER_PARAMS+=" --disable-gso"
CLIENT_PARAMS+=" --disable-gso"

ARCH=$(uname -m)
echo $ARCH
if [ "$ARCH" == "aarch64" ] || [ "$ARCH" == "arm64" ]; then
  # x86 images running on ARM hardware may produce incorrect
  # UDP checksums. These commands will force the UDP checksum to
  # be recalculated.
  tc qdisc add dev eth0 handle ffff: ingress
  tc filter add dev eth0 parent ffff: matchall action csum udp
fi

if [ "$QNS_MODE" == "interop" ]; then
    if [ "$ROLE" == "server" ]; then
        SERVER_PARAMS+=" --www-dir /www"
    elif [ "$ROLE" == "client" ]; then
        CLIENT_PARAMS+=" --download-dir /downloads"
    fi

    if [ "$TESTCASE" == "http3" ]; then
        SERVER_PARAMS+=" --application-protocols h3"
        CLIENT_PARAMS+=" --application-protocols h3"
    fi
fi

if [ "$QNS_MODE" == "interop" ]; then
    SERVER_PARAMS+=" --tls $TLS"
    CLIENT_PARAMS+=" --tls $TLS"
fi

if [ "$TEST_TYPE" == "MEASUREMENT" ] && [ -x "$(command -v s2n-quic-qns-release)" ]; then
    echo "using optimized build"
    QNS_BIN="s2n-quic-qns-release"
    unset RUST_LOG
fi

# https://github.com/marten-seemann/quic-interop-runner/blob/1dedeab03da41716bdc3ab84243328ac2409f9fe/README.md#building-a-quic-endpoint
# The Interop Runner generates a key and a certificate chain and mounts it into /certs.
# The server needs to load its private key from priv.key, and the certificate chain from cert.pem.
if [ -d "/certs" ]; then
    if [ "$ROLE" == "server" ]; then
        SERVER_PARAMS+=" --private-key /certs/priv.key --certificate /certs/cert.pem"
    elif [ "$ROLE" == "client" ]; then
        CLIENT_PARAMS+=" --ca /certs/ca.pem"
    fi
fi

if [ "$ROLE" == "client" ]; then
    # Wait for the simulator to start up.
    /wait-for-it.sh sim:57832 -s -t 30
    $QNS_BIN $QNS_MODE client \
        $CLIENT_PARAMS \
        $REQUESTS > $LOG
elif [ "$ROLE" == "server" ]; then
    $QNS_BIN $QNS_MODE server \
        $SERVER_PARAMS > $LOG
fi


#/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

set -e

# cd into the script directory so it can be executed from anywhere
pushd "$(dirname "${BASH_SOURCE[0]}")"

# delete the existing copy in case we have extra files
rm -rf s2n-tls-sys/lib
mkdir -p s2n-tls-sys/lib
mkdir -p s2n-tls-sys/lib/tests
mkdir -p s2n-tls-sys/src/features

# we copy the C sources into the `lib` directory so they get published in the
# actual crate artifact.
cp -r \
  ../../api \
  ../../crypto \
  ../../error \
  ../../pq-crypto \
  ../../stuffer \
  ../../tls \
  ../../utils \
  s2n-tls-sys/lib/

cp -r \
  ../../tests/features \
  s2n-tls-sys/lib/tests/

cp -r \
  ../../CMakeLists.txt \
  ../../cmake \
  s2n-tls-sys/lib/

# generate the bindings modules from the copied sources
pushd generate
cargo run -- ../s2n-tls-sys
popd

# make sure everything builds and passes sanity checks
pushd s2n-tls-sys
cargo test
cargo test --all-features
cargo test --release
cargo publish --dry-run --allow-dirty
cargo publish --dry-run --allow-dirty --all-features
popd

pushd integration
cargo run
popd

popd


# immediately bail if any command fails
set -e

pushd "$(dirname "$0")"

echo "generating CA private key and certificate"
openssl req -nodes -new -x509 -keyout ca-key.pem -out ca-cert.pem -days 65536 -config config/ca.cnf

# secp384r1 is an arbitrarily chosen curve that is supported by the default
# security policy in s2n-tls.
# https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#chart-security-policy-version-to-supported-curvesgroups
echo "generating server private key and CSR"
openssl req  -new -nodes -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout server-key.pem -out server.csr -config config/server.cnf

echo "generating client private key and CSR"
openssl req  -new -nodes -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -keyout client-key.pem -out client.csr -config config/client.cnf

echo "generating server certificate and signing it"
openssl x509 -days 65536 -req -in server.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extensions req_ext -extfile config/server.cnf

echo "generating client certificate and signing it"
openssl x509 -days 65536 -req -in client.csr -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out client-cert.pem -extensions req_ext -extfile config/client.cnf

echo "verifying generated certificates"
openssl verify -CAfile ca-cert.pem server-cert.pem
openssl verify -CAfile ca-cert.pem client-cert.pem

cat server-cert.pem ca-cert.pem > fullchain.pem

echo "cleaning up temporary files"
rm server.csr
rm client.csr
rm ca-key.pem

popd


# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# this script will generate all of the certs used for the tokio examples and
# tests.

# used for TLS 1.2 connections
echo "generating rsa key and cert"
openssl req -x509 -newkey rsa:4096 -keyout key_rsa.pem -out cert_rsa.pem -sha256 -days 36500 -nodes -subj "/C=US/ST=AZ/L=Tempe/O=Maas/OU=BioComputing/CN=localhost"

# used for TLS 1.3 connections
echo "generating ec key and cert"
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout key.pem -out cert.pem -sha256 -days 36500 -nodes -subj "/C=US/ST=AZ/L=Tempe/O=Amazon/OU=AmazonWebServices/CN=localhost"


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

set -ex
pushd "$(pwd)"

usage() {
    echo "build_aws_crt_cpp.sh build_dir install_dir"
    exit 1
}

if [ "$#" -ne "2" ]; then
    usage
fi

source codebuild/bin/s2n_setup_env.sh

BUILD_DIR=$1
INSTALL_DIR=$2

mkdir -p "$BUILD_DIR/s2n"
# In case $BUILD_DIR is a subdirectory of current directory
for file in *;do test "$file" != "$BUILD_DIR" && cp -r "$file" "$BUILD_DIR/s2n";done
cd "$BUILD_DIR"
git clone --depth 1 --shallow-submodules --recurse-submodules https://github.com/awslabs/aws-crt-cpp.git
# Replace S2N
rm -r aws-crt-cpp/crt/s2n
mv s2n aws-crt-cpp/crt/

cmake ./aws-crt-cpp -Bbuild -GNinja -DBUILD_DEPS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
ninja -C ./build install
CTEST_OUTPUT_ON_FAILURE=1 CTEST_PARALLEL_LEVEL=$(nproc) ninja -C ./build test

popd

exit 0


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

# Get a list of changed files
changed_files=$(git diff origin/main --name-only )

# Run clang-format on each changed file
for file in $changed_files
do
    if [[ $file == *.c || $file == *.h ]]; then # Only run on .c and .h files
        echo "clang formatting ${file}"
        clang-format -i $file
    fi
done


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

set -e

S2N_FILES=$(find "$PWD" -type f -name "s2n_*.[ch]")
S2N_FILES+=" "
S2N_FILES+=$(find "$PWD"/codebuild/ -type f -name "*.sh")
S2N_FILES+=" "
S2N_FILES+=$(find "$PWD"/tests/ -type f -name "*.sh")

FAILED=0

for file in $S2N_FILES; do
    # The word "Copyright" should appear at least once in the first 3 lines of every file
    COUNT=`head -3 $file | grep "Copyright" | wc -l`;
    if [ "$COUNT" == "0" ];
    then
        FAILED=1;
        echo "Copyright Check Failed: $file";
    fi
done

if [ $FAILED == 1 ];
then
    printf "\\033[31;1mFAILED Copyright Check\\033[0m\\n"
    exit -1
else
    printf "\\033[32;1mPASSED Copyright Check\\033[0m\\n"
fi


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -e

source codebuild/bin/s2n_setup_env.sh

# LLVM complains about corrupt coverage information
# for static targets, so compile to a shared lib
# instead.
cmake . -Bbuild \
    -DCOVERAGE=ON \
    -DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT \
    -DBUILD_SHARED_LIBS=ON

cmake --build ./build -- -j $(nproc)

echo "done with the build"


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -e

# merge profiling data
llvm-profdata merge -failure-mode=all -sparse tests/unit/ut_*.profraw -o merged.profdata

# generate file-level summary
llvm-cov report build/lib/libs2n.so \
    -instr-profile=merged.profdata \
    > coverage_summary.txt

# convert llvm information to lcov format for genhtml
llvm-cov export build/lib/libs2n.so \
    -instr-profile=merged.profdata \
    -format=lcov \
    > unit_test_coverage.info

# generate html report with annotated source files
genhtml unit_test_coverage.info \
    --branch-coverage \
    -o coverage_report


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

set -e
echo "The codebuild source version is ${CODEBUILD_SOURCE_VERSION}"

CLOUDFRONT_DISTRIBUTION="https://dx1inn44oyl7n.cloudfront.net"

aws s3 sync coverage_report      s3://s2n-tls-public-coverage-artifacts/${CODEBUILD_SOURCE_VERSION}/report
aws s3 cp   coverage_summary.txt s3://s2n-tls-public-coverage-artifacts/${CODEBUILD_SOURCE_VERSION}/summary.txt

echo "report : is at ${CLOUDFRONT_DISTRIBUTION}/${CODEBUILD_SOURCE_VERSION}/report/index.html"
echo "summary: is at ${CLOUDFRONT_DISTRIBUTION}/${CODEBUILD_SOURCE_VERSION}/summary.txt"


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

S2N_FILES=$(find "$PWD" -type f -name "s2n*.[ch]")

FAILED=0

for file in $S2N_FILES; do
    # There should be no c++ style comments: //
    RESULT=`grep -rnv '\*' $file | grep '\B\/\/.*$' | grep -v '\".*\"'`;
    if [ "${#RESULT}" != "0" ];
    then
        FAILED=1;
        printf "\e[1;34mC++ Comments Check Failed in $file:\e[0m\n$RESULT\n\n";
    fi
done

if [ $FAILED == 1 ];
then
    printf "\\033[31;1mFAILED C++ Comments Check\\033[0m\\n"
    exit -1
else
    printf "\\033[32;1mPASSED C++ Comments Check\\033[0m\\n"
fi


#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -eu
source codebuild/bin/s2n_setup_env.sh
source codebuild/bin/utils.sh

# Disable PQ
export S2N_NO_PQ=1
# Limit the number of child processes in the test run
export XDIST_WORKERS=2
export RUST_BACKTRACE=1
export TOX_TEST_NAME="$INTEGV2_TEST"

# There can be only one artifact config per batch job,
# so we're scipting the baseline upload steps here.
upload_artifacts(){
  cd tests/integrationv2/target/criterion
  echo "Creating zip ${AWS_S3_PATH}"
  zip -r "${AWS_S3_PATH}" ./*
  aws s3 cp "${AWS_S3_PATH}" "${AWS_S3_URL}"
  echo "S3 upload complete"
}

if [ -d "third-party-src" ]; then
  echo "Not running against c.a.c."
  return 0
fi

# setting LOCAL_TESTING disables a check for an existing baseline.
if [ -z "${LOCAL_TESTING:-}" ]; then
  # Fetch creds and the latest release number.
  gh_login s2n_codebuild_PRs
  LATEST_RELEASE_VER=$(get_latest_release)
  # Build a specific filename for this release
  AWS_S3_PATH="integv2criterion_${INTEGV2_TEST}_${LATEST_RELEASE_VER}.zip"
  zip_count=$(aws s3 ls "${AWS_S3_URL}${AWS_S3_PATH}"|wc -l||true)

  # Only do the baseline if an artifact for the current release doesn't exist.
  if [ "$zip_count" -eq 0 ]; then
    echo "File ${AWS_S3_URL}${AWS_S3_PATH} not found"
    criterion_install_deps
    ORIGINAL_COMMIT=$(git rev-parse HEAD)
    git fetch --tags
    git checkout "$LATEST_RELEASE_VER"
    S2N_USE_CRITERION=baseline make -C tests/integrationv2 "$INTEGV2_TEST"
    upload_artifacts
    git reset --hard  ${ORIGINAL_COMMIT}
  else
    echo "Found existing artifact for ${LATEST_RELEASE_VER}, not rebuilding."
    exit 0
  fi
else
  echo "Local testing enabled; baselining without checking s3"
  criterion_install_deps
  S2N_USE_CRITERION=baseline make -C tests/integrationv2 "$INTEGV2_TEST"
fi


#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
set -eu
source ./codebuild/bin/utils.sh
# Disable PQ
export S2N_NO_PQ=1
export AWS_S3_BUCKET="s3://s2n-tls-logs/"
# Limit the number of child processes in the test run
export XDIST_WORKERS=4
export RUST_BACKTRACE=1

export GIT_COMMIT=$(git log -n 1 --format="%h")
export AWS_S3_REPORT_PATH="reports/${INTEGV2_TEST}/$(date +%Y%m%d_%H%M_${GIT_COMMIT})"

# CodeBuild artifacts are too limited;
# scipting the baseline download steps here.
download_artifacts(){
  mkdir -p ./tests/integrationv2/target/criterion || true
  echo "Downloading ${AWS_S3_BUCKET}${1}/${2}"
  pushd  ./tests/integrationv2/target/criterion/
  aws s3 cp "${AWS_S3_BUCKET}${1}/${2}" .
  unzip -o "${2}"
  echo "S3 download complete"
  popd
}

upload_report(){
  cd tests/integrationv2/target/criterion
  echo "Uploading report to ${AWS_S3_BUCKET}/${AWS_S3_REPORT_PATH}"
  aws s3 sync . "${AWS_S3_BUCKET}${AWS_S3_REPORT_PATH}"
  echo "S3 upload complete"
}

# Fetch creds and the latest release number.
gh_login s2n_codebuild_PRs
LATEST_RELEASE_VER=$(get_latest_release)
AWS_ZIPFILE="integv2criterion_${INTEGV2_TEST}_${LATEST_RELEASE_VER}.zip"
AWS_S3_BASE_PATH="release"
criterion_install_deps
download_artifacts ${AWS_S3_BASE_PATH} ${AWS_ZIPFILE}

echo "Current dir: $(pwd)"
S2N_USE_CRITERION=delta make -C tests/integrationv2 "$INTEGV2_TEST"
upload_report


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -e
CLANG_NINE=$(which clang-format-9)
CLANG_VER=${CLANG_NINE:-clang-format}
for i in $(find . -not -path "./test-deps/*" -name '*.h' -or -name '*.c' -or -name '*.cpp'); do
        $CLANG_VER --verbose -i "$i" ;
done

if [[ `git status --porcelain` ]]; then
        echo "clang-format updated files, throwing an error"
        exit 255
else
        echo "No files touched"
fi


#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

FAILED=0

#############################################
# Grep for any instances of raw memcpy() function. s2n code should instead be
# using one of the *_ENSURE_MEMCPY macros.
#############################################
S2N_FILES_ASSERT_NOT_USING_MEMCPY=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/tests/*"  -not -path "*/pq-crypto/*")
for file in $S2N_FILES_ASSERT_NOT_USING_MEMCPY; do
  RESULT_NUM_LINES=`grep 'memcpy(' $file | wc -l`
  if [ "${RESULT_NUM_LINES}" != 0 ]; then
    echo "Found ${RESULT_NUM_LINES} raw 'memcpy' calls in $file"
    FAILED=1
  fi
done

#############################################
# Grep for any instances of raw memcmp() function. s2n code should instead be
# using s2n_constant_time_equals()
#
# KNOWN_MEMCMP_USAGE is used to capture all known uses of memcmp and acts as a
# safeguard against any new uses of memcmp.
#############################################
S2N_FILES_ASSERT_NOT_USING_MEMCMP=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/tests/*" -not -path "*/bindings/*")
declare -A KNOWN_MEMCMP_USAGE
KNOWN_MEMCMP_USAGE["$PWD/crypto/s2n_rsa.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_early_data.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_kem.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_cipher_suites.c"]=3
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_server_hello.c"]=3
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_security_policies.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_psk.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_config.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_resume.c"]=2
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_connection.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/tls/s2n_protocol_preferences.c"]=1
KNOWN_MEMCMP_USAGE["$PWD/utils/s2n_map.c"]=3
KNOWN_MEMCMP_USAGE["$PWD/stuffer/s2n_stuffer_text.c"]=1

for file in $S2N_FILES_ASSERT_NOT_USING_MEMCMP; do
  # NOTE: this matches on 'memcmp', which will also match comments. However, there
  # are no uses of 'memcmp' in comments so we opt for this stricter check.
  RESULT_NUM_LINES=`grep -n 'memcmp' $file | wc -l`

  # set default KNOWN_MEMCMP_USAGE value
  [ -z "${KNOWN_MEMCMP_USAGE["$file"]}" ] && KNOWN_MEMCMP_USAGE["$file"]="0"

  # check if memcmp usage is 0 or a known value
  if [ "${RESULT_NUM_LINES}" != "${KNOWN_MEMCMP_USAGE["$file"]}" ]; then
    echo "Expected: ${KNOWN_MEMCMP_USAGE["$file"]} Found: ${RESULT_NUM_LINES} usage of 'memcmp' in $file"
    FAILED=1
  fi
done

#############################################
# Assert that functions do not return -1 or S2N_ERR* codes directly.
# To indicate failure, functions should use the S2N_ERROR* macros defined
# in s2n_errno.h.
#############################################
S2N_FILES_ASSERT_RETURN=$(find "$PWD" -type f -name "s2n*.c" -not -path "*/tests/*" -not -path "*/docs/examples/*")
for file in $S2N_FILES_ASSERT_RETURN; do
  RESULT_NEGATIVE_ONE=`grep -rn 'return -1;' $file`
  RESULT_S2N_ERR=`grep -rn 'return S2N_ERR*' $file`
  RESULT_S2N_FAIL=`grep -rn 'return S2N_FAIL*' $file`

  if [ "${#RESULT_NEGATIVE_ONE}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mGrep for 'return -1;' check failed in $file:\e[0m\n$RESULT_NEGATIVE_ONE\n\n"
  fi
  if [ "${#RESULT_S2N_ERR}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mGrep for 'return S2N_ERR*' check failed in $file:\e[0m\n$RESULT_S2N_ERR\n\n"
  fi
  if [ "${#RESULT_S2N_FAIL}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mGrep for 'return S2N_FAIL*' check failed in $file:\e[0m\n$RESULT_S2N_FAIL\n\n"
  fi
done

#############################################
# Detect any array size calculations that are not using the s2n_array_len() function.
#############################################
S2N_FILES_ARRAY_SIZING_RETURN=$(find "$PWD" -type f -name "s2n*.c" -path "*")
for file in $S2N_FILES_ARRAY_SIZING_RETURN; do
  RESULT_ARR_DIV=`grep -Ern 'sizeof\((.*)\) \/ sizeof\(\1\[0\]\)' $file`

  if [ "${#RESULT_ARR_DIV}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mUsage of 'sizeof(array) / sizeof(array[0])' check failed. Use s2n_array_len(array) instead in $file:\e[0m\n$RESULT_ARR_DIV\n\n"
  fi
done

#############################################
# Assert that all assignments from s2n_stuffer_raw_read() have a
# notnull_check (or similar manual null check) on the same, or next, line.
# The assertion is shallow; this doesn't guarantee that we're doing the
# *correct* null check, just that we are doing *some* null check.
#############################################
S2N_FILES_ASSERT_NOTNULL_CHECK=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/tests/*")
for file in $S2N_FILES_ASSERT_NOTNULL_CHECK; do
  while read -r line_one; do
    # When called with the -A option, grep uses lines of "--" as delimiters. We ignore them.
    if [[ $line_one == "--" ]]; then
      continue
    fi

    read -r line_two

    # $line_one definitely contains an assignment from s2n_stuffer_raw_read(),
    # because that's what we grepped for. So verify that either $line_one or
    # $line_two contains a null check.
    null_check_regex="(.*(if|ENSURE).*=\ NULL)|(ENSURE_REF)"
    if [[ $line_one =~ $null_check_regex ]] || [[ $line_two =~ $null_check_regex ]]; then
      # Found a notnull_check
      continue
    else
      FAILED=1
      printf "\e[1;34mFound a call to s2n_stuffer_raw_read without an ENSURE_REF in $file:\e[0m\n$line_one\n\n"
    fi
  done < <(grep -rnE -A 1 "=\ss2n_stuffer_raw_read\(.*\)" $file)
done

#############################################
# Assert that "index" is not a variable name. An "index" function exists in strings.h, and older compilers (<GCC 4.8)
# warn if any local variables called "index" are used because they are considered to shadow that declaration.
#############################################
S2N_FILES_ASSERT_VARIABLE_NAME_INDEX=$(find "$PWD" -type f -name "s2n*.[ch]")
for file in $S2N_FILES_ASSERT_VARIABLE_NAME_INDEX; do
  RESULT_VARIABLE_NAME_INDEX=`gcc -fpreprocessed -dD -E -w $file | grep -v '"' | grep '[\*|,|;|[:space:]]index[;|,|\)|[:space:]]'`
  if [ "${#RESULT_VARIABLE_NAME_INDEX}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mGrep for variable name 'index' check failed in $file:\e[0m\n$RESULT_VARIABLE_NAME_INDEX\n\n"
  fi
done

#############################################
# Assert that we didn't accidentally add an extra semicolon when ending a line.
# This also errors when there is whitespace in-between semicolons, as that is an empty
# statement and usually not purposeful.
#############################################
S2N_FILES_ASSERT_DOUBLE_SEMICOLON=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/bindings/*")
for file in $S2N_FILES_ASSERT_DOUBLE_SEMICOLON; do
  RESULT_DOUBLE_SEMICOLON=`grep -Ern ';[[:space:]]*;' $file`
  if [ "${#RESULT_DOUBLE_SEMICOLON}" != "0" ]; then
    FAILED=1
    printf "\e[1;34mFound a double semicolon in $file:\e[0m\n$RESULT_DOUBLE_SEMICOLON\n\n"
  fi
done

#############################################
## Assert that there are no new uses of S2N_ERROR_IF
# TODO add crypto, tls (see https://github.com/aws/s2n-tls/issues/2635)
#############################################
S2N_ERROR_IF_FREE="bin error pq-crypto scram stuffer utils tests"
for dir in $S2N_ERROR_IF_FREE; do
  files=$(find "$dir" -type f -name "*.c" -path "*")
  for file in $files; do
    result=`grep -Ern 'S2N_ERROR_IF' $file`
    if [ "${#result}" != "0" ]; then
      FAILED=1
      printf "\e[1;34mUsage of 'S2N_ERROR_IF' check failed. Use 'POSIX_ENSURE' instead in $file:\e[0m\n$result\n\n"
    fi
  done
done

#############################################
## Assert all ".[c|h]" source files have the correct file mode.
#############################################
S2N_FILES_WITH_WRONG_MODE=$(find "$PWD" \( -name '*.c' -o -name '*.h' \) -a \! -perm 644)
if [[ -n $S2N_FILES_WITH_WRONG_MODE ]]; then
  for file in $S2N_FILES_WITH_WRONG_MODE; do
    FAILED=1
    printf "\\033[31;1mFile mode of %s is not 644.\\033[0m\\n" "$file"
  done
  printf "\\033[31;1mPlease run \`find s2n-tls/ -name '*.c' -o -name '*.h' -exec chmod 644 {} \\;\` to fix all file modes.\\033[0m\\n"
fi

#############################################
## Assert "extern" is not added to function declarations unnecessarily.
#############################################
S2N_UNNECESSARY_EXTERNS=$(find "$PWD" -type f -name "s2n*.[h]" \! -path "*/api/*" \! -path "*/bindings/*" \
  -exec grep -RE "extern (.*?) (.*?)\(" {} +)
if [[ -n $S2N_UNNECESSARY_EXTERNS ]]; then
  FAILED=1
  printf "\e[1;34mFound unnecessary 'extern' in function declaration:\e[0m\n"
  printf "$S2N_UNNECESSARY_EXTERNS\n\n"
fi

#############################################
# Assert ENSURE/GUARD have a valid error code
#############################################
S2N_ENSURE_WITH_INVALID_ERROR_CODE=$(find "$PWD" -type f -name "s2n*.c" -path "*" \! -path "*/tests/*" \
    -exec grep -RE "(ENSURE|GUARD_OSSL)\(.*?, .*?);" {} + | grep -v "S2N_ERR_")
if [[ -n $S2N_ENSURE_WITH_INVALID_ERROR_CODE ]]; then
  FAILED=1
  printf "\e[1;34mENSURE and GUARD_OSSL require a valid error code from errors/s2n_errno.h:\e[0m\n"
  printf "$S2N_ENSURE_WITH_INVALID_ERROR_CODE\n\n"
fi

#############################################
# REPORT FINAL RESULTS
#############################################
if [ $FAILED == 1 ]; then
  printf "\\033[31;1mFAILED Grep For Simple Mistakes check\\033[0m\\n"
  exit -1
else
  printf "\\033[32;1mPASSED Grep For Simple Mistakes check\\033[0m\\n"
fi


#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

set -eu
source ./codebuild/bin/s2n_setup_env.sh

if [[ ${DISTRO} != "amazon linux" ]]; then
    echo "Target AL2, but running on $DISTRO: Nothing to do."
    exit 0
fi

base_packages() {
    # Latest AL2 image had dependency issues related to NodeJS.
    # We don't use NodeJS, so just remove it.
    yum erase -y nodejs || true
    yum update -y
    # The default openssl-devel on AL2 is openssl-1.0.
    # We replace it with openssl-1.1 later in the build process.
    yum erase -y openssl-devel || true
    yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true
    yum install amazon-linux-extras

    # Who owns this package? It needs updating to not install modules under python2.7
    PYTHON=$(which python2) amazon-linux-extras install -y ruby2.6 rust1 python3.8
    PYTHON=$(which python2) amazon-linux-extras enable epel
    PYTHON=$(which python2) amazon-linux-extras enable corretto8
    yum install -y openssh-clients
}

mono() {
    rpm --import https://download.mono-project.com/repo/xamarin.gpg
    curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo
}

symlink_all_the_things() {
    # Package owners should be doing this.
    # Note the version number at the end allows for upgrades to supersede these.
    update-alternatives --install /usr/bin/pip pip3 /usr/bin/pip3 300
    update-alternatives --install /usr/bin/ninja ninja /usr/bin/ninja-build 170
    update-alternatives --install /usr/bin/cmake cmake /usr/bin/cmake3 313
    update-alternatives --install /usr/bin/gcc-7 gcc /usr/bin/gcc 700
    update-alternatives --install /usr/bin/g++-7 g++ /usr/bin/g++ 700
    update-alternatives --install /usr/bin/g++-7 g++ /usr/bin/g++ 700
}

base_packages
mono
yum groupinstall -y "Development tools"
yum install -y clang cmake3 iproute net-tools nettle-devel nettle openssl11-static openssl11-libs openssl11-devel which sudo psmisc python3-pip  tcpdump unzip zlib-devel libtool ninja-build valgrind  wget which
symlink_all_the_things


#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#

set -eu
source codebuild/bin/s2n_setup_env.sh

usage() {
    echo "install_apache2.sh config_dir install_dir"
    exit 1
}

if [ "$#" -ne "2" ]; then
    usage
fi

APACHE2_CONFIG_DIR="$1"
APACHE2_INSTALL_DIR="$2"

apache_enable() {
    item_type="$1"
    item="$2"
    required="$3"

    source_path="/etc/apache2/${item_type}-available/${item}"
    dest_path="${APACHE2_INSTALL_DIR}/${item_type}-enabled/${item}"

    if [ ! -f "${source_path}" ]; then
        if [ "$required" = true ]; then
            echo "apache item not found: ${source_path}"
            exit 1
        fi

        return
    fi

    ln -s "$source_path" "$dest_path"
}

mod_enable() {
    mod="$1"
    apache_enable "mods" "${mod}.load" true
    apache_enable "mods" "${mod}.conf" false
}

conf_enable() {
    conf="$1"
    apache_enable "conf" "${conf}.conf" true
}

cp -r "${APACHE2_CONFIG_DIR}" "${APACHE2_INSTALL_DIR}"
mkdir "${APACHE2_INSTALL_DIR}/mods-enabled"
mkdir "${APACHE2_INSTALL_DIR}/conf-enabled"
mkdir "${APACHE2_INSTALL_DIR}/run"
mkdir "${APACHE2_INSTALL_DIR}/lock"
mkdir "${APACHE2_INSTALL_DIR}/log"

# Enable default mods
DEFAULT_MODS=("access_compat" "alias" "auth_basic" "authn_core" "authn_file" "authz_core" "authz_host" "authz_user"
              "autoindex" "deflate" "dir" "env" "filter" "mime" "mpm_event" "negotiation" "reqtimeout" "setenvif"
              "socache_shmcb" "status" "ssl")
for mod in "${DEFAULT_MODS[@]}"; do
    mod_enable "$mod"
done

# Enable default configuration
DEFAULT_CONF=("charset" "localized-error-pages" "other-vhosts-access-log" "security" "serve-cgi-bin")
for conf in "${DEFAULT_CONF[@]}"; do
    conf_enable "$conf"
done


#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

set -e
pushd "$(pwd)"

usage() {
    echo "install_awslc.sh build_dir install_dir is_fips"
    exit 1
}

if [ "$#" -ne "3" ]; then
    usage
fi

BUILD_DIR=$1
INSTALL_DIR=$2
IS_FIPS=$3

source codebuild/bin/jobs.sh

# These tags represents the latest versions that S2N is compatible
# with. It prevents our build system from breaking when AWS-LC
# is updated, last done on 2023-02-22.
if [ "$IS_FIPS" == "1" ]; then
  AWSLC_VERSION=AWS-LC-FIPS-1.0.3
else
  AWSLC_VERSION=v1.8.0
fi
mkdir -p "$BUILD_DIR"||true
cd "$BUILD_DIR"
echo "Checking out tag=$AWSLC_VERSION"
# --branch can also take tags and detaches the HEAD at that commit in the resulting repository
# --depth 1 Create a shallow clone with a history truncated to 1 commit
git clone https://github.com/awslabs/aws-lc.git --branch "$AWSLC_VERSION" --depth 1

install_awslc() {
	echo "Building with shared library=$1"
	cmake ./aws-lc -Bbuild -GNinja -DBUILD_SHARED_LIBS=$1 -DCMAKE_BUILD_TYPE=relwithdebinfo -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" -DFIPS="${IS_FIPS}"
	ninja -j "${JOBS}" -C build install
	ninja -C build clean
}

if [ "$IS_FIPS" != "1" ]; then
  install_awslc 0
fi

install_awslc 1

exit 0