@@ -4,7 +4,7 @@ set -euo pipefail
44echo -e " \n* * * Ensuring ~/nym-binaries exists * * *"
55mkdir -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
88if [[ -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
5656check_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+
58173echo -e " \n* * * Resolving latest release tag URL * * *"
59174LATEST_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
65180fi
66181
67- DOWNLOAD_URL=" ${LATEST_TAG_URL/ tag/ download} /nym-node"
68182NYM_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
81195fi
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
90199echo -e " \n * * * Making binary executable * * *"
91200chmod +x " ${NYM_NODE} "
@@ -95,7 +204,7 @@ echo "Nym node binary downloaded:"
95204" ${NYM_NODE} " --version || true
96205echo " ---------------------------------------------------"
97206
98- # check that MODE is set (after sourcing env.sh)
207+ # check that MODE is set (after sourcing env.sh or other scripts )
99208if [[ -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"
0 commit comments