fix: Multiple bug fixes for TUI stability and correctness

This commit is contained in:
SamNet-dev
2026-01-29 17:32:36 -06:00
parent 8519627e54
commit 9680fad2e8

View File

@@ -392,7 +392,7 @@ prompt_settings() {
echo -e "${CYAN}───────────────────────────────────────────────────────────────${NC}" echo -e "${CYAN}───────────────────────────────────────────────────────────────${NC}"
read -p " Set unlimited bandwidth? [y/N] " unlimited_bw < /dev/tty || true read -p " Set unlimited bandwidth? [y/N] " unlimited_bw < /dev/tty || true
if [[ "$unlimited_bw" =~ ^[Yy] ]]; then if [[ "$unlimited_bw" =~ ^[Yy]$ ]]; then
BANDWIDTH="-1" BANDWIDTH="-1"
echo -e " Selected: ${GREEN}Unlimited (-1)${NC}" echo -e " Selected: ${GREEN}Unlimited (-1)${NC}"
else else
@@ -474,7 +474,7 @@ prompt_settings() {
echo "" echo ""
read -p " Proceed with these settings? [Y/n] " confirm < /dev/tty || true read -p " Proceed with these settings? [Y/n] " confirm < /dev/tty || true
if [[ "$confirm" =~ ^[Nn] ]]; then if [[ "$confirm" =~ ^[Nn]$ ]]; then
continue continue
fi fi
break break
@@ -578,9 +578,10 @@ check_and_offer_backup_restore() {
echo -e " ${YELLOW}Note:${NC} If you don't restore, a new identity will be generated." echo -e " ${YELLOW}Note:${NC} If you don't restore, a new identity will be generated."
echo "" echo ""
while true; do
read -p " Do you want to restore your previous node identity? (y/n): " restore_choice < /dev/tty || true read -p " Do you want to restore your previous node identity? (y/n): " restore_choice < /dev/tty || true
if [ "$restore_choice" = "y" ] || [ "$restore_choice" = "Y" ]; then if [[ "$restore_choice" =~ ^[Yy]$ ]]; then
echo "" echo ""
log_info "Restoring node identity from backup..." log_info "Restoring node identity from backup..."
@@ -612,12 +613,15 @@ check_and_offer_backup_restore() {
echo "" echo ""
return 1 return 1
fi fi
else elif [[ "$restore_choice" =~ ^[Nn]$ ]]; then
echo "" echo ""
log_info "Skipping restore. A new node identity will be generated." log_info "Skipping restore. A new node identity will be generated."
echo "" echo ""
return 1 return 1
else
echo " Please enter y or n."
fi fi
done
} }
run_conduit() { run_conduit() {
@@ -2619,7 +2623,7 @@ change_settings() {
read -p " Set unlimited bandwidth? [y/N]: " set_unlimited < /dev/tty || true read -p " Set unlimited bandwidth? [y/N]: " set_unlimited < /dev/tty || true
local new_bandwidth="" local new_bandwidth=""
if [[ "$set_unlimited" =~ ^[Yy] ]]; then if [[ "$set_unlimited" =~ ^[Yy]$ ]]; then
new_bandwidth="-1" new_bandwidth="-1"
else else
read -p " New bandwidth in Mbps (1-40) [${cur_bw}]: " input_bw < /dev/tty || true read -p " New bandwidth in Mbps (1-40) [${cur_bw}]: " input_bw < /dev/tty || true
@@ -2776,14 +2780,19 @@ uninstall_all() {
echo "You have backed up node identity keys. These allow you to restore" echo "You have backed up node identity keys. These allow you to restore"
echo "your node identity if you reinstall Conduit later." echo "your node identity if you reinstall Conduit later."
echo "" echo ""
while true; do
read -p "Do you want to KEEP your backup keys? (y/n): " keep_confirm < /dev/tty || true read -p "Do you want to KEEP your backup keys? (y/n): " keep_confirm < /dev/tty || true
if [[ "$keep_confirm" =~ ^[Yy]$ ]]; then
if [ "$keep_confirm" = "y" ] || [ "$keep_confirm" = "Y" ]; then
keep_backups=true keep_backups=true
echo -e "${GREEN}✓ Backup keys will be preserved.${NC}" echo -e "${GREEN}✓ Backup keys will be preserved.${NC}"
else break
elif [[ "$keep_confirm" =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}⚠ Backup keys will be deleted.${NC}" echo -e "${YELLOW}⚠ Backup keys will be deleted.${NC}"
break
else
echo "Please enter y or n."
fi fi
done
echo "" echo ""
fi fi
@@ -3346,7 +3355,7 @@ show_settings_menu() {
read -p " Enter choice: " choice < /dev/tty || { return; } read -p " Enter choice: " choice < /dev/tty || { return; }
case $choice in case "$choice" in
1) 1)
change_settings change_settings
redraw=true redraw=true
@@ -3386,6 +3395,7 @@ show_settings_menu() {
;; ;;
9) 9)
echo "" echo ""
while true; do
read -p "Reset tracker and delete all stats data? (y/n): " confirm < /dev/tty || true read -p "Reset tracker and delete all stats data? (y/n): " confirm < /dev/tty || true
if [[ "$confirm" =~ ^[Yy]$ ]]; then if [[ "$confirm" =~ ^[Yy]$ ]]; then
echo "Stopping tracker service..." echo "Stopping tracker service..."
@@ -3397,9 +3407,14 @@ show_settings_menu() {
regenerate_tracker_script regenerate_tracker_script
setup_tracker_service setup_tracker_service
echo -e "${GREEN}Tracker data has been reset.${NC}" echo -e "${GREEN}Tracker data has been reset.${NC}"
else break
elif [[ "$confirm" =~ ^[Nn]$ ]]; then
echo "Cancelled." echo "Cancelled."
break
else
echo "Please enter y or n."
fi fi
done
read -n 1 -s -r -p "Press any key to return..." < /dev/tty || true read -n 1 -s -r -p "Press any key to return..." < /dev/tty || true
redraw=true redraw=true
;; ;;
@@ -3468,7 +3483,7 @@ show_menu() {
read -p " Enter choice: " choice < /dev/tty || { echo "Input error. Exiting."; exit 1; } read -p " Enter choice: " choice < /dev/tty || { echo "Input error. Exiting."; exit 1; }
case $choice in case "$choice" in
1) 1)
show_dashboard show_dashboard
redraw=true redraw=true
@@ -3806,26 +3821,34 @@ health_check() {
# Single docker logs call for network + stats checks # Single docker logs call for network + stats checks
local hc_logs=$(docker logs --tail 100 "$cname" 2>&1) local hc_logs=$(docker logs --tail 100 "$cname" 2>&1)
local hc_stats_lines=$(echo "$hc_logs" | grep "\[STATS\]") local hc_stats_lines=$(echo "$hc_logs" | grep "\[STATS\]" || true)
local hc_stats_count=$(echo "$hc_stats_lines" | grep -c "\[STATS\]" 2>/dev/null || echo 0) local hc_stats_count=0
if [ -n "$hc_stats_lines" ]; then
hc_stats_count=$(echo "$hc_stats_lines" | wc -l | tr -d ' ')
fi
hc_stats_count=${hc_stats_count:-0}
local hc_last_stat=$(echo "$hc_stats_lines" | tail -1) local hc_last_stat=$(echo "$hc_stats_lines" | tail -1)
local hc_connected=$(echo "$hc_last_stat" | sed -n 's/.*Connected:[[:space:]]*\([0-9]*\).*/\1/p') local hc_connected=$(echo "$hc_last_stat" | sed -n 's/.*Connected:[[:space:]]*\([0-9]*\).*/\1/p' | head -1 | tr -d '\n')
hc_connected=${hc_connected:-0} hc_connected=${hc_connected:-0}
local hc_connecting=$(echo "$hc_last_stat" | sed -n 's/.*Connecting:[[:space:]]*\([0-9]*\).*/\1/p') local hc_connecting=$(echo "$hc_last_stat" | sed -n 's/.*Connecting:[[:space:]]*\([0-9]*\).*/\1/p' | head -1 | tr -d '\n')
hc_connecting=${hc_connecting:-0} hc_connecting=${hc_connecting:-0}
echo -n "Network connection: " echo -n "Network connection: "
if [ "$hc_connected" -gt 0 ]; then if [ "$hc_connected" -gt 0 ] 2>/dev/null; then
echo -e "${GREEN}OK${NC} (${hc_connected} peers connected, ${hc_connecting} connecting)" echo -e "${GREEN}OK${NC} (${hc_connected} peers connected, ${hc_connecting} connecting)"
elif [ "$hc_stats_count" -gt 0 ]; then elif [ "$hc_stats_count" -gt 0 ] 2>/dev/null; then
if [ "$hc_connecting" -gt 0 ]; then if [ "$hc_connecting" -gt 0 ] 2>/dev/null; then
echo -e "${GREEN}OK${NC} (Connected, ${hc_connecting} peers connecting)" echo -e "${GREEN}OK${NC} (Connected, ${hc_connecting} peers connecting)"
else else
echo -e "${GREEN}OK${NC} (Connected, awaiting peers)" echo -e "${GREEN}OK${NC} (Connected, awaiting peers)"
fi fi
else else
local info_lines=$(echo "$hc_logs" | grep -c "\[INFO\]" 2>/dev/null || echo 0) local info_lines=0
if [ "$info_lines" -gt 0 ]; then if [ -n "$hc_logs" ]; then
info_lines=$(echo "$hc_logs" | grep "\[INFO\]" | wc -l | tr -d ' ')
fi
info_lines=${info_lines:-0}
if [ "$info_lines" -gt 0 ] 2>/dev/null; then
echo -e "${YELLOW}CONNECTING${NC} - Establishing connection..." echo -e "${YELLOW}CONNECTING${NC} - Establishing connection..."
else else
echo -e "${YELLOW}WAITING${NC} - Starting up..." echo -e "${YELLOW}WAITING${NC} - Starting up..."
@@ -3833,7 +3856,7 @@ health_check() {
fi fi
echo -n "Stats output: " echo -n "Stats output: "
if [ "$hc_stats_count" -gt 0 ]; then if [ "$hc_stats_count" -gt 0 ] 2>/dev/null; then
echo -e "${GREEN}OK${NC} (${hc_stats_count} entries)" echo -e "${GREEN}OK${NC} (${hc_stats_count} entries)"
else else
echo -e "${YELLOW}NONE${NC} - Run 'conduit restart' to enable" echo -e "${YELLOW}NONE${NC} - Run 'conduit restart' to enable"
@@ -3931,8 +3954,8 @@ backup_key() {
echo -e "${GREEN}✓ Backup created successfully${NC}" echo -e "${GREEN}✓ Backup created successfully${NC}"
echo "" echo ""
echo " Backup file: ${CYAN}${backup_file}${NC}" echo -e " Backup file: ${CYAN}${backup_file}${NC}"
echo " Node ID: ${CYAN}${node_id}${NC}" echo -e " Node ID: ${CYAN}${node_id}${NC}"
echo "" echo ""
echo -e "${YELLOW}Important:${NC} Store this backup securely. It contains your node's" echo -e "${YELLOW}Important:${NC} Store this backup securely. It contains your node's"
echo "private key which identifies your node on the Psiphon network." echo "private key which identifies your node on the Psiphon network."
@@ -4001,7 +4024,7 @@ restore_key() {
echo "" echo ""
read -p "Proceed with restore? [y/N] " confirm < /dev/tty || true read -p "Proceed with restore? [y/N] " confirm < /dev/tty || true
if [[ ! "$confirm" =~ ^[Yy] ]]; then if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Restore cancelled." echo "Restore cancelled."
return 0 return 0
fi fi
@@ -4059,7 +4082,7 @@ restore_key() {
echo "" echo ""
echo -e "${GREEN}✓ Node key restored successfully${NC}" echo -e "${GREEN}✓ Node key restored successfully${NC}"
echo " Node ID: ${CYAN}${node_id}${NC}" echo -e " Node ID: ${CYAN}${node_id}${NC}"
} }
update_conduit() { update_conduit() {
@@ -4069,14 +4092,26 @@ update_conduit() {
echo "Current image: ${CONDUIT_IMAGE}" echo "Current image: ${CONDUIT_IMAGE}"
echo "" echo ""
# Check for updates by pulling # Check for updates by pulling and capture output
echo "Checking for updates..." echo "Checking for updates..."
if ! docker pull "$CONDUIT_IMAGE" 2>/dev/null; then local pull_output
pull_output=$(docker pull "$CONDUIT_IMAGE" 2>&1)
local pull_status=$?
echo "$pull_output"
if [ $pull_status -ne 0 ]; then
echo -e "${RED}Failed to check for updates. Check your internet connection.${NC}" echo -e "${RED}Failed to check for updates. Check your internet connection.${NC}"
return 1 return 1
fi fi
# Check if image was actually updated
if echo "$pull_output" | grep -q "Status: Image is up to date"; then
echo ""
echo -e "${GREEN}Already running the latest version. No update needed.${NC}"
return 0
fi
echo "" echo ""
echo "Recreating container(s) with updated image..." echo "Recreating container(s) with updated image..."
@@ -4306,7 +4341,7 @@ main() {
echo "" echo ""
read -p " Enter choice: " choice < /dev/tty || true read -p " Enter choice: " choice < /dev/tty || true
case $choice in case "$choice" in
1) 1)
echo -e "${CYAN}Updating management script and opening menu...${NC}" echo -e "${CYAN}Updating management script and opening menu...${NC}"
create_management_script create_management_script
@@ -4384,7 +4419,7 @@ main() {
print_summary print_summary
read -p "Open management menu now? [Y/n] " open_menu < /dev/tty || true read -p "Open management menu now? [Y/n] " open_menu < /dev/tty || true
if [[ ! "$open_menu" =~ ^[Nn] ]]; then if [[ ! "$open_menu" =~ ^[Nn]$ ]]; then
"$INSTALL_DIR/conduit" menu "$INSTALL_DIR/conduit" menu
fi fi
} }