From 8db384e2690b3b4e6bf8902322f2226b2a9d6afb Mon Sep 17 00:00:00 2001 From: Dylane Bengono Date: Mon, 26 Aug 2024 12:35:42 +0100 Subject: [PATCH] chore: Update Snort build workflow to use /tmp/work directory --- .github/workflows/package-snort.yml | 93 +--------------------- scripts/snort3.sh | 117 ++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 90 deletions(-) create mode 100644 scripts/snort3.sh diff --git a/.github/workflows/package-snort.yml b/.github/workflows/package-snort.yml index 0caae62..c235a0e 100644 --- a/.github/workflows/package-snort.yml +++ b/.github/workflows/package-snort.yml @@ -21,97 +21,10 @@ jobs: with: go-version: "1.22.4" - - name: Install dependencies + - name: Install dependencies and build Snort run: | - sudo apt-get update && sudo apt-get install -y --no-install-recommends \ - git libtool pkg-config autoconf gettext \ - libpcap-dev g++ vim make cmake wget libssl-dev \ - liblzma-dev python3-pip unzip protobuf-compiler \ - golang nano net-tools automake checkinstall - - - name: Build and install Snort - run: | - # Variables - LIBDAQ_VERSION=3.0.15 - LIBDNET_VERSION=1.14 - FLEX_VERSION=2.6.4 - HWLOC_VERSION=2.5.0 - PCRE_VERSION=8.45 - ZLIB_VERSION=1.2.13 - SNORT_VER=3.2.2.0 - WORK_DIR=/tmp/work - - # Create working directories - sudo mkdir -p $WORK_DIR - sudo chown $USER:$USER $WORK_DIR - - # Install libdaq - cd $WORK_DIR - wget https://github.com/snort3/libdaq/archive/refs/tags/v${LIBDAQ_VERSION}.tar.gz - tar -xvf v${LIBDAQ_VERSION}.tar.gz - cd libdaq-${LIBDAQ_VERSION} - ./bootstrap && ./configure && make && sudo make install - cd $WORK_DIR - rm -rf v${LIBDAQ_VERSION}.tar.gz - - # Install libdnet - wget https://github.com/ofalk/libdnet/archive/refs/tags/libdnet-${LIBDNET_VERSION}.tar.gz - tar -xvf libdnet-${LIBDNET_VERSION}.tar.gz - cd libdnet-libdnet-${LIBDNET_VERSION} - ./configure && make && sudo make install - cd $WORK_DIR - rm -rf libdnet-${LIBDNET_VERSION} libdnet-${LIBDNET_VERSION}.tar.gz - - # Install Flex - wget https://github.com/westes/flex/releases/download/v${FLEX_VERSION}/flex-${FLEX_VERSION}.tar.gz - tar -xvf flex-${FLEX_VERSION}.tar.gz - cd flex-${FLEX_VERSION} - ./configure && make && sudo make install - cd $WORK_DIR - rm -rf flex-${FLEX_VERSION} flex-${FLEX_VERSION}.tar.gz - - # Install hwloc - wget https://download.open-mpi.org/release/hwloc/v2.5/hwloc-${HWLOC_VERSION}.tar.gz - tar -xvf hwloc-${HWLOC_VERSION}.tar.gz - cd hwloc-${HWLOC_VERSION} - ./configure && make && sudo make install - cd $WORK_DIR - rm -rf hwloc-${HWLOC_VERSION} hwloc-${HWLOC_VERSION}.tar.gz - - # Install LuaJIT with update - cd $WORK_DIR - git clone https://luajit.org/git/luajit.git - cd luajit - make && sudo make install - cd $WORK_DIR - rm -rf luajit - - # Install PCRE - wget https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz - tar -xvf pcre-${PCRE_VERSION}.tar.gz - cd pcre-${PCRE_VERSION} - ./configure && make && sudo make install - cd $WORK_DIR - rm -rf pcre-${PCRE_VERSION} pcre-${PCRE_VERSION}.tar.gz - - # Install zlib - wget https://github.com/madler/zlib/releases/download/v${ZLIB_VERSION}/zlib-${ZLIB_VERSION}.tar.gz - tar -xvf zlib-${ZLIB_VERSION}.tar.gz - cd zlib-${ZLIB_VERSION} - ./configure && make && sudo make install - cd $WORK_DIR - rm -rf zlib-${ZLIB_VERSION} zlib-${ZLIB_VERSION}.tar.gz - - # Install Snort 3 - wget https://github.com/snort3/snort3/archive/refs/tags/${SNORT_VER}.tar.gz - tar -xvf ${SNORT_VER}.tar.gz - cd snort3-${SNORT_VER} - export my_path=/usr/local - ./configure_cmake.sh --prefix=$my_path - cd build - make -j$(nproc) install - cd $WORK_DIR - rm -rf snort3-${SNORT_VER} ${SNORT_VER}.tar.gz + chmod +x /scripts/snort3.sh + /scripts/snort3.sh - name: Create Debian package run: | diff --git a/scripts/snort3.sh b/scripts/snort3.sh new file mode 100644 index 0000000..3c0de85 --- /dev/null +++ b/scripts/snort3.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +set -e + +# Variables +LIBDAQ_VERSION=3.0.15 +LIBDNET_VERSION=1.14 +FLEX_VERSION=2.6.4 +HWLOC_VERSION=2.5.0 +PCRE_VERSION=8.45 +ZLIB_VERSION=1.2.13 +SNORT_VER=3.2.2.0 +ARCH=$(dpkg --print-architecture) + +# Disable interactive prompts +export DEBIAN_FRONTEND=noninteractive + +# Update system and install dependencies +sudo apt-get update && sudo apt-get install -y --no-install-recommends \ + git libtool pkg-config autoconf gettext \ + libpcap-dev g++ vim make cmake wget libssl-dev \ + liblzma-dev python3-pip unzip protobuf-compiler \ + golang nano net-tools automake + +# Install Go +if [ "$ARCH" = "amd64" ]; then + GO_BIN=go1.22.4.linux-amd64.tar.gz +elif [ "$ARCH" = "arm64" ]; then + GO_BIN=go1.22.4.linux-arm64.tar.gz +else + echo "Unsupported architecture"; exit 1 +fi +wget https://go.dev/dl/${GO_BIN} +tar -xvf ${GO_BIN} +sudo mv go /usr/local +rm -rf ${GO_BIN} +export PATH=$PATH:/usr/local/go/bin + +# Install protoc-gen-go and protoc-gen-go-grpc +go install github.com/golang/protobuf/protoc-gen-go@v1.5.2 +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0 +sudo mv ~/go/bin/protoc-gen-go /usr/local/bin/ +sudo mv ~/go/bin/protoc-gen-go-grpc /usr/local/bin/ + +# Create working directories +WORK_DIR=/work +sudo mkdir -p $WORK_DIR + +# Install libdaq +cd $WORK_DIR +wget https://github.com/snort3/libdaq/archive/refs/tags/v${LIBDAQ_VERSION}.tar.gz +tar -xvf v${LIBDAQ_VERSION}.tar.gz +cd libdaq-${LIBDAQ_VERSION} +./bootstrap && ./configure && make && sudo make install +cd $WORK_DIR +rm -rf v${LIBDAQ_VERSION}.tar.gz + +# Install libdnet +wget https://github.com/ofalk/libdnet/archive/refs/tags/libdnet-${LIBDNET_VERSION}.tar.gz +tar -xvf libdnet-${LIBDNET_VERSION}.tar.gz +cd libdnet-libdnet-${LIBDNET_VERSION} +./configure && make && sudo make install +cd $WORK_DIR +rm -rf libdnet-${LIBDNET_VERSION} libdnet-${LIBDNET_VERSION}.tar.gz + +# Install Flex +wget https://github.com/westes/flex/releases/download/v${FLEX_VERSION}/flex-${FLEX_VERSION}.tar.gz +tar -xvf flex-${FLEX_VERSION}.tar.gz +cd flex-${FLEX_VERSION} +./configure && make && sudo make install +cd $WORK_DIR +rm -rf flex-${FLEX_VERSION} flex-${FLEX_VERSION}.tar.gz + +# Install hwloc +wget https://download.open-mpi.org/release/hwloc/v2.5/hwloc-${HWLOC_VERSION}.tar.gz +tar -xvf hwloc-${HWLOC_VERSION}.tar.gz +cd hwloc-${HWLOC_VERSION} +./configure && make && sudo make install +cd $WORK_DIR +rm -rf hwloc-${HWLOC_VERSION} hwloc-${HWLOC_VERSION}.tar.gz + +# Install LuaJIT with update +cd $WORK_DIR +git clone https://luajit.org/git/luajit.git +cd luajit +make && sudo make install +cd $WORK_DIR +rm -rf luajit + +# Install PCRE +wget https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz +tar -xvf pcre-${PCRE_VERSION}.tar.gz +cd pcre-${PCRE_VERSION} +./configure && make && sudo make install +cd $WORK_DIR +rm -rf pcre-${PCRE_VERSION} pcre-${PCRE_VERSION}.tar.gz + +# Install zlib +wget https://github.com/madler/zlib/releases/download/v${ZLIB_VERSION}/zlib-${ZLIB_VERSION}.tar.gz +tar -xvf zlib-${ZLIB_VERSION}.tar.gz +cd zlib-${ZLIB_VERSION} +./configure && make && sudo make install +cd $WORK_DIR +rm -rf zlib-${ZLIB_VERSION} zlib-${ZLIB_VERSION}.tar.gz + +# Install Snort 3 +wget https://github.com/snort3/snort3/archive/refs/tags/${SNORT_VER}.tar.gz +tar -xvf ${SNORT_VER}.tar.gz +cd snort3-${SNORT_VER} +export my_path=/usr/local +./configure_cmake.sh --prefix=$my_path +cd build +make -j$(nproc) install +cd $WORK_DIR +rm -rf snort3-${SNORT_VER} ${SNORT_VER}.tar.gz + +echo "Snort 3 installation is complete." \ No newline at end of file