@@ -48,7 +48,7 @@ show_banner() {
4848 echo " / ____/ /_/ (__ ) / / / / /___/ / / / /_/ / / / / / "
4949 echo " /_/ \\ __,_/____/_/ /_/ \\ ____/_/ /_/\\ __,_/_/_/ /_/ "
5050 echo -e " ${NC} "
51- echo -e " ${BOLD}${YELLOW} Push Node Manager v1 .0.0${NC} "
51+ echo -e " ${BOLD}${YELLOW} Push Node Manager v2 .0.0${NC} "
5252 echo -e " ${GREEN} ═══════════════════════════════${NC} "
5353 echo
5454}
6565 DOCKER_COMPOSE=" docker-compose"
6666fi
6767
68+ # Update detection functions
69+ check_for_updates () {
70+ # Cache file for GitHub API responses (to avoid rate limiting)
71+ local CACHE_FILE=" /tmp/push_node_manager_update_check"
72+ local CACHE_DURATION=3600 # 1 hour
73+ local CURRENT_TIME=$( date +%s)
74+
75+ # Check if cache is still valid
76+ if [ -f " $CACHE_FILE " ]; then
77+ local CACHE_TIME=$( stat -f %m " $CACHE_FILE " 2> /dev/null || stat -c %Y " $CACHE_FILE " 2> /dev/null || echo " 0" )
78+ local CACHE_AGE=$(( CURRENT_TIME - CACHE_TIME))
79+
80+ if [ $CACHE_AGE -lt $CACHE_DURATION ]; then
81+ # Use cached result
82+ cat " $CACHE_FILE " 2> /dev/null || echo " "
83+ return 0
84+ fi
85+ fi
86+
87+ # Fetch latest release from GitHub API
88+ local LATEST_RELEASE=$( curl -s --connect-timeout 10 \
89+ " https://api.github.com/repos/pushchain/push-chain-node/releases/latest" 2> /dev/null)
90+
91+ if [ -n " $LATEST_RELEASE " ] && echo " $LATEST_RELEASE " | grep -q ' "tag_name"' ; then
92+ echo " $LATEST_RELEASE " > " $CACHE_FILE "
93+ echo " $LATEST_RELEASE "
94+ else
95+ # Return empty if failed
96+ echo " "
97+ fi
98+ }
99+
100+ get_latest_version () {
101+ local RELEASE_DATA=$( check_for_updates)
102+ if [ -n " $RELEASE_DATA " ]; then
103+ echo " $RELEASE_DATA " | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' || echo " "
104+ else
105+ echo " "
106+ fi
107+ }
108+
109+ get_current_binary_version () {
110+ # Try to get version from the binary if it's running
111+ if $DOCKER_COMPOSE ps | grep -q " push-node-manager.*Up" ; then
112+ local VERSION=$( $DOCKER_COMPOSE exec -T validator pchaind version --long 2> /dev/null | \
113+ grep " version:" | awk ' {print $2}' 2> /dev/null || echo " " )
114+
115+ if [ -n " $VERSION " ] && [ " $VERSION " != " null" ]; then
116+ echo " $VERSION "
117+ else
118+ echo " unknown"
119+ fi
120+ else
121+ echo " unknown"
122+ fi
123+ }
124+
125+ compare_versions () {
126+ local CURRENT=" $1 "
127+ local LATEST=" $2 "
128+
129+ # If we can't determine versions, assume update needed
130+ if [ -z " $CURRENT " ] || [ " $CURRENT " = " unknown" ] || [ -z " $LATEST " ]; then
131+ return 1 # Update available (unknown state)
132+ fi
133+
134+ # Simple string comparison for now (works for semantic versions)
135+ if [ " $CURRENT " != " $LATEST " ]; then
136+ return 0 # Update available
137+ else
138+ return 1 # No update needed
139+ fi
140+ }
141+
142+ check_and_notify_updates () {
143+ local LATEST_VERSION=$( get_latest_version)
144+ local CURRENT_VERSION=$( get_current_binary_version)
145+
146+ if [ -n " $LATEST_VERSION " ] && compare_versions " $CURRENT_VERSION " " $LATEST_VERSION " ; then
147+ echo
148+ print_warning " 📦 Update Available!"
149+ echo -e " Current: ${YELLOW} $CURRENT_VERSION ${NC} "
150+ echo -e " Latest: ${GREEN} $LATEST_VERSION ${NC} "
151+ echo
152+ echo -e " Run ${BOLD}${GREEN} './push-node-manager update'${NC} to update"
153+ if [ " ${AUTO_UPDATE:- false} " != " true" ]; then
154+ echo -e " Or set ${BOLD} AUTO_UPDATE=true${NC} in .env for automatic updates"
155+ fi
156+ echo
157+ return 0 # Update available
158+ fi
159+ return 1 # No update available
160+ }
161+
162+ perform_auto_update () {
163+ local LATEST_VERSION=$( get_latest_version)
164+ local CURRENT_VERSION=$( get_current_binary_version)
165+
166+ if [ -n " $LATEST_VERSION " ] && compare_versions " $CURRENT_VERSION " " $LATEST_VERSION " ; then
167+ print_status " 🔄 Auto-updating to $LATEST_VERSION ..."
168+
169+ # Check if validator is actively validating (has voting power)
170+ if $DOCKER_COMPOSE ps | grep -q " push-node-manager.*Up" ; then
171+ local VOTING_POWER=$( $DOCKER_COMPOSE exec -T validator pchaind status --home /root/.pchain 2> /dev/null | \
172+ jq -r ' .validator_info.voting_power // "0"' 2> /dev/null || echo " 0" )
173+
174+ if [ " $VOTING_POWER " != " 0" ] && [ " $VOTING_POWER " != " null" ]; then
175+ print_warning " ⚠️ Validator is actively validating (voting power: $VOTING_POWER )"
176+ echo " Skipping auto-update to avoid disruption."
177+ echo " Run './push-node-manager update' manually when ready."
178+ return 1
179+ fi
180+ fi
181+
182+ # Perform the update
183+ print_status " 🔨 Rebuilding image with latest binary..."
184+ $DOCKER_COMPOSE build --no-cache --quiet || {
185+ print_error " ❌ Auto-update failed!"
186+ echo " Try running './push-node-manager update' manually."
187+ return 1
188+ }
189+
190+ print_success " ✅ Auto-update complete!"
191+ echo " Using binary version: $LATEST_VERSION "
192+ return 0
193+ fi
194+ return 1 # No update needed
195+ }
68196
69197# Show banner for interactive commands (not for status checks)
70198case " $1 " in
@@ -85,8 +213,16 @@ case "$1" in
85213 exit 0
86214 fi
87215
216+ # Check for auto-update if enabled
217+ if [ " ${AUTO_UPDATE:- false} " = " true" ]; then
218+ print_status " 🔍 Checking for updates (AUTO_UPDATE=true)..."
219+ if perform_auto_update; then
220+ print_status " Continuing with startup using updated binary..."
221+ fi
222+ fi
223+
88224 # Build image if needed
89- if ! docker images | grep -q " push-node-manager.*local " ; then
225+ if ! docker images | grep -q " push-node-manager" ; then
90226 print_status " 🔨 Building validator image..."
91227 $DOCKER_COMPOSE build
92228 fi
@@ -355,6 +491,9 @@ case "$1" in
355491 echo -e " ${GREEN} •${NC} Getting tokens from the faucet"
356492 echo -e " ${GREEN} •${NC} Registering as a validator"
357493 fi
494+
495+ # Check for available updates
496+ check_and_notify_updates
358497 ;;
359498
360499 logs)
@@ -498,9 +637,31 @@ case "$1" in
498637
499638 update)
500639 print_status " 🔄 Updating validator..."
640+ echo " This will:"
641+ echo " • Pull latest scripts and configuration"
642+ echo " • Download latest pchaind binary from GitHub releases"
643+ echo " • Rebuild the validator image"
644+ echo
645+
646+ read -p " Continue with update? (yes/no): " confirm
647+ if [[ ! " $confirm " =~ ^[Yy][Ee][Ss]$ ]]; then
648+ echo " Update cancelled"
649+ exit 0
650+ fi
651+
652+ # Pull latest repository changes
653+ print_status " 📥 Updating repository..."
501654 git pull
502- $DOCKER_COMPOSE pull
503- print_success " ✅ Update complete. Restart validator to apply changes."
655+
656+ # Rebuild image with latest binary
657+ print_status " 🔨 Rebuilding image with latest binary..."
658+ $DOCKER_COMPOSE build --no-cache
659+
660+ print_success " ✅ Update complete!"
661+ echo
662+ echo " Next steps:"
663+ echo " • Restart validator: ./push-node-manager restart"
664+ echo " • Check status: ./push-node-manager status"
504665 ;;
505666
506667 validators|list-validators)
@@ -1070,7 +1231,7 @@ $(echo -e "${BOLD}${GREEN}Wallet & Keys:${NC}")
10701231$( echo -e " ${BOLD}${GREEN} Maintenance:${NC} " )
10711232 reset-data Reset blockchain data (keeps wallets)
10721233 reset-all $( echo -e " ${RED} DANGER:${NC} " ) Complete reset - deletes EVERYTHING!
1073- update Update node software to latest version
1234+ update Update node software to latest version (or set AUTO_UPDATE=true)
10741235 public-setup Setup HTTPS endpoints for public access (Linux only)
10751236 help Show this help message
10761237
@@ -1095,6 +1256,11 @@ $(echo -e "${BOLD}Wallet Management:${NC}")
10951256 ./push-node-manager keys show mykey # Show address for 'mykey'
10961257 ./push-node-manager backup # Backup your keys
10971258
1259+ $( echo -e " ${BOLD} Updates:${NC} " )
1260+ ./push-node-manager update # Manual update (default)
1261+ echo "AUTO_UPDATE=true" >> .env # Enable automatic updates
1262+ ./push-node-manager start # Auto-updates if enabled
1263+
10981264$( echo -e " ${BOLD} Troubleshooting:${NC} " )
10991265 ./push-node-manager test # Run health checks
11001266 ./push-node-manager reset-data # Reset blockchain data
0 commit comments