2020-07-15 20:13:51 +00:00
|
|
|
#!/bin/bash
|
2021-04-19 11:40:47 +00:00
|
|
|
if [ -z "$GITHUB_WORKSPACE" ];then
|
|
|
|
echo "GITHUB_WORKSPACE environemnt variable not set!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-07-15 20:13:51 +00:00
|
|
|
if [ "$#" -ne 1 ];then
|
|
|
|
echo "Usage: ${0} [x86|x86_64|armhf|aarch64]"
|
|
|
|
echo "Example: ${0} x86_64"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-04-19 11:40:47 +00:00
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
set -x
|
2020-07-15 20:13:51 +00:00
|
|
|
source $GITHUB_WORKSPACE/build/lib.sh
|
|
|
|
init_lib $1
|
|
|
|
|
|
|
|
build_nmap() {
|
|
|
|
fetch "https://github.com/nmap/nmap.git" "${BUILD_DIRECTORY}/nmap" git
|
|
|
|
cd "${BUILD_DIRECTORY}/nmap"
|
|
|
|
git clean -fdx || true
|
|
|
|
# make sure we only build the static libraries
|
|
|
|
sed -i '/build-zlib: $(ZLIBDIR)\/Makefile/!b;n;c\\t@echo Compiling zlib; cd $(ZLIBDIR) && $(MAKE) static;' "${BUILD_DIRECTORY}/nmap/Makefile.in"
|
|
|
|
CC='gcc -static -fPIC' \
|
|
|
|
CXX='g++ -static -static-libstdc++ -fPIC' \
|
|
|
|
LD=ld \
|
|
|
|
LDFLAGS="-L/build/openssl" \
|
|
|
|
./configure \
|
|
|
|
--host="$(get_host_triple)" \
|
|
|
|
--without-ndiff \
|
|
|
|
--without-zenmap \
|
|
|
|
--without-nmap-update \
|
|
|
|
--without-libssh2 \
|
|
|
|
--with-pcap=linux \
|
|
|
|
--with-openssl="${BUILD_DIRECTORY}/openssl"
|
|
|
|
sed -i -e "s/shared\: /shared\: #/" "${BUILD_DIRECTORY}/nmap/libpcap/Makefile"
|
|
|
|
make
|
|
|
|
strip nmap ncat/ncat nping/nping
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
lib_build_openssl
|
|
|
|
build_nmap
|
2020-11-04 11:41:52 +00:00
|
|
|
if [ ! -f "${BUILD_DIRECTORY}/nmap/nmap" -o \
|
|
|
|
! -f "${BUILD_DIRECTORY}/nmap/ncat/ncat" -o \
|
|
|
|
! -f "${BUILD_DIRECTORY}/nmap/nping/nping" ];then
|
2020-07-15 20:13:51 +00:00
|
|
|
echo "[-] Building Nmap ${CURRENT_ARCH} failed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
VERSION_CMD=$(get_version "${BUILD_DIRECTORY}/nmap/nmap --version")
|
|
|
|
NMAP_VERSION=$(echo "$VERSION_CMD" | grep "Nmap version" | awk '{print $3}')
|
|
|
|
if [ -n "$NMAP_VERSION" ];then
|
|
|
|
NMAP_VERSION="-${NMAP_VERSION}"
|
|
|
|
fi
|
|
|
|
cp "${BUILD_DIRECTORY}/nmap/nmap" "${OUTPUT_DIRECTORY}/nmap${NMAP_VERSION}"
|
|
|
|
cp "${BUILD_DIRECTORY}/nmap/ncat/ncat" "${OUTPUT_DIRECTORY}/ncat${NMAP_VERSION}"
|
|
|
|
cp "${BUILD_DIRECTORY}/nmap/nping/nping" "${OUTPUT_DIRECTORY}/nping${NMAP_VERSION}"
|
|
|
|
echo "[+] Finished building Nmap ${CURRENT_ARCH}"
|
|
|
|
NMAP_COMMIT=$(cd "${BUILD_DIRECTORY}/nmap/" && git rev-parse --short HEAD)
|
|
|
|
NMAP_DIR="${OUTPUT_DIRECTORY}/nmap-data${NMAP_VERSION}-${NMAP_COMMIT}"
|
|
|
|
if [ ! -d "$NMAP_DIR" ];then
|
|
|
|
echo "[-] ${NMAP_DIR} does not exist, creating it"
|
|
|
|
mkdir -p "${NMAP_DIR}"
|
|
|
|
fi
|
|
|
|
if [ -n "$(ls $NMAP_DIR)" ];then
|
|
|
|
echo "[+] Data directory is not empty"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
cd "${BUILD_DIRECTORY}/nmap"
|
|
|
|
make install
|
2020-11-04 11:41:52 +00:00
|
|
|
cp -r /usr/local/share/nmap/* $NMAP_DIR
|
2020-07-15 20:13:51 +00:00
|
|
|
echo "[+] Copied data to Nmap data dir"
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|