Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

3.8 KB
Raw Blame
#!/usr/bin/env bash
# Build a self-contained, timestamped release jar for Linux.
#
# Unlike build.sh (a lean ~10 MB dev jar), this embeds the trimmed OWASP ZAP scan
# engine inside the jar as a resource. On first run the app extracts it once to
# ~/.opensuite/engine and runs it headless, so the single jar is self-contained:
# download one file, `java -jar opensuite.jar`, and scanning works. The local
# file keeps the timestamp in its name; publish.sh uploads it as opensuite.jar.
#
# The build is identified by a UTC timestamp (YYYYMMDD-HHMMSS) used for both the
# filename and the jar's Implementation-Version, which the app shows in its title.
#
# The testing browser is NOT embedded (it is ~680 MB); it is offered as an
# optional in-app download the first time the user opens a browser.
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"

# Prefer the pinned portable JDK (fetch-jdk.sh) so the release bytecode matches
# the runtime the AppImage bundles. Falls back to the system JDK if jdk/ is absent.
if [ -x "$DIR/jdk/bin/javac" ]; then
    export JAVA_HOME="$DIR/jdk"
    export PATH="$DIR/jdk/bin:$PATH"
fi

# OPENSUITE_BUILD names the build instead, so a package made later for a
# published release (the macOS app) carries that release's own identifier.
TS="${OPENSUITE_BUILD:-$(date -u +%Y%m%d-%H%M%S)}"
[[ "$TS" =~ ^[0-9]{8}-[0-9]{6}$ ]] || { echo "OPENSUITE_BUILD must look like 20261019-085441, not $TS" >&2; exit 1; }
echo "Release build $TS (UTC)"

# Start from an empty build/ so nothing left by an earlier build or by the
# AppImage packaging (its runtime and staging directories live under build/)
# is packed into the release jar.
rm -rf build
mkdir -p build dist

# Java's class path is joined with ";" on Windows (Git Bash there) and ":" elsewhere.
case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) S=';' ;; *) S=':' ;; esac
echo "Compiling..."
javac -d build -cp "lib/*${S}build" $(find src -name '*.java')

echo "Copying resources..."
mkdir -p build/opensuite/ui/icons
cp src/opensuite/ui/icons/*.png build/opensuite/ui/icons/ 2>/dev/null || true

echo "Unpacking vendored jars..."
( cd build && for j in ../lib/*.jar; do jar xf "$j"; done
  rm -rf META-INF/*.SF META-INF/*.DSA META-INF/*.RSA 2>/dev/null || true )

if ls engine/zap-*.jar >/dev/null 2>&1; then
    echo "Embedding scan engine..."
    mkdir -p build/opensuite/engine
    # zip when it is installed; otherwise the JDK's own jar tool, which writes
    # the same format (M: no manifest) and is always present for a build.
    if command -v zip >/dev/null 2>&1; then
        ( cd engine && zip -qr -1 "$DIR/build/opensuite/engine/engine.zip" . )
    else
        jar cfM "$DIR/build/opensuite/engine/engine.zip" -C engine .
    fi
    ZV="$(ls engine/zap-*.jar | head -1 | sed -E 's#.*/zap-([0-9.]+)\.jar#\1#')"
    printf '%s' "$ZV" > build/opensuite/engine/VERSION
    # What is in the engine, add-ons included: a copy unpacked from an earlier
    # build is replaced when this differs, even if the engine version is the same.
    ( cd engine && ls zap-*.jar plugin/*.zap | sort | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-16 ) > build/opensuite/engine/CONTENTS
    echo "  engine $ZV embedded ($(du -h build/opensuite/engine/engine.zip | cut -f1))"
else
    echo "WARNING: no engine/ present. Run ./fetch-zap.sh first, or the release jar"
    echo "         will fall back to a system ZAP at runtime if one is installed."
fi

printf 'Main-Class: opensuite.ui.Main\nImplementation-Version: %s\n' "$TS" > dist/.manifest.txt
OUT="dist/opensuite_${TS}.jar"
# Each dated jar is about 150 MB: keep the three newest and drop the rest.
ls -t dist/opensuite_*.jar 2>/dev/null | tail -n +3 | while read -r old; do rm -f "$old"; done
jar cfm "$OUT" dist/.manifest.txt -C build .
rm -f dist/.manifest.txt

echo
echo "Built $OUT ($(du -h "$OUT" | cut -f1))"
echo "Run it with:  java -jar $OUT"