-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·118 lines (98 loc) · 3.67 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·118 lines (98 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# Check GitHub for a newer Teranode release, bump TERANODE_VERSION in .env.
set -eo pipefail
USAGE=$(cat <<'EOF'
Usage: ./update.sh [flags]
Check GitHub for a newer Teranode release, bump TERANODE_VERSION in .env,
print next steps. (Use ./start.sh afterwards to pull and recreate services.)
Flags:
--check Dry-run: show current vs latest, exit without changing .env
--to <tag> Pin to a specific tag (downgrade or forward-pin)
--yes Non-interactive: accept the prompt
-h, --help Show this help and exit
EOF
)
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$REPO_ROOT"
source "${REPO_ROOT}/lib/colors.sh"
source "${REPO_ROOT}/lib/github_release.sh"
if [ ! -f .env ]; then
echo_error ".env not found. Run ./setup.sh first."
exit 1
fi
CHECK=0
AUTO_YES=0
PIN_TAG=""
while [ $# -gt 0 ]; do
case "$1" in
--check) CHECK=1 ;;
--to) PIN_TAG="$2"; shift ;;
--yes) AUTO_YES=1 ;;
-h|--help) echo "$USAGE"; exit 0 ;;
*) echo_error "Unknown flag: $1"; echo "$USAGE" >&2; exit 2 ;;
esac
shift
done
set -a
# shellcheck disable=SC1091
source .env
set +a
CURRENT="${TERANODE_VERSION:-unknown}"
# Strip whitespace / CR (defends against hand-edits, Windows line endings).
CURRENT="${CURRENT//[[:space:]]/}"
if [ -n "$PIN_TAG" ]; then
TARGET="$PIN_TAG"
echo_info "Pinning to user-specified tag: $TARGET"
else
echo_info "Checking github.com/bsv-blockchain/teranode for latest release..."
TARGET=$(latest_release_tag)
if [ -z "$TARGET" ]; then
echo_error "Failed to query GitHub Releases API."
exit 1
fi
fi
echo ""
echo_white "Current: $CURRENT"
echo_white "Target: $TARGET"
echo_white "Release: $(release_html_url "$TARGET")"
echo ""
if versions_equal "$CURRENT" "$TARGET"; then
echo_success "Already on $TARGET. Nothing to do."
exit 0
fi
if [ "$CHECK" -eq 1 ]; then
echo_info "--check: not modifying .env or pulling images."
exit 0
fi
if [ "$AUTO_YES" -ne 1 ]; then
read -r -p "Apply update? [y/N]: " ans
[[ "$ans" =~ ^[Yy] ]] || { echo_warning "Aborted."; exit 0; }
fi
"${REPO_ROOT}/lib/env_writer.sh" .env TERANODE_VERSION "$TARGET"
echo_success "Set TERANODE_VERSION=$TARGET in .env (was $CURRENT)"
# Remove a stale global GOGC override (shipped by older .env.example).
# env_file injects it into every container, and teranode skips its own
# per-service GC tuning (GOMEMLIMIT-aware GOGC=100) when GOGC is set in the
# environment — under big-block load the heap then runs deferred GC straight
# into the GOMEMLIMIT ceiling.
if grep -qE '^GOGC=' .env; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/^GOGC=/d' .env
else
sed -i '/^GOGC=/d' .env
fi
echo_info "Removed GOGC override from .env — teranode auto-tunes GC per service (GOMEMLIMIT from the container cap, GOGC=100)."
fi
# Backfill per-service memory caps for .env files created before quickstart
# grew MEM_LIMIT_* support. write_mem_limits --only-missing is idempotent and
# per-key: keys the user set (or that a previous run wrote) are never touched,
# and individually deleted keys are restored.
source "${REPO_ROOT}/lib/mem_limits.sh"
NETWORK="$(grep -E '^network=' .env | head -1 | cut -d= -f2 | tr -d '\r')"
TOTAL_RAM_GB=$(detect_total_ram_gb)
write_mem_limits .env "${NETWORK:-testnet}" "$TOTAL_RAM_GB" --only-missing
echo_info "Ensured per-service MEM_LIMIT_* caps in .env (host: ${TOTAL_RAM_GB}GB; existing values untouched)."
echo ""
echo_info "Next: ./start.sh"
echo_info " (docker compose pulls the new image and recreates only the changed services;"
echo_info " running on top of an existing stack is fine — data volumes persist)"