#!/usr/bin/env bash # Run ObsidianDragon against tools/fake_dragonxd in a throwaway, fully isolated HOME (Linux). # # tools/fake_dragonxd/run-gui-with-fake.sh [--build-dir DIR] [--scratch DIR] [-- GUI args...] # # FAKE_* variables in the environment pass through to the stub (see README.md). It never touches # the real ~/.hush or ~/.config: HOME, XDG_CONFIG_HOME and TMPDIR all point into the scratch dir. # Re-using a --scratch dir keeps its settings, conf and GUI log; the stub's events file is appended. set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" build_dir="$repo/build/linux" scratch="" port=21769 # the GUI's external-node / port checks are hard-wired to the default RPC port usage() { sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//'; } while [[ $# -gt 0 ]]; do case "$1" in --build-dir) build_dir="$(cd "$2" && pwd)"; shift 2 ;; --scratch) scratch="$2"; shift 2 ;; -h|--help) usage; exit 0 ;; --) shift; break ;; *) echo "unknown option: $1" >&2; usage >&2; exit 2 ;; esac done gui="$build_dir/bin/ObsidianDragon" stub="$build_dir/fake_dragonxd/dragonxd" # A Lite tree has no embedded daemon and builds ObsidianDragonLite; any bin/ObsidianDragon in it is stale. if grep -q '^DRAGONX_BUILD_LITE:BOOL=ON' "$build_dir/CMakeCache.txt" 2>/dev/null; then echo "$build_dir is configured as the Lite variant; pass --build-dir of a full-node tree" >&2 exit 1 fi if [[ ! -x "$gui" ]]; then echo "missing $gui; build the app first (./build.sh)" >&2 exit 1 fi if [[ ! -x "$stub" ]]; then echo "missing $stub; build it with:" >&2 echo " cmake -S . -B ${build_dir#"$repo"/} -DDRAGONX_BUILD_FAKE_DAEMON=ON && cmake --build ${build_dir#"$repo"/} --target fake_dragonxd" >&2 exit 1 fi if ss -ltn 2>/dev/null | grep -qE "[:.]$port( |$)"; then echo "port $port is already in use (a real dragonxd?). The GUI would adopt it as an external node; stop it first." >&2 exit 1 fi scratch="${scratch:-$(mktemp -d "${TMPDIR:-/tmp}/fake-dragonxd.XXXXXX")}" mkdir -p "$scratch" scratch="$(cd "$scratch" && pwd)" app="$scratch/app" home="$scratch/home" datadir="$home/.hush/DRAGONX" config_dir="$home/.config/ObsidianDragon" mkdir -p "$app" "$datadir/blocks" "$config_dir" "$scratch/tmp" # Copies, not symlinks: the GUI looks for dragonxd next to /proc/self/exe, which resolves links. cp -f "$gui" "$app/ObsidianDragon" cp -f "$stub" "$app/dragonxd" ln -sfn "$build_dir/bin/res" "$app/res" for f in sapling-spend.params sapling-output.params asmap.dat; do if [[ -e "$build_dir/bin/$f" ]]; then ln -sf "$build_dir/bin/$f" "$app/$f"; fi done # The GUI also keeps a dragonxd copy in its daemon dir; keep that one the stub too. if [[ -e "$config_dir/dragonx/dragonxd" ]]; then cp -f "$stub" "$config_dir/dragonx/dragonxd"; fi # A pre-made conf + blocks/ dir skips the first-run wizard (App::isFirstRun). if [[ ! -e "$datadir/DRAGONX.conf" ]]; then printf 'rpcuser=fake\nrpcpassword=fake-%s\nrpcport=%s\n' "$RANDOM$RANDOM" "$port" > "$datadir/DRAGONX.conf" fi if [[ ! -e "$config_dir/settings.json" ]]; then printf '{\n "wizard_completed": true,\n "verbose_logging": true\n}\n' > "$config_dir/settings.json" fi cat </dev/null || echo "(none)" if pgrep -f "^$app/dragonxd" >/dev/null; then echo "--- the stub is still running (pid $(pgrep -f "^$app/dragonxd" | tr '\n' ' ')); it exits after its rebuild + flush." fi exit "$rc"