#!/usr/bin/env bash # JesusOS MAIN original Termux local Stratum connection — operator opt-in. # 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 — existing original Android mining connection' 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; } # Never compete with or impersonate the already running 3340 reporter endpoint. if curl -fsS --max-time 2 'http://127.0.0.1:3340/status' >/dev/null 2>&1; then echo 'BLOCKED: Original local status 127.0.0.1:3340 is already running.' echo 'Do not launch a second relay or reporter. Stop ONLY that old process in' echo 'its original Termux session first, then rerun this command.' echo 'No existing processes were terminated; no secrets were requested.' exit 4 fi # 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,3340]){ 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 "${JESUSOS_MINING_REPORTER_TOKEN:-}" ]]; then read -r -s -p 'JesusOS existing reporter token (private, hidden): ' JESUSOS_MINING_REPORTER_TOKEN echo fi [[ "$JESUSOS_MINING_REPORTER_TOKEN" =~ ^jmr1_[0-9a-f]{64}$ ]] || { echo 'Missing or invalid JesusOS reporter token; acquire it from signed-in /bitcoin-mining-telemetry. Do not paste it into chat.' >&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 JESUSOS_MINING_REPORTER_TOKEN export STATUS_PORT=3340 LOCAL_STRATUM_PORT=3334 LOCAL_STRATUM_HOST=127.0.0.1 export JESUSOS_DEVICE_ALLOW_MINING=1 cd "$dir" echo 'Starting one PINNED relay and the existing opted-in device agent.' echo 'Pool hostname and pool worker provided locally; credentials never printed or saved.' echo 'Ctrl+C in THIS terminal stops only these two child processes.' relay_pid='' agent_pid='' cleanup(){ trap - INT TERM EXIT [[ -z "$agent_pid" ]] || kill -TERM "$agent_pid" 2>/dev/null || true [[ -z "$relay_pid" ]] || kill -TERM "$relay_pid" 2>/dev/null || true } 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 2 'http://127.0.0.1:3340/status' >/dev/null 2>&1; then ready=1;break fi sleep 1 done if (( ready != 1 )); then echo 'Relay did not become ready on local port 3340. Agent NOT started.' >&2;exit 5 fi node "$agent" & agent_pid=$! echo 'JesusOS MAIN original-device agent running; waiting for hourly bounded work.' echo 'One relay, one reporter. Real pool authorization and accepted shares still need verification.' wait "$agent_pid" || exit $?