From 65ffd4fd255b9528b82817ff8fb5c90d6c3a1944 Mon Sep 17 00:00:00 2001 From: Yiyao Yu Date: Sat, 20 Apr 2024 18:22:06 -0700 Subject: [PATCH] Initial setup --- .gitignore | 5 +++ 00-cpp_compat.patch | 22 ++++++++++ Dockerfile | 97 +++++++++++++++++++++++++++++++++++++++++++++ Makefile | 44 ++++++++++++++++++++ README.md | 37 +++++++++++++++++ mobileinsight.def | 11 +++++ 6 files changed, 216 insertions(+) create mode 100644 .gitignore create mode 100644 00-cpp_compat.patch create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 mobileinsight.def diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..730dfce --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.tar.gz +*.sif +.docker_build +overlay/ +shared/ diff --git a/00-cpp_compat.patch b/00-cpp_compat.patch new file mode 100644 index 0000000..52818c4 --- /dev/null +++ b/00-cpp_compat.patch @@ -0,0 +1,22 @@ +--- epan.h.old 2024-04-20 00:34:15.534364916 -0700 ++++ epan.h 2024-04-20 00:34:25.094467480 -0700 +@@ -10,9 +10,6 @@ + #ifndef __EPAN_H__ + #define __EPAN_H__ + +-#ifdef __cplusplus +-extern "C" { +-#endif /* __cplusplus */ + + #include + #include +@@ -22,6 +19,9 @@ + #include + #include "ws_symbol_export.h" + ++#ifdef __cplusplus ++extern "C" { ++#endif /* __cplusplus */ + + /** Global variable holding the content of the corresponding environment variable + * to save fetching it repeatedly. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b79eefd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,97 @@ +FROM ubuntu:22.04 + +ARG MAX_THREADS=1 +ARG WS_VER=3.4.0 +ARG MI_BRANCH=ubuntu22-py310 +ARG WIRESHARK_URL=http://www.mobileinsight.net/wireshark-${WS_VER}-rbc-dissector.tar.xz +ADD 00-cpp_compat.patch /build/00-cpp_compat.patch + +# Run apt update +RUN set -ex; \ + export DEBIAN_FRONTEND=noninteractive; \ + apt-get update; \ + apt-get upgrade -y; \ + apt-get install -y \ + git \ + python3 \ + python3-pip \ + python3-wxgtk4.0 \ + python3-matplotlib \ + cmake \ + pkg-config \ + wget \ + libglib2.0-dev \ + bison \ + flex \ + libpcap-dev \ + libgcrypt-dev \ + qtbase5-dev \ + qtchooser \ + qt5-qmake \ + qtbase5-dev-tools \ + qttools5-dev \ + qtmultimedia5-dev \ + libqt5svg5-dev \ + libc-ares-dev \ + libsdl2-mixer-2.0-0 \ + libsdl2-image-2.0-0 \ + libsdl2-2.0-0; + +# Download resources +RUN set -ex; \ + mkdir -p /build; \ + cd /build; \ + wget "$WIRESHARK_URL" -nv -O "wireshark-$WS_VER.tar.xz"; \ + tar -xf "wireshark-$WS_VER.tar.xz"; \ + git clone "https://github.com/mobile-insight/mobileinsight-core.git"; \ + git -C mobileinsight-core checkout "$MI_BRANCH"; + +# Compile and install wireshark +RUN set -ex; \ + cd "/build/wireshark-$WS_VER"; \ + patch epan/epan.h < /build/00-cpp_compat.patch; \ + cmake -DBUILD_wireshark=OFF .; \ + make -j "$MAX_THREADS"; \ + make install; \ + ldconfig; + +# Compile and install Wireshark dissector +Run set -ex; \ + cd /build/mobileinsight-core/ws_dissector; \ + g++ ws_dissector.cpp packet-aww.cpp -o ws_dissector \ + $(pkg-config --libs --cflags glib-2.0) \ + -I"/build/wireshark-$WS_VER" \ + -L"/usr/local/lib" \ + -lwireshark \ + -lwsutil \ + -lwiretap; \ + strip ws_dissector; \ + install -Dm 755 ws_dissector /usr/local/bin/ws_dissector; + +# Compile and install MobileInsight +Run set -ex; \ + cd /build/mobileinsight-core; \ + pip3 install pyserial; \ + python3 setup.py install; + +# Install MobileInsight GUI +Run set -ex; \ + cd /build/mobileinsight-core; \ + mkdir -p /usr/local/share/mobileinsight; \ + cp -r gui/* /usr/local/share/mobileinsight;\ + ln -s /usr/local/share/mobileinsight/mi-gui /usr/local/bin/mi-gui; + +# Install examples +Run set -ex; \ + cd /build/mobileinsight-core; \ + cp -r examples /opt/mobileinsight-examples; + +# Link python3 to python +Run set -ex; \ + cd /usr/bin; \ + ln -s python3 python; + +# Cleanup +Run set -ex; \ + apt-get autoclean -y; \ + rm -rf /build; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..05ed3ba --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +DOCKER ?= docker +APPTAINER ?= apptainer +OVERLAY_DIR ?= ./overlay +SHARED_DIR ?= ./shared +MAX_THREADS ?= $(shell grep -c processor /proc/cpuinfo) + +UID := $(shell id -u) +GID := $(shell id -g) + +.DEFAULT_GOAL := .docker_build + +.docker_build: Dockerfile + "$(DOCKER)" build --build-arg "MAX_THREADS=$(MAX_THREADS)" -t mobileinsight . + touch "$@" + +mobileinsight.tar.gz: .docker_build + "$(DOCKER)" save mobileinsight:latest | gzip > "$@" + +mobileinsight.sif: mobileinsight.def .docker_build + "$(APPTAINER)" build "$@" "$<" + +run: .docker_build + @mkdir -p "$(SHARED_DIR)" + @test -n "$(shell docker image ls -q mobileinsight)" \ + || (echo Cannot find image mobileinsight:latest, has it been built yet? 1>&2 \ + && false) + @"$(DOCKER)" run --rm -it --privileged -v "$(SHARED_DIR):/mnt" \ + -e TERM -u root --entrypoint bash mobileinsight:latest + +app-run: mobileinsight.sif + @mkdir -p "$(OVERLAY_DIR)" + @lsmod | grep overlay > /dev/null || sudo modprobe overlay + @$(APPTAINER) run --overlay "$(OVERLAY_DIR)" \ + -B "/run/user/$(UID)" mobileinsight.sif + +clean: + "$(DOCKER)" container prune + "$(DOCKER)" image prune -a + rm -f .docker_build mobileinsight.tar.gz mobileinsight.sif + +clean-data: + rm -rf $(OVERLAY_DIR) $(SHARED_DIR) + +.PHONY: sc-run run clean clean-data diff --git a/README.md b/README.md new file mode 100644 index 0000000..7de1e77 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +MobileInsight Apptainer +======================= + +Single launch binary for MobileInsight in a Ubuntu 22.04 portable container. + +Dependencies +------------ + +The host side only needs `apptainer` or `singularity` to function. A gui is +needed to launch the log viewer. + +Usage +----- + +``` +# Start the log viewer +$ ./mobileinsight.sif mi-gui + +# Start a python3 shell with MobileInsight available +$ ./mobileinsight.sif python3 "$PYTHON_ARGS" + +# Start a bash shell inside the container +$ ./mobileinsight.sif bash +``` + +Examples are stored in /opt/mobileinsight-examples. + +Building +-------- + +To build the apptainer, the following dependencies are needed on the host +machine: + +1. Apptainer or Singularity +2. Docker + +Run `make mobileinsight.sif` to build the apptainer image. diff --git a/mobileinsight.def b/mobileinsight.def new file mode 100644 index 0000000..7918624 --- /dev/null +++ b/mobileinsight.def @@ -0,0 +1,11 @@ +BootStrap: docker-daemon +From: mobileinsight:latest + +%runscript + set -e + echo "Welcome to MobileInsight Apptainer!" + if [ $# -eq 0 ]; then + exec /bin/bash + else + "$@" + fi