This commit is contained in:
Justin (shocknet) 2024-07-23 11:08:58 -04:00
parent 637e76e20d
commit 86bbe4f1dc

View file

@ -10,6 +10,7 @@ get_log_info() {
fi fi
LOG_DIR="$USER_HOME/lightning_pub/logs" LOG_DIR="$USER_HOME/lightning_pub/logs"
DATA_DIR="$USER_HOME/lightning_pub/"
START_TIME=$(date +%s) START_TIME=$(date +%s)
MAX_WAIT_TIME=120 # Maximum wait time in seconds MAX_WAIT_TIME=120 # Maximum wait time in seconds
WAIT_INTERVAL=5 # Time to wait between checks in seconds WAIT_INTERVAL=5 # Time to wait between checks in seconds
@ -42,24 +43,36 @@ get_log_info() {
log "Wallet status: $(echo "$latest_entry" | cut -d' ' -f4-)" log "Wallet status: $(echo "$latest_entry" | cut -d' ' -f4-)"
# Find nprofile key log "Retrieving connection information..."
MAX_ATTEMPTS=4
ATTEMPT=0
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do # Wait for either .admin_connect or app.nprofile to appear
LATEST_LOG=$(ls -1t ${LOG_DIR}/components/nostrMiddleware_*.log 2>/dev/null | head -n 1) START_TIME=$(date +%s)
if [ -n "$LATEST_LOG" ]; then while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do
latest_nprofile_key=$(grep -oP 'nprofile: \K\w+' "$LATEST_LOG" | tail -n 1) if [ -f "$DATA_DIR/.admin_connect" ]; then
[ -n "$latest_nprofile_key" ] && break admin_connect=$(cat "$DATA_DIR/.admin_connect")
# Check if the admin_connect string is complete (contains both nprofile and secret)
if [[ $admin_connect == nprofile* ]] && [[ $admin_connect == *:* ]]; then
log "An admin has not yet been enrolled."
log "Paste this string into ShockWallet to administer the node:"
log "${SECONDARY_COLOR}$admin_connect${RESET_COLOR}"
break
else
log "Waiting for complete admin connect information..."
fi
elif [ -f "$DATA_DIR/app.nprofile" ]; then
app_nprofile=$(cat "$DATA_DIR/app.nprofile")
log "Node is already set up. Use this nprofile to invite guestusers:"
log "${SECONDARY_COLOR}$app_nprofile${RESET_COLOR}"
break
fi fi
sleep 4 sleep $WAIT_INTERVAL
ATTEMPT=$((ATTEMPT + 1))
done done
if [ -z "$latest_nprofile_key" ]; then if [ ! -f "$DATA_DIR/.admin_connect" ] && [ ! -f "$DATA_DIR/app.nprofile" ]; then
log "Error: Failed to find nprofile key. Please check the service status." log "Error: Neither .admin_connect nor app.nprofile file found after waiting. Please check the service status."
exit 1
elif [ -f "$DATA_DIR/.admin_connect" ] && ! [[ $(cat "$DATA_DIR/.admin_connect") == nprofile1* ]] && ! [[ $(cat "$DATA_DIR/.admin_connect") == *:* ]]; then
log "Error: Admin connect information is incomplete. Please check the service status."
exit 1 exit 1
fi fi
log "Paste this string into ShockWallet to connect to the node: $latest_nprofile_key"
} }