#!/bin/sh
# e.bat installer — robust, self-contained.
# - detects OS/arch and picks the right release asset
# - falls back to building from source (go) if no release asset
# - creates every required directory (~/.local/bin, ~/.e.bat/...)
# - installs the tools e.bat needs (nmap, gobuster, ... ghidra) via the
# detected package manager, warning (never dying) on failures
# - supports: --uninstall, --build, --dest
, --no-deps
set -u
REPO="${REPO:-ex6p/e.bat}"
DEST="${DEST:-}"
DO_BUILD=0
INSTALL_DEPS=1
say() { printf '%s\n' "$*"; }
warn() { printf 'warn: %s\n' "$*" >&2; }
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
have() { command -v "$1" >/dev/null 2>&1; }
# ---------- OS / arch ----------
detect_asset() {
os=$(uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]')
case "$os" in
linux*) os=linux ;;
darwin*) os=darwin ;;
freebsd*) os=freebsd ;;
*) os=linux ;;
esac
m=$(uname -m 2>/dev/null)
case "$m" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
armv7l|armv6l|arm) arch=arm ;;
i386|i686|x86) arch=386 ;;
riscv64) arch=riscv64 ;;
mips) arch=mips ;;
mipsle) arch=mipsle ;;
s390x) arch=s390x ;;
ppc64le) arch=ppc64le ;;
*) arch=amd64 ;;
esac
ASSET="e.bat-$os-$arch"
[ "$os" = "windows" ] && ASSET="$ASSET.exe"
}
# ---------- download ----------
download() {
url="$1"; out="$2"
if have curl; then curl -fsSL --retry 3 "$url" -o "$out"
elif have wget; then wget -q "$url" -O "$out"
else die "need curl or wget"; fi
}
# ---------- dirs ----------
default_dest() {
if [ "$(id -u)" = "0" ]; then echo /usr/local/bin
else echo "$HOME/.local/bin"; fi
}
ensure_dirs() {
# binary dir
mkdir -p "$DEST" 2>/dev/null || { warn "cannot create $DEST"; DEST="$HOME/.local/bin"; mkdir -p "$DEST"; }
# e.bat data tree
base="$HOME/.e.bat"
for d in "" config data logs recon reports decomp tmp config/sessions; do
mkdir -p "$base/$d" 2>/dev/null || warn "cannot create $base/$d"
done
}
# ---------- package manager ----------
detect_pm() {
if have pacman; then PM=pacman
elif have apt-get; then PM=apt
elif have dnf; then PM=dnf
elif have yum; then PM=yum
elif have pkg; then PM=pkg # Termux
elif have apk; then PM=apk
elif have zypper; then PM=zypper
elif have xbps-install; then PM=xbps
else PM=none
fi
}
pm_install() {
pkg="$1"
[ "$PM" = "none" ] && { warn "no package manager; install '$pkg' manually"; return 1; }
say " installing $pkg via $PM ..."
case "$PM" in
pacman) pacman -S --noconfirm --needed "$pkg" ;;
apt) sudo apt-get install -y "$pkg" 2>/dev/null || apt-get install -y "$pkg" ;;
dnf) sudo dnf install -y "$pkg" 2>/dev/null || dnf install -y "$pkg" ;;
yum) sudo yum install -y "$pkg" 2>/dev/null || yum install -y "$pkg" ;;
pkg) pkg install -y "$pkg" ;;
apk) sudo apk add "$pkg" 2>/dev/null || apk add "$pkg" ;;
zypper) sudo zypper -n install "$pkg" 2>/dev/null || zypper -n install "$pkg" ;;
xbps) sudo xbps-install -y "$pkg" 2>/dev/null || xbps-install -y "$pkg" ;;
esac
}
# ---------- dependencies ----------
install_deps() {
detect_pm
say "installing e.bat dependencies (failures are warnings, not fatal) ..."
# tool:preferred-package
deps="nmap:nmap gobuster:gobuster ffuf:ffuf nikto:nikto sqlmap:sqlmap \
wpscan:wpscan hydra:hydra john:john hashcat:hashcat binwalk:binwalk \
exiftool:exiftool nuclei:nuclei"
for pair in $deps; do
tool=${pair%%:*}; pkg=${pair##*:}
if have "$tool"; then say " [ok] $tool"; continue; fi
if pm_install "$pkg"; then
have "$tool" && say " [ok] $tool" || warn "$tool installed but not on PATH yet"
else
warn "could not install $tool ($pkg) — install manually"
fi
done
# Ghidra (not in most repos): AUR helper, else warn.
if have ghidra || have analyzeHeadless || [ -n "${GHIDRA:-}" ]; then
say " [ok] ghidra"
else
ghidra_ok=0
for h in yay paru; do
if have "$h"; then
say " installing ghidra via $h ..."
"$h" -S --noconfirm ghidra 2>/dev/null && ghidra_ok=1 && break
fi
done
if [ "$ghidra_ok" = "1" ]; then say " [ok] ghidra"
else
warn "ghidra not installed (needed for 'decomp')."
warn " AUR: yay -S ghidra | or download: https://github.com/NationalSecurityAgency/ghidra/releases"
warn " then: export GHIDRA=/path/to/ghidra"
fi
fi
say "dependencies done."
}
# ---------- source build ----------
build_from_source() {
have go || die "no release asset and no 'go' to build from source"
tmp=$(mktemp -d)
say "cloning source into $tmp ..."
if have git; then
git clone -q "https://github.com/$REPO.git" "$tmp/src" || die "clone failed"
else
download "https://github.com/$REPO/archive/refs/heads/main.tar.gz" "$tmp/src.tar.gz"
mkdir -p "$tmp/src"
tar -xzf "$tmp/src.tar.gz" -C "$tmp/src" --strip-components=1
fi
( cd "$tmp/src" && CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o "$tmp/e.bat" . ) || die "build failed"
BIN="$tmp/e.bat"
}
# ---------- uninstall ----------
uninstall() {
DEST="${DEST:-$(default_dest)}"
rm -f "$DEST/e.bat" && say "removed $DEST/e.bat"
exit 0
}
# ---------- args ----------
while [ $# -gt 0 ]; do
case "$1" in
--uninstall) uninstall ;;
--build) DO_BUILD=1; shift ;;
--no-deps) INSTALL_DEPS=0; shift ;;
--dest) DEST="${2:-}"; shift 2 2>/dev/null || shift ;;
-h|--help) say "usage: ./install.sh [--build] [--no-deps] [--dest ] [--uninstall]"; exit 0 ;;
*) warn "unknown option: $1"; shift ;;
esac
done
DEST="${DEST:-$(default_dest)}"
ensure_dirs
# ---------- get binary ----------
if [ "$DO_BUILD" = "1" ]; then
build_from_source
else
detect_asset
URL="https://github.com/$REPO/releases/latest/download/$ASSET"
TMP=$(mktemp); trap 'rm -f "$TMP"' EXIT
say "downloading $URL"
if download "$URL" "$TMP" 2>/dev/null && [ -s "$TMP" ]; then
BIN="$TMP"
else
warn "no release asset '$ASSET' — building from source"
build_from_source
fi
fi
chmod +x "$BIN" 2>/dev/null || true
if ! install -m 0755 "$BIN" "$DEST/e.bat" 2>/dev/null; then
if cp "$BIN" "$DEST/e.bat" 2>/dev/null && chmod +x "$DEST/e.bat" 2>/dev/null; then
:
else
warn "cannot write to $DEST — falling back to ~/.local/bin"
DEST="$HOME/.local/bin"; mkdir -p "$DEST"
install -m 0755 "$BIN" "$DEST/e.bat" 2>/dev/null \
|| cp "$BIN" "$DEST/e.bat" 2>/dev/null \
|| die "failed to install binary"
chmod +x "$DEST/e.bat" 2>/dev/null || true
fi
fi
say "installed: $DEST/e.bat"
"$DEST/e.bat" --version 2>/dev/null || true
# ---------- deps ----------
[ "$INSTALL_DEPS" = "1" ] && install_deps
# ---------- PATH ----------
case ":$PATH:" in
*":$DEST:"*) ;;
*) warn "add to PATH: export PATH=\"$DEST:\$PATH\"" ;;
esac
say "done."