#!/usr/bin/env bash # JesusOS MAIN original Termux mining agent setup v2. # If an original installation cannot be found, reconstruct the EXISTING JesusOS # source layout in ~/jesusos-bitcoin-mining. Never auto-start/kill a process. set -euo pipefail BASE='https://jesusos.online' AGENT_SHA='e89784ae28eadfc95a7c24d188498ca5b5b84d5812bcb7cb7c44ca700c34a831' MINER_SHA='2cdc072de0f8915250651bca8aae2853136e244fe4373e4926455b2f16f554c4' LAUNCHER_SHA='98093a654db90fd11edbfb33ea56aa0b4c6545d56237e3a22456d3ae7483e5e3' PROXY_SHA='5fa74b2366c8ef8d4c7885c9885237fe0ea2d9db36821ce42a72edb9223c45a3' echo 'JesusOS MAIN · original-device setup v2 (no additional app or credentials)' for bin in node curl sha256sum find mktemp; do command -v "$bin" >/dev/null || { printf 'Missing %s in the original Termux environment.\n' "$bin" >&2; exit 2; } done node -e 'if(Number(process.versions.node.split(".")[0])<20)process.exit(2)' || { echo 'Node.js 20+ required.' >&2; exit 2; } if [[ -n "${JESUSOS_MINER_DIR:-}" ]]; then dir="$JESUSOS_MINER_DIR" echo 'Using explicitly selected existing JesusOS directory.' else mapfile -t matches < <(find "$HOME" -maxdepth 8 -type f -name jesusos-mining-launch.mjs -print 2>/dev/null) if (( ${#matches[@]} == 1 )); then dir="$(dirname "${matches[0]}")" echo 'Discovered one existing JesusOS launcher.' elif (( ${#matches[@]} == 0 )); then dir="$HOME/jesusos-bitcoin-mining" echo 'No original launcher files were found. Preparing canonical source in the current JesusOS mining workspace.' else printf 'Found %s launchers. Not safe to choose. Set JESUSOS_MINER_DIR and retry.\n' "${#matches[@]}" >&2 exit 2 fi fi mkdir -p "$dir" dir="$(cd "$dir" && pwd -P)" [[ "$dir" == "$HOME"* ]] || { echo 'Refusing to write outside the original Termux home directory.' >&2; exit 2; } temp="$(mktemp -d)" trap 'rm -rf "$temp"' EXIT fetch_verified(){ local label="$1" url="$2" hash="$3" filename="$4" curl -fsSL --retry 1 --max-time 20 "$BASE/$url" -o "$temp/$filename" printf '%s %s\n' "$hash" "$temp/$filename" | sha256sum --check --status || { echo "Failed $label SHA-256 verification. No files have been changed." >&2; exit 3; } } # Download AND verify ALL code before modifying original files. fetch_verified 'mining agent' 'jesusos-mining-device-agent-v1.txt' "$AGENT_SHA" agent.mjs fetch_verified 'CPU miner' 'jesusos-owner-cpu-miner-v1.txt' "$MINER_SHA" miner.mjs fetch_verified 'original launcher' 'jesusos-mining-launch-v1.txt' "$LAUNCHER_SHA" launcher.mjs fetch_verified 'original proxy' 'jesusos-stratum-proxy-v1.txt' "$PROXY_SHA" proxy.mjs for file in agent.mjs miner.mjs launcher.mjs proxy.mjs; do node --check "$temp/$file"; done node "$temp/agent.mjs" --selftest node "$temp/miner.mjs" --selftest # Never clobber an existing different launcher or proxy. This is a safe # recovery of missing source files, not replacement of an unknown installation. install_if_missing(){ local source="$1" target="$2" expected="$3" if [[ -e "$target" ]]; then if [[ ! -f "$target" ]]; then echo "Refusing non-file path: $target" >&2; exit 4; fi local actual actual="$(sha256sum "$target")";actual="${actual%% *}" if [[ "$actual" != "$expected" ]]; then echo "Existing custom file kept, not overwritten: $target" fi else cp "$temp/$source" "$target" chmod 600 "$target" echo "Reconstructed missing source: ${target##*/}" fi } install_if_missing launcher.mjs "$dir/jesusos-mining-launch.mjs" "$LAUNCHER_SHA" install_if_missing proxy.mjs "$dir/jesusos-stratum-proxy.mjs" "$PROXY_SHA" old="$dir/jesusos-mining-reporter.mjs" backup="$dir/jesusos-mining-reporter.mjs.before-agent" if [[ -e "$old" && ! -f "$old" ]]; then echo 'Existing reporter is not a regular file. Refusing to replace.' >&2; exit 4; fi if [[ -f "$old" && ! -f "$backup" ]]; then cp -p "$old" "$backup"; chmod 600 "$backup" echo 'Backed up original local reporter.' fi cp "$temp/agent.mjs" "$dir/.jesusos-mining-reporter.mjs.new" chmod 600 "$dir/.jesusos-mining-reporter.mjs.new" mv -f "$dir/.jesusos-mining-reporter.mjs.new" "$old" entry="$dir/jesusos-mining-start-with-agent.sh" cat >"$entry" <<'RUN' #!/usr/bin/env bash set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" export JESUSOS_DEVICE_ALLOW_MINING=1 exec node ./jesusos-mining-launch.mjs RUN chmod 700 "$entry" echo 'SETUP VERIFIED: original JesusOS relay, reporter and hashing source are present.' echo "Selected workspace: $dir" echo 'No device process was started, stopped or duplicated.' if curl -fsS --max-time 2 'http://127.0.0.1:3340/status' >/dev/null 2>&1; then echo 'ALERT: Local status port 3340 is already occupied. Stop the existing launcher BEFORE starting a new one.' fi missing=() for var in STRATUM_HOST STRATUM_WORKER JESUSOS_MINING_REPORTER_TOKEN; do [[ -n "${!var:-}" ]] || missing+=("$var") done if (( ${#missing[@]} )); then printf 'NOT STARTED — these environment values are absent in this shell: %s\n' "${missing[*]}" echo 'Use the ORIGINAL valid pool worker and existing signed-in JesusOS reporter token; do not paste secrets into chat.' else echo 'The original pool and reporter environment variable names are present (values not printed).' fi echo 'After stopping the OLD launcher (if any), start this existing JesusOS launcher from a shell with its settings:' printf ' %q\n' "$entry" if [[ -f "$backup" ]]; then echo 'Rollback if needed (after stopping the launcher):' printf ' cp -- %q %q\n' "$backup" "$old" fi echo 'Device installation by itself does not prove actual pool shares or earnings.'