diff --git a/scripts/extract_nprofile.sh b/scripts/extract_nprofile.sh new file mode 100644 index 00000000..ee7e9044 --- /dev/null +++ b/scripts/extract_nprofile.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +get_log_info() { + if [ "$EUID" -eq 0 ]; then + USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6) + USER_NAME=$SUDO_USER + else + USER_HOME=$HOME + USER_NAME=$(whoami) + fi + + LOG_DIR="$USER_HOME/lightning_pub/logs" + MAX_ATTEMPTS=4 + ATTEMPT=0 + + find_latest_log() { + ls -1t ${LOG_DIR}/components/nostrMiddleware_*.log 2>/dev/null | head -n 1 + } + + while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do + LATEST_LOG=$(find_latest_log) + if [ -n "$LATEST_LOG" ]; then + break + fi + echo "Awaiting nostr information..." + sleep 4 + ATTEMPT=$((ATTEMPT + 1)) + done + + if [ -z "$LATEST_LOG" ]; then + echo "Failed to find the log file, check service status" + exit 1 + fi + + nprofile_key=$(grep -oP 'nprofile: \K\w+' "$LATEST_LOG") + + if [ -z "$nprofile_key" ]; then + echo "No nprofile key found in the log." + exit 1 + fi + + # Print the extracted key + echo "Paste this string into ShockWallet to connect to the node: $nprofile_key" +} + +get_log_info \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh index 35cb812c..a47132e8 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,7 +2,6 @@ set -e BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/fix/bootstrap/scripts/" - modules=( "utils" "check_homebrew" @@ -13,6 +12,7 @@ modules=( "install_nodejs" "install_lightning_pub" "start_services" + "extract_nprofile" # Add extract_nprofile to the modules array ) for module in "${modules[@]}"; do @@ -40,4 +40,5 @@ else install_nodejs install_lightning_pub start_services -fi + get_log_info +fi \ No newline at end of file