94 lines
3.6 KiB
Bash
94 lines
3.6 KiB
Bash
# shellcheck shell=bash
|
|
# Shared by scripts/install.sh (Linux) and scripts/macos_install.sh. Sourced,
|
|
# not run.
|
|
|
|
# sha256 of a file, hex only (sha256sum on Linux, shasum on macOS).
|
|
sha256_of() {
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
sha256sum < "$1" | cut -d' ' -f1
|
|
else
|
|
shasum -a 256 < "$1" | cut -d' ' -f1
|
|
fi
|
|
}
|
|
|
|
# Shell completions, generated from the CLI's command table.
|
|
# $1: installed strawberry binary.
|
|
install_completions() {
|
|
local bin="$1" entry shell target
|
|
for entry in "bash:/usr/local/share/bash-completion/completions/strawberry" \
|
|
"zsh:/usr/local/share/zsh/site-functions/_strawberry" \
|
|
"fish:/usr/local/share/fish/vendor_completions.d/strawberry.fish"; do
|
|
shell="${entry%%:*}"
|
|
target="${entry#*:}"
|
|
install -d -m 0755 "$(dirname "$target")"
|
|
if "$bin" completion "$shell" > "$target.tmp"; then
|
|
chmod 0644 "$target.tmp" && mv -f "$target.tmp" "$target"
|
|
else
|
|
echo "Warning: could not generate $shell completions"
|
|
rm -f "$target.tmp"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Write the installed-files manifest atomically: root-owned, 0644, in
|
|
# sha256sum format. The daemon records writes to these persistence paths as
|
|
# evidence instead of raising findings while the content still matches.
|
|
# $1: manifest path, $2: owner group (root/wheel), then pairs of
|
|
# <source file> <installed path>.
|
|
write_installed_manifest() {
|
|
local manifest="$1" group="$2"
|
|
shift 2
|
|
: > "$manifest.tmp"
|
|
while [ $# -ge 2 ]; do
|
|
if [ -f "$1" ]; then
|
|
printf '%s %s\n' "$(sha256_of "$1")" "$2" >> "$manifest.tmp"
|
|
fi
|
|
shift 2
|
|
done
|
|
install -m 0644 -o root -g "$group" "$manifest.tmp" "$manifest"
|
|
rm -f "$manifest.tmp"
|
|
}
|
|
|
|
# Attack traces for replay and training (read-only data):
|
|
# standard.trace evaluates (strawberry replay --inject, the promotion gate),
|
|
# training.trace trains (strawberry model train --inject-train).
|
|
# $1: install prefix (/usr/local).
|
|
install_traces() {
|
|
local dir="$1/share/strawberry/traces" trace
|
|
install -d -m 0755 "$dir"
|
|
for trace in config/traces/*.trace; do
|
|
install -m 0644 "$trace" "$dir/$(basename "$trace")"
|
|
done
|
|
}
|
|
|
|
# Install pinned feed snapshots (packaging/rules-snapshot) in the layout the
|
|
# daemon reads: <feeds-dir>/<id>/<version>/(*.yar | list.txt) and a directory
|
|
# symlink current -> <version>, switched atomically. Generic: installs every
|
|
# feed listed in SNAPSHOT ("<id> <version> <sha256-of-dir>") whose subdir exists.
|
|
# $1: snapshot dir, $2: feeds dir, $3: group that reads the feeds.
|
|
install_feed_snapshot() {
|
|
local snap="$1" feeds="$2" group="$3" id version _rest dir dest file n=0
|
|
[ -f "$snap/SNAPSHOT" ] || return 1
|
|
install -d -m 0750 -g "$group" "$feeds"
|
|
while read -r id version _rest; do
|
|
case "$id" in ''|'#'*) continue ;; esac
|
|
dir="$snap/$id"
|
|
[ -d "$dir" ] || continue
|
|
case "$id$version" in */*|*..*) echo "Warning: bad snapshot entry '$id $version'"; continue ;; esac
|
|
[ -n "$version" ] || continue
|
|
dest="$feeds/$id/$version"
|
|
install -d -m 0750 -g "$group" "$feeds/$id" "$dest"
|
|
for file in "$dir"/*.yar "$dir"/list.txt; do
|
|
[ -f "$file" ] || continue
|
|
command cp -f "$file" "$dest/$(basename "$file")"
|
|
done
|
|
chmod 0750 "$dest"
|
|
chgrp -R "$group" "$dest"
|
|
# atomic switch: temp symlink then rename over current
|
|
ln -sfn "$version" "$feeds/$id/.current.tmp"
|
|
mv -fT "$feeds/$id/.current.tmp" "$feeds/$id/current"
|
|
echo " installed feed $id $version"
|
|
n=$((n + 1))
|
|
done < "$snap/SNAPSHOT"
|
|
[ "$n" -gt 0 ]
|
|
}
|