diff --git a/installer b/installer index 4f6477d..abccd79 100755 --- a/installer +++ b/installer @@ -893,7 +893,156 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { EOF # --------------------------------------------------------------------------- -echo "[7/8] NGINX with HTTPS + redirect" +echo "System Dashboard" +# --------------------------------------------------------------------------- +cat > /usr/local/sbin/btc-console-dashboard <<'EOF' +#!/bin/bash +# Console dashboard for Bitcoin Solo Miner + +BITCOIN_CLI="/usr/local/bin/bitcoin-cli" +BITCOIN_CONF="/etc/bitcoin/bitcoin.conf" +DATADIR="/var/lib/bitcoind" + +# colors +RED="\033[31m" +GRN="\033[32m" +YEL="\033[33m" +BLU="\033[34m" +CYN="\033[36m" +BOLD="\033[1m" +RST="\033[0m" + +get_ip() { + ip -4 addr show scope global 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1 +} + +draw_header() { + tput clear + tput civis 2>/dev/null || true + tput cup 0 0; echo -e "${BOLD}Bitcoin Node for Solo Miners${RST}" + tput cup 1 0; echo -e "A Linux Appliance by Robbie Ferguson" + tput cup 2 0; printf '%*s' "$(tput cols)" '' | tr ' ' '─' +} + +draw_dynamic() { + # args: time ip web status progress services workers + local now="$1" + local ip="$2" + local web="$3" + local status="$4" + local progress="$5" + local services="$6" + local workers="$7" + + # line 3 was the bar, so start at 3/4 + tput cup 3 0; echo -e "Time: ${CYN}${now}${RST}\033[K" + tput cup 4 0; echo -e "IP: ${CYN}${ip}${RST}\033[K" + tput cup 5 0; echo -e "Web: ${CYN}${web}${RST}\033[K" + tput cup 6 0; printf '%*s' "$(tput cols)" '' | tr ' ' '─' + + tput cup 7 0; echo -e "${status}\033[K" + tput cup 8 0; echo -e "${progress}\033[K" + tput cup 9 0; echo -e "${services}\033[K" + + tput cup 10 0; printf '%*s' "$(tput cols)" '' | tr ' ' '─' + tput cup 11 0; echo -e "Workers:\033[K" + tput cup 12 2; echo -e "${workers}\033[K" + + tput cup 14 0; echo -e "(Appliance console view. Use the web UI for full details.)\033[K" +} + +draw_header + +while true; do + # 1) COLLECT DATA FIRST + NOW=$(date '+%Y-%m-%d %H:%M') + + IPADDR=$(get_ip) + [ -z "$IPADDR" ] && IPADDR="No network" + WEB="https://${IPADDR}/" + + BTC_STATE=$(systemctl is-active bitcoind 2>/dev/null || true) + CKP_STATE=$(systemctl is-active ckpool 2>/dev/null || true) + + STATUS_LINE="" + PROGRESS_LINE="" + SERVICES_LINE="Bitcoin: ${BTC_STATE} CKPool: ${CKP_STATE}" + WORKERS_LINE="No workers detected (point your ASICs at this node)" + + # try to get blockchain info + INFO=$($BITCOIN_CLI -conf="$BITCOIN_CONF" getblockchaininfo 2>/dev/null) + + if [ "$BTC_STATE" != "active" ]; then + STATUS_LINE="${RED}❌ Bitcoin service is not running.${RST}" + elif [ -z "$INFO" ]; then + STATUS_LINE="${RED}❌ bitcoin-cli did not respond.${RST}" + else + # we have info; parse it + if command -v jq >/dev/null 2>&1; then + IBD=$(echo "$INFO" | jq -r '.initialblockdownload') + BLOCKS=$(echo "$INFO" | jq -r '.blocks') + HEADERS=$(echo "$INFO" | jq -r '.headers') + PROG=$(echo "$INFO" | jq -r '.verificationprogress') + PRUNED=$(echo "$INFO" | jq -r '.pruned') + + if [ "$PROG" != "null" ]; then + PROG_PCT=$(printf "%.1f" "$(echo "$PROG * 100" | bc -l 2>/dev/null || echo 0)") + else + PROG_PCT="0.0" + fi + + if [ "$IBD" = "true" ]; then + # still syncing + if [ "$(echo "$PROG_PCT < 0.1" | bc -l 2>/dev/null || echo 0)" = "1" ]; then + STATUS_LINE="${YEL}⚠ Bitcoin Core is starting up and loading blockchain data…${RST}" + else + STATUS_LINE="${YEL}⚠ Syncing blockchain… ${PROG_PCT}%${RST}" + fi + else + STATUS_LINE="${GRN}✔ Bitcoin Core is ready.${RST}" + fi + + PROGRESS_LINE="Blocks: ${BLOCKS} / ${HEADERS} $( [ "$PRUNED" = "true" ] && echo '(pruned)' )" + else + STATUS_LINE="${CYN}ℹ Bitcoin Core is active (install jq for more detail).${RST}" + fi + fi + + # 2) NOW DRAW (single block) + draw_dynamic "$NOW" "$IPADDR" "$WEB" "$STATUS_LINE" "$PROGRESS_LINE" "$SERVICES_LINE" "$WORKERS_LINE" + + sleep 5 +done +EOF + +chmod +x /usr/local/sbin/btc-console-dashboard + +cat > /etc/systemd/system/btc-console-dashboard.service <<'EOF' +[Unit] +Description=Bitcoin Solo Miner Console Dashboard (dialog) +After=network-online.target +WantedBy=multi-user.target + +[Service] +Type=simple +ExecStart=/usr/local/sbin/btc-console-dashboard +StandardInput=tty +StandardOutput=tty +TTYPath=/dev/tty1 +TTYReset=yes +TTYVHangup=yes +Restart=always + +[Install] +WantedBy=getty.target +EOF + +systemctl daemon-reload +systemctl disable getty@tty1.service --now 2>/dev/null || true +systemctl enable --now btc-console-dashboard.service + +# --------------------------------------------------------------------------- +echo "NGINX with HTTPS + redirect" # --------------------------------------------------------------------------- mkdir -p "$CERT_DIR" openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \