#!/bin/bash # Install Strawberry from a build tree (builddir/). Run as root: # sudo ./scripts/install.sh # On macOS this runs scripts/macos_install.sh. set -euo pipefail cd "$(dirname "$0")/.." if [ "$(uname -s)" = "Darwin" ]; then exec bash ./scripts/macos_install.sh "$@" fi . ./scripts/install_common.sh echo "=== Strawberry Security Scanner Installation ===" echo # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (sudo)" exit 1 fi # Access group: members can read findings and use the desktop app's controls # (reload rules, rescan). Nobody else can see the evidence. if ! getent group strawberry >/dev/null; then echo "Creating 'strawberry' group..." groupadd --system strawberry fi # Create directories. Rules are root-only (anyone who can edit them can blind # the scanner); evidence is readable by the strawberry group only. echo "Creating directories..." install -d -m 0755 /etc/strawberry install -d -m 0700 /etc/strawberry/rules install -d -m 0750 -g strawberry /var/lib/strawberry install -d -m 0750 -g strawberry /var/lib/strawberry/feeds # Evidence: a legacy database.db file (imported into the event store by the # daemon on its next start, old file kept as database.db.migrated-) or # the event store directory. Either way the strawberry group reads evidence; # telemetry/ stays root-only through its own 0700/0600 modes. f=/var/lib/strawberry/database.db if [ -f "$f" ]; then chgrp strawberry "$f" && chmod 0640 "$f" elif [ -d "$f" ]; then chgrp -R strawberry "$f" chmod 0750 "$f" [ -d "$f/evidence" ] && chmod 0750 "$f/evidence" fi # Copy configuration if [ -f "config/strawberry.conf" ]; then echo "Installing configuration..." if [ -f /etc/strawberry/strawberry.conf ]; then echo " keeping existing /etc/strawberry/strawberry.conf" else install -m 0644 config/strawberry.conf /etc/strawberry/strawberry.conf fi fi # Copy example YARA rules if [ -f "config/example_rules.yar" ]; then echo "Installing example YARA rules..." install -m 0600 config/example_rules.yar /etc/strawberry/rules/example_rules.yar fi # Pinned rule snapshot shipped in the release: install the default feeds from # it (no per-node download). Standalone trees without a snapshot keep fetching. snapshot_installed="" if [ -f "packaging/rules-snapshot/SNAPSHOT" ]; then echo "Verifying pinned rule snapshot..." (cd packaging/rules-snapshot && sha256sum -c MANIFEST.sha256 --quiet) \ || { echo "Error: rule snapshot does not match MANIFEST.sha256"; exit 1; } echo "Installing pinned rule snapshot..." if install_feed_snapshot packaging/rules-snapshot /var/lib/strawberry/feeds strawberry; then snapshot_installed=1 # Fleet/release default: no background fetch. Scoped to the snapshot # path only, and only when the key is not already set. if [ "${STRAWBERRY_RULE_AUTO_FETCH:-}" != "1" ] && [ -f /etc/strawberry/strawberry.conf ] \ && ! grep -q '^[[:space:]]*#\?[[:space:]]*rule_auto_fetch=' /etc/strawberry/strawberry.conf; then printf '\n# Set by install.sh: rules come from the pinned snapshot\nrule_auto_fetch=false\n' \ >> /etc/strawberry/strawberry.conf fi fi fi # Install binary if [ -f "builddir/src/strawberry" ]; then echo "Installing binary..." install -m 0755 builddir/src/strawberry /usr/local/bin/strawberry install_completions /usr/local/bin/strawberry install_traces /usr/local else echo "Error: Binary not found. Please build first with 'meson compile -C builddir'" exit 1 fi # Install the eBPF exec monitor object (without it the daemon falls back to # slower procfs polling, which misses short-lived processes) if [ -f "builddir/src/process_monitor.bpf.o" ]; then echo "Installing eBPF object..." install -d -m 0755 /usr/local/share/strawberry install -m 0644 builddir/src/process_monitor.bpf.o /usr/local/share/strawberry/process_monitor.bpf.o else echo "Warning: builddir/src/process_monitor.bpf.o not found; the daemon will use procfs polling" fi # Desktop app + tray indicator (optional; built when Qt6 is available) if [ -f "builddir/app/strawberry-tray" ]; then echo "Installing desktop app..." install -m 0755 builddir/app/strawberry-tray /usr/local/bin/strawberry-tray install -d -m 0755 /usr/local/share/applications install -m 0644 packaging/strawberry-tray.desktop /usr/local/share/applications/strawberry-tray.desktop else echo "Note: builddir/app/strawberry-tray not built (needs Qt6); skipping the desktop app" fi # MCP server for agents (optional; built when nlohmann_json is available) if [ -f "builddir/mcp/strawberry-mcp" ]; then echo "Installing MCP server..." install -m 0755 builddir/mcp/strawberry-mcp /usr/local/bin/strawberry-mcp fi # Install systemd units: the scanner, plus the sandboxed rule updater # (daily timer + "Update now" path trigger). # Hashes of the unit files this installer writes into a persistence location # (written first): the daemon records these writes as evidence instead of # raising findings, as long as the installed content still matches. manifest_args=() for unit in strawberry.service strawberry-update.service strawberry-update.timer strawberry-update.path \ strawberry-reduce.service strawberry-reduce.timer strawberry-trackerd.service; do manifest_args+=("scripts/$unit" "/etc/systemd/system/$unit") done write_installed_manifest /var/lib/strawberry/installed-files.sha256 root "${manifest_args[@]}" if [ -f "scripts/strawberry.service" ]; then echo "Installing systemd units..." install -m 0644 scripts/strawberry.service /etc/systemd/system/strawberry.service for unit in strawberry-update.service strawberry-update.timer strawberry-update.path strawberry-trackerd.service; do install -m 0644 "scripts/$unit" "/etc/systemd/system/$unit" done # Scheduled telemetry reduction (stop -> reduce -> start): installed but NOT # enabled. It drops telemetry and causes a monitoring gap, so it is opt-in. install -d -m 0755 /usr/local/lib/strawberry install -m 0755 scripts/strawberry-reduce.sh /usr/local/lib/strawberry/strawberry-reduce.sh for unit in strawberry-reduce.service strawberry-reduce.timer; do install -m 0644 "scripts/$unit" "/etc/systemd/system/$unit" done systemctl daemon-reload # Pick up the new binary if the service is already running. systemctl try-restart strawberry || true echo "Enabling automatic YARA rule updates (daily)..." systemctl enable --now strawberry-update.timer strawberry-update.path # Fetch the default feed (YARA Forge core) now, in the background, unless a # pinned snapshot was installed (opt back in: STRAWBERRY_RULE_AUTO_FETCH=1). if [ -z "$snapshot_installed" ] || [ "${STRAWBERRY_RULE_AUTO_FETCH:-}" = "1" ]; then systemctl start --no-block strawberry-update.service || true fi fi # OpenSnitch: containment rules can pin a binary by hash only when OpenSnitch # computes checksums. Offer to turn that on. if [ -f /etc/opensnitchd/default-config.json ] && [ -x /usr/local/bin/strawberry ]; then if grep -q '"EnableChecksums": *true' /etc/opensnitchd/default-config.json; then echo "OpenSnitch checksums already enabled (containment rules are hash-pinned)." elif [ -t 0 ]; then read -r -p "Enable OpenSnitch checksums so network containment is pinned to the exact binary? [Y/n] " answer if [ "$answer" != "n" ] && [ "$answer" != "N" ]; then /usr/local/bin/strawberry opensnitch enable-checksums --config /etc/strawberry/strawberry.conf \ && systemctl try-restart opensnitchd || true fi else echo "Tip: sudo strawberry opensnitch enable-checksums && sudo systemctl restart opensnitchd" fi fi # Tracker attribution (advisory, never blocks; docs/tracker-attribution.md). # OpenSnitch sends connection events to the host-namespace relay # (strawberry-trackerd) on a loopback port only root can bind; the relay strips # command lines and environments and forwards the program, tracker domain, port # and time to the daemon over an AF_UNIX socket, so the daemon keeps its network # sandbox and never sees those secrets. Turn it off with privacy_trackers=false. if [ -f /etc/opensnitchd/default-config.json ] && [ -x /usr/local/bin/strawberry ] \ && ! grep -q '^privacy_trackers=false' /etc/strawberry/strawberry.conf 2>/dev/null; then if events_out=$(/usr/local/bin/strawberry opensnitch enable-events --config /etc/strawberry/strawberry.conf); then if [[ "$events_out" == *"will send"* ]]; then echo "OpenSnitch configured to send connection events to the tracker relay." systemctl try-restart opensnitchd || true fi else echo "Warning: could not set up OpenSnitch connection events (tracker attribution stays off)" fi echo "Starting the tracker-attribution relay (strawberry-trackerd)..." systemctl enable --now strawberry-trackerd.service || \ echo " (could not start strawberry-trackerd; check 'systemctl status strawberry-trackerd')" fi # Offer to grant the invoking desktop user access. if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then if [[ " $(id -nG "$SUDO_USER") " == *" strawberry "* ]]; then echo "User '$SUDO_USER' is already in the strawberry group." elif [ -t 0 ]; then read -r -p "Add '$SUDO_USER' to the strawberry group (view findings, use controls)? [y/N] " answer if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then usermod -aG strawberry "$SUDO_USER" echo "Added. Log out and back in for it to take effect." fi else echo "To use the desktop app: sudo usermod -aG strawberry $SUDO_USER (then log out/in)" fi fi echo echo "Installation complete!" echo echo "To start the scanner now and on every boot:" echo " sudo systemctl enable --now strawberry" echo echo "Rule updates: daily via strawberry-update.timer (first run started now)." echo " status: strawberry policy show logs: journalctl -u strawberry-update" echo "reduce: scheduled reduction is OFF; enable with store_reduce_enabled=true + systemctl enable --now strawberry-reduce.timer" echo echo "Configuration: /etc/strawberry/strawberry.conf" PROFILE=$(sed -n 's/^scan_profile=//p' /etc/strawberry/strawberry.conf 2>/dev/null | tail -1) echo "Scan profile: ${PROFILE:-balanced (default)} (efficient | balanced | aggressive;" echo " set scan_profile= in the config; matching systemd limits: systemctl edit strawberry)" echo "State/Data: /var/lib/strawberry/" echo "YARA Rules: /etc/strawberry/rules/" echo "Logs: journalctl -u strawberry" echo echo "Desktop app: launch 'Strawberry' from your app launcher, or start the tray" echo "indicator with your session. For sway, add to your sway config:" echo " exec strawberry-tray"