#!/usr/bin/env bash # JesusOS MAIN original Stratum real-pool diagnostic, preserves existing Termux sessions. # Uses original existing directory, a SHA-256-pinned ORIGINAL relay and the # installed original JesusOS agent. Never modifies or kills the old custom proxy. # Requires a genuine operator-selected Bitcoin pool + worker + reporter token. # Runs in the foreground, no password/token files, no claim of BTC income. set -euo pipefail dir="$HOME/jesusos-bitcoin-mining" base='https://jesusos.online' relay_hash='5fa74b2366c8ef8d4c7885c9885237fe0ea2d9db36821ce42a72edb9223c45a3' agent_hash='e89784ae28eadfc95a7c24d188498ca5b5b84d5812bcb7cb7c44ca700c34a831' relay="$dir/jesusos-original-pinned-stratum-proxy.mjs" agent="$dir/jesusos-mining-reporter.mjs" echo 'JesusOS MAIN — NON-DESTRUCTIVE original pool verification. Existing status 3340 and auto-reporter remain untouched.' for tool in curl node sha256sum; do command -v "$tool" >/dev/null || { echo "Missing: $tool" >&2; exit 2; }; done [[ -d "$dir" && -f "$agent" ]] || { echo 'Original Termux workspace not installed. Run the JesusOS installer v2 first.' >&2;exit 2; } [[ "$(sha256sum "$agent" | cut -d' ' -f1)" == "$agent_hash" ]] || { echo 'Installed agent fingerprint mismatch. No process touched.' >&2; exit 3; } # The original jesusos-local-status.mjs owns 3340. Preserve that service. # Test that BOTH required ports are free, independent of the status endpoint. node --input-type=module -e ' import net from "node:net"; for(const port of [3334,3345]){ const ok=await new Promise(resolve=>{ const s=net.createServer(); s.once("error",()=>resolve(false)); s.listen(port,"127.0.0.1",()=>s.close(()=>resolve(true))); }); if(!ok){console.error("BLOCKED: port "+port+" is in use. No process changed.");process.exit(4)} }' || exit 4 if [[ ! -f "$relay" ]]; then tempdir="$(mktemp -d)" tmp="$tempdir/relay.mjs" trap 'rm -rf "$tempdir"' EXIT curl -fsSL --max-time 20 "$base/jesusos-stratum-proxy-v1.txt" -o "$tmp" printf '%s %s\n' "$relay_hash" "$tmp" | sha256sum --check --status || { echo 'Pinned Stratum relay SHA-256 mismatch. Nothing started.' >&2;exit 3; } node --check "$tmp" cp "$tmp" "$relay" chmod 600 "$relay" rm -f "$tmp" rmdir "$tempdir" trap - EXIT fi [[ "$(sha256sum "$relay" | cut -d' ' -f1)" == "$relay_hash" ]] || { echo 'Pinned Stratum relay SHA-256 mismatch. Nothing started.' >&2;exit 3; } node -e 'if(Number(process.versions.node.split(".")[0])<20)process.exit(2)' || { echo 'Node.js 20 or newer required' >&2;exit 2; } # Check named settings, never look for a wallet key or replace an existing pool identity. if [[ -z "${STRATUM_HOST:-}" ]]; then read -r -p 'Authorized pool HOST (hostname only, no scheme): ' STRATUM_HOST fi [[ "$STRATUM_HOST" =~ ^[a-zA-Z0-9.-]+$ ]] || { echo 'Invalid pool hostname; expected hostname without stratum://.' >&2;exit 2; } if [[ -z "${STRATUM_PORT:-}" ]]; then read -r -p 'Authorized pool PORT (ask your pool): ' STRATUM_PORT fi [[ "$STRATUM_PORT" =~ ^[0-9]{1,5}$ ]] && ((10#$STRATUM_PORT>0 && 10#$STRATUM_PORT<=65535)) || { echo 'Invalid port' >&2;exit 2; } STRATUM_PORT="$((10#$STRATUM_PORT))" if [[ -z "${STRATUM_WORKER:-}" ]]; then read -r -p 'Authorized pool WORKER (associated with YOUR payout account): ' STRATUM_WORKER fi [[ -n "$STRATUM_WORKER" && "$STRATUM_WORKER" != *$'\n'* && "${#STRATUM_WORKER}" -le 230 ]] || { echo 'Invalid worker identifier' >&2;exit 2; } if [[ -z "${STRATUM_TLS:-}" ]]; then read -r -p 'Does your selected pool port use TLS? [yes/no]: ' tls_answer case "$tls_answer" in yes|y|YES|Y) STRATUM_TLS=true;; no|n|NO|N) STRATUM_TLS=false;; *)echo 'Specify yes or no' >&2;exit 2;; esac fi [[ "$STRATUM_TLS" == 'true' || "$STRATUM_TLS" == 'false' ]] || { echo 'STRATUM_TLS must be true or false' >&2;exit 2; } if [[ -z "${STRATUM_PASSWORD:-}" ]]; then read -r -s -p 'Pool worker password (Enter for x): ' STRATUM_PASSWORD echo STRATUM_PASSWORD="${STRATUM_PASSWORD:-x}" fi export STRATUM_HOST STRATUM_PORT STRATUM_WORKER STRATUM_TLS STRATUM_PASSWORD export STATUS_PORT=3345 LOCAL_STRATUM_PORT=3334 LOCAL_STRATUM_HOST=127.0.0.1 cd "$dir" # Download only the already published, pinned CPU worker. Do not replace # an existing custom worker; use a new isolated filename. miner="$dir/jesusos-original-pinned-cpu-miner.mjs" miner_sha='2cdc072de0f8915250651bca8aae2853136e244fe4373e4926455b2f16f554c4' if [[ ! -f "$miner" ]]; then tempdir="$(mktemp -d)" tmp="$tempdir/miner.mjs" trap 'rm -rf "$tempdir"' EXIT curl -fsSL --max-time 20 "$base/jesusos-owner-cpu-miner-v1.txt" -o "$tmp" printf '%s %s\n' "$miner_sha" "$tmp" | sha256sum --check --status || { echo 'CPU miner SHA-256 mismatch; no process started.' >&2;exit 3; } node --check "$tmp" cp "$tmp" "$miner" chmod 600 "$miner" rm -f "$tmp" rmdir "$tempdir" trap - EXIT fi [[ "$(sha256sum "$miner" | cut -d' ' -f1)" == "$miner_sha" ]] || { echo 'Pinned miner fingerprint mismatch; no process started.' >&2;exit 3; } echo 'Checking real pool for a bounded 90-second CPU worker session.' echo 'Legacy JesusOS status on 3340, auto-reporter and all HeavenCoin sessions remain running.' echo 'No wallet password, reporter token or server-side mission is required for this one local pool test.' relay_pid='' cleanup(){ trap - INT TERM EXIT if [[ -n "$relay_pid" ]]; then # This is our own child PID, not a scanned Termux/HeavenCoin service. # The pinned original relay's SIGTERM handler closes TCP but does not # close its independent HTTP status listener, so ensure it really exits. kill -TERM "$relay_pid" 2>/dev/null || true for _ in 1 2 3 4 5; do if ! kill -0 "$relay_pid" 2>/dev/null; then break; fi sleep 0.2 done if kill -0 "$relay_pid" 2>/dev/null; then kill -KILL "$relay_pid" 2>/dev/null || true fi wait "$relay_pid" 2>/dev/null || true fi } trap cleanup EXIT trap 'exit 130' INT TERM node "$relay" & relay_pid=$! ready=0 for _ in 1 2 3 4 5 6 7 8 9 10; do if ! kill -0 "$relay_pid" 2>/dev/null; then break; fi if curl -fsS --max-time 1 'http://127.0.0.1:3345/status' >/dev/null 2>&1; then ready=1;break;fi sleep 1 done if (( ready != 1 )); then echo 'Pinned Stratum relay did not become ready on 3345; no worker started.' >&2;exit 5 fi node "$miner" --selftest session_seconds="${JESUSOS_MINING_SECONDS:-90}" [[ "$session_seconds" =~ ^[0-9]{1,2}$ ]] && ((session_seconds>=5 && session_seconds<=90)) || { echo 'JESUSOS_MINING_SECONDS must be 5..90; refusing to start.' >&2; exit 2; } echo "Local mining protocol worker beginning bounded ${session_seconds}-second test." JESUSOS_MINING_SECONDS="$session_seconds" JESUSOS_HASHES_PER_SECOND=5000 node "$miner" --mine echo 'Original-device pool test concluded. This does not establish pool credit or BTC payout.'