Skip to content

Commit eeb0278

Browse files
authored
Bugfix: Nym node CLI download nym-node exception (#6058)
* dowloand nym-node script fix * ready for review * ready for review * fix landing page flow * fix landing page flow
1 parent 8d28016 commit eeb0278

File tree

2 files changed

+151
-18
lines changed

2 files changed

+151
-18
lines changed

scripts/nym-node-setup/nym-node-install.sh

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
echo -e "\n* * * Ensuring ~/nym-binaries exists * * *"
55
mkdir -p "$HOME/nym-binaries"
66

7-
# Load env.sh via absolute path if provided, else try ./env.sh
7+
# load env.sh via absolute path if provided, else try ./env.sh
88
if [[ -n "${ENV_FILE:-}" && -f "${ENV_FILE}" ]]; then
99
set -a
1010
# shellcheck disable=SC1090
@@ -55,6 +55,121 @@ check_existing_config() {
5555
# run the check before any initialization
5656
check_existing_config
5757

58+
# downloader for nym-node: probes platform-specific assets; if none exist,
59+
# asks user for a direct downloadable URL and validates it.
60+
download_nym_node() {
61+
local latest_tag_url="$1" # e.g. "https://github.com/nymtech/nym/releases/tag/nym-binaries-v2025.13-emmental"
62+
local dest_path="$2" # e.g. "$HOME/nym-binaries/nym-node"
63+
local base_download_url
64+
local os arch exe_ext=""
65+
local candidates=()
66+
local found_url=""
67+
local http_code=""
68+
69+
if [[ -z "$latest_tag_url" || "$latest_tag_url" != *"/releases/tag/"* ]]; then
70+
echo "ERROR: Invalid latest tag URL: $latest_tag_url" >&2
71+
return 1
72+
fi
73+
74+
base_download_url="${latest_tag_url/tag/download}"
75+
76+
# detect OS / ARCH
77+
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
78+
linux*) os="linux" ;;
79+
darwin*) os="darwin" ;;
80+
msys*|cygwin*|mingw*) os="windows"; exe_ext=".exe" ;;
81+
*) echo "WARNING: Unknown OS; defaulting to linux." ; os="linux" ;;
82+
esac
83+
84+
case "$(uname -m)" in
85+
x86_64|amd64) arch="x86_64" ;;
86+
aarch64|arm64) arch="aarch64" ;;
87+
armv7*|armv6*|armv5*) arch="arm" ;;
88+
*) arch="$(uname -m)";;
89+
esac
90+
91+
# candidate asset names to probe (no assumptions about compression)
92+
if [[ "$os" == "linux" ]]; then
93+
candidates+=(
94+
"nym-node"
95+
"nym-node-${arch}-unknown-linux-gnu"
96+
"nym-node-${arch}-unknown-linux-musl"
97+
)
98+
elif [[ "$os" == "darwin" ]]; then
99+
candidates+=(
100+
"nym-node-${arch}-apple-darwin"
101+
"nym-node"
102+
)
103+
elif [[ "$os" == "windows" ]]; then
104+
candidates+=(
105+
"nym-node-${arch}-pc-windows-msvc${exe_ext}"
106+
"nym-node${exe_ext}"
107+
)
108+
fi
109+
110+
# return 0 if URL exists (HTTP 200)
111+
url_exists() {
112+
local url="$1"
113+
http_code="$(curl -sI -L -o /dev/null -w '%{http_code}' "$url")"
114+
[[ "$http_code" == "200" ]]
115+
}
116+
117+
echo -e "\n* * * Probing release assets for your platform ($os/$arch) * * *"
118+
119+
# try candidate assets in order
120+
for name in "${candidates[@]}"; do
121+
local try_url="${base_download_url}/${name}"
122+
if url_exists "$try_url"; then
123+
found_url="$try_url"
124+
break
125+
fi
126+
done
127+
128+
# if nothing found, prompt the user for a URL
129+
if [[ -z "$found_url" ]]; then
130+
echo
131+
echo "Could not find a 'nym-node' asset for your platform in the latest release:"
132+
echo " $latest_tag_url"
133+
echo
134+
echo "HTTP check for first candidate (${base_download_url}/${candidates[0]}): ${http_code:-n/a}"
135+
echo
136+
echo "Please paste a direct, downloadable URL for the 'nym-node' binary for your platform."
137+
echo "Tip: Open the GitHub release page, right-click the correct asset, and copy link address."
138+
read -r -p "Custom download URL: " user_url
139+
140+
if [[ -z "${user_url// }" ]]; then
141+
echo "ERROR: No URL provided. Aborting."
142+
return 1
143+
fi
144+
if ! url_exists "$user_url"; then
145+
echo "ERROR: The provided URL does not appear downloadable (HTTP $http_code). Aborting."
146+
return 1
147+
fi
148+
found_url="$user_url"
149+
fi
150+
151+
echo -e "\n* * * Downloading nym-node from: $found_url * * *"
152+
mkdir -p "$(dirname "$dest_path")"
153+
154+
# remove any existing file to avoid 'text file busy'
155+
if [[ -e "$dest_path" ]]; then
156+
echo "Removing existing binary at $dest_path ..."
157+
rm -f "$dest_path"
158+
fi
159+
160+
if ! curl -fL "$found_url" -o "$dest_path"; then
161+
echo "ERROR: Download failed from $found_url" >&2
162+
return 1
163+
fi
164+
165+
chmod +x "$dest_path" 2>/dev/null || true
166+
167+
echo "---------------------------------------------------"
168+
echo "Nym node binary downloaded to: $dest_path"
169+
"$dest_path" --version || true
170+
echo "---------------------------------------------------"
171+
}
172+
58173
echo -e "\n* * * Resolving latest release tag URL * * *"
59174
LATEST_TAG_URL="$(curl -sI -L -o /dev/null -w '%{url_effective}' https://github.com/nymtech/nym/releases/latest)"
60175
# expected example: https://github.com/nymtech/nym/releases/tag/nym-binaries-v2025.13-emmental
@@ -64,7 +179,6 @@ if [[ -z "${LATEST_TAG_URL}" || "${LATEST_TAG_URL}" != *"/releases/tag/"* ]]; th
64179
exit 1
65180
fi
66181

67-
DOWNLOAD_URL="${LATEST_TAG_URL/tag/download}/nym-node"
68182
NYM_NODE="$HOME/nym-binaries/nym-node"
69183

70184
# if binary already exists, ask to overwrite; if yes, remove first
@@ -80,12 +194,7 @@ if [[ -e "${NYM_NODE}" ]]; then
80194
fi
81195
fi
82196

83-
echo -e "\n* * * Downloading nym-node from:"
84-
echo " ${DOWNLOAD_URL}"
85-
# only download if file is missing (or we just removed it)
86-
if [[ ! -e "${NYM_NODE}" ]]; then
87-
curl -fL "${DOWNLOAD_URL}" -o "${NYM_NODE}"
88-
fi
197+
download_nym_node "$LATEST_TAG_URL" "$NYM_NODE"
89198

90199
echo -e "\n * * * Making binary executable * * *"
91200
chmod +x "${NYM_NODE}"
@@ -95,7 +204,7 @@ echo "Nym node binary downloaded:"
95204
"${NYM_NODE}" --version || true
96205
echo "---------------------------------------------------"
97206

98-
# check that MODE is set (after sourcing env.sh)
207+
# check that MODE is set (after sourcing env.sh or other scripts)
99208
if [[ -z "${MODE:-}" ]]; then
100209
echo "ERROR: Environment variable MODE is not set."
101210
echo "Please export MODE as one of: mixnode, entry-gateway, exit-gateway"

scripts/nym-node-setup/setup-nginx-proxy-wss.sh

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export SYSTEMD_COLORS="0"
1616
DEBIAN_FRONTEND=noninteractive
1717

1818
# sanity check
19-
if [[ "${HOSTNAME}" == "localhost" || "${HOSTNAME}" == "127.0.0.1" ]]; then
19+
if [[ "${HOSTNAME}" == "localhost" || "${HOSTNAME}" == "127.0.0.1" || "${HOSTNAME}" == "ubuntu" ]]; then
2020
echo "ERROR: HOSTNAME cannot be 'localhost'. Use a public FQDN." >&2
2121
exit 1
2222
fi
@@ -64,7 +64,7 @@ cert_ok() {
6464
}
6565

6666
fetch_landing_html() {
67-
local url="https://raw.githubusercontent.com/nymtech/nym/refs/heads/feature/node-setup-cli/scripts/nym-node-setup/landing-page.html"
67+
local url="https://raw.githubusercontent.com/nymtech/nym/refs/heads/develop/scripts/nym-node-setup/landing-page.html"
6868
mkdir -p "${WEBROOT}"
6969

7070
if command -v curl >/dev/null 2>&1; then
@@ -99,21 +99,45 @@ fetch_landing_html() {
9999
<p>This is a Nym Exit Gateway. The operator of this router has no access to any of the data routing through that due to encryption design.</p>
100100
</body>
101101
</html>
102-
HTML
103-
104102
HTML
105103
fi
106104
}
107105

108106
inject_email() {
109-
if [[ -n "${EMAIL:-}" ]]; then
110-
sed -i "s|<meta name=\"contact:email\" content=\"[^\"]*\"|<meta name=\"contact:email\" content=\"${EMAIL}\"|" \
111-
"${WEBROOT}/index.html"
107+
local file="${WEBROOT}/index.html"
108+
[[ -n "${EMAIL:-}" && -s "$file" ]] || return 0
109+
110+
# Escape characters that would break sed replacement
111+
local esc_email
112+
esc_email="$(printf '%s' "$EMAIL" | sed -e 's/[&/\]/\\&/g')"
113+
114+
# try to update existing meta (case-insensitive on the name attr)
115+
if grep -qiE '<meta[^>]+name=["'"'"']contact:email["'"'"']' "$file"; then
116+
sed -i -E \
117+
"s|(<meta[^>]+name=[\"']contact:email[\"'][^>]*content=\")[^\"]*(\"[^>]*>)|\1${esc_email}\2|I" \
118+
"$file" || true
119+
return 0
112120
fi
121+
122+
# insert before </head> if present (case-insensitive)
123+
if grep -qi '</head>' "$file"; then
124+
awk -v email="$EMAIL" '
125+
BEGIN{IGNORECASE=1}
126+
/<\/head>/ && !done {
127+
print " <meta name=\"contact:email\" content=\"" email "\">"
128+
done=1
129+
}
130+
{ print }
131+
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
132+
return 0
133+
fi
134+
135+
# fallback: append at end
136+
printf '\n<meta name="contact:email" content="%s">\n' "$EMAIL" >> "$file" || true
113137
}
114138

115139
fetch_logo() {
116-
local logo_url=" https://raw.githubusercontent.com/nymtech/websites/refs/heads/main/www/nym.com/public/images/Nym_meta_Image.png?token=GHSAT0AAAAAACEERII7URYRTFACZ4F2OWZ42GMCPBQ"
140+
local logo_url="https://raw.githubusercontent.com/nymtech/websites/refs/heads/main/www/nym.com/public/images/Nym_meta_Image.png?token=GHSAT0AAAAAACEERII7URYRTFACZ4F2OWZ42GMCPBQ"
117141
mkdir -p "${WEBROOT}/images"
118142
if [[ ! -s "${WEBROOT}/images/nym_logo.png" ]]; then
119143
if command -v curl >/dev/null 2>&1; then
@@ -127,7 +151,7 @@ fetch_logo() {
127151
reload_nginx() { nginx -t && systemctl reload nginx; }
128152

129153
# landing page (idempotent)
130-
fetch_landing
154+
fetch_landing_html
131155
inject_email
132156
fetch_logo
133157
echo "Landing page at ${WEBROOT}/index.html"

0 commit comments

Comments
 (0)