Files
marqdo-app-harness/scripts/install.sh
cflmy 5f56c23455 feat: add unified egress, bootstrap, diagnostics and app distribution
Implements the four follow-up design issues for MQDH:\n\n- network: one policy/proxy/mirror/offline/audit client for product egress\n- bootstrap: first-run state machine, default Tools, real smoke, doctor/repair\n- diagnostics: local redacted reports and explicit Gitea issue submission\n- distribution: release manifest, user install tree, update/rollback, installer\n\nThe product CLI exposes bootstrap/doctor/repair/report/update/network and the\n/mqdh workbench renders the same services. Marqdo runtime artifacts remain\ndownloaded from trusted releases; unsupported platforms and unrun gates stay\nUNVERIFIED in docs/mqdh/STATUS.md.
2026-11-28 23:07:07 +08:00

95 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# User-level installer for a packaged Marqdo Harness tree.
#
# ./install.sh [--prefix DIR] [--no-path]
# ./install.sh --uninstall [--prefix DIR]
#
# The application install tree is separate from MQDH_HOME (user data, private
# knowledge, sessions and the Marqdo runtime). Uninstall preserves MQDH_HOME.
set -euo pipefail
src="$(cd "$(dirname "$0")" && pwd)"
prefix="${MQDH_INSTALL_ROOT:-$HOME/.local/opt/mqdh}"
no_path=0
uninstall=0
while [ $# -gt 0 ]; do
case "$1" in
--prefix) prefix="${2:?--prefix needs a value}"; shift 2 ;;
--no-path) no_path=1; shift ;;
--uninstall) uninstall=1; shift ;;
-h|--help) sed -n '2,9p' "$0"; exit 0 ;;
*) echo "install.sh: unknown argument $1" >&2; exit 2 ;;
esac
done
mkdir -p "$prefix"
prefix="$(cd "$prefix" && pwd)"
wrapper="$prefix/bin/mqdh"
user_wrapper="$HOME/.local/bin/mqdh"
if [ "$uninstall" = 1 ]; then
if [ -f "$wrapper" ] && grep -qF "MQDH_INSTALL_ROOT_BINDING=\"$prefix\"" "$wrapper" 2>/dev/null; then
rm -f "$wrapper"
fi
if [ -L "$user_wrapper" ] && [ "$(readlink "$user_wrapper")" = "$wrapper" ]; then
rm -f "$user_wrapper"
fi
rm -rf "$prefix"
echo "removed $prefix; user data under \${MQDH_HOME:-~/.local/share/marqdo-harness} is preserved"
exit 0
fi
test -f "$src/scripts/mqdh.mjs" || { echo "install.sh: not a Marqdo Harness tree: $src" >&2; exit 1; }
test -f "$src/SOURCE_SHA" || { echo "install.sh: missing SOURCE_SHA in $src" >&2; exit 1; }
version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$src/packages/marqdo/harness/package.json" | head -1)"
test -n "$version" || { echo "install.sh: cannot read the product version" >&2; exit 1; }
sha="$(tr -d '[:space:]' < "$src/SOURCE_SHA")"
test "${#sha}" -ge 12 || { echo "install.sh: invalid SOURCE_SHA" >&2; exit 1; }
install_id="$version-${sha:0:12}"
mkdir -p "$prefix/versions"
target="$prefix/versions/$install_id"
if [ ! -d "$target" ]; then
mkdir -p "$target"
if [ "${MQDH_INSTALL_HARDLINK:-0}" = "1" ]; then
cp -al "$src/." "$target/"
else
cp -a "$src/." "$target/"
fi
fi
previous=""
if [ -f "$prefix/current.json" ]; then
previous="$(sed -n 's/.*"install_id": *"\([^"]*\)".*/\1/p' "$prefix/current.json" | head -1)"
fi
mkdir -p "$prefix"
if [ -n "$previous" ]; then previous_json="\"$previous\""; else previous_json="null"; fi
printf '{\n "schema": "marqdo.mqdh.app-current",\n "schema_version": 1,\n "version": "%s",\n "install_id": "%s",\n "source_sha": "%s",\n "previous": %s,\n "previous_version": null,\n "updated_at": "%s"\n}\n' \
"$version" "$install_id" "$sha" "$previous_json" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$prefix/current.json"
mkdir -p "$prefix/bin"
cat > "$wrapper" <<WRAPPER
#!/usr/bin/env bash
# Generated by Marqdo Harness install.sh.
set -euo pipefail
MQDH_INSTALL_ROOT_BINDING="$prefix"
root="\${MQDH_INSTALL_ROOT:-$prefix}"
pointer="\$root/current.json"
id="\$(sed -n 's/.*"install_id": *"\([^"]*\)".*/\1/p' "\$pointer" | head -1)"
case "\$id" in ""|*..*|*[!0-9A-Za-z._-]*) echo "mqdh: invalid or missing install pointer: \$pointer" >&2; exit 1 ;; esac
tree="\$root/versions/\$id"
if [ -x "\$tree/runtime/node" ]; then
exec "\$tree/runtime/node" "\$tree/scripts/mqdh.mjs" "\$@"
fi
exec node "\$tree/scripts/mqdh.mjs" "\$@"
WRAPPER
chmod 755 "$wrapper"
if [ "$no_path" = 0 ] && [ -d "$HOME/.local/bin" ]; then
ln -sf "$wrapper" "$user_wrapper"
echo "linked $user_wrapper"
fi
echo "installed Marqdo Harness $version ($install_id) at $prefix"
echo "run: $wrapper --version"
echo "user data: \${MQDH_HOME:-~/.local/share/marqdo-harness}"