@@ -15,13 +15,14 @@ show_help() {
1515 echo
1616 echo " Options:"
1717 echo " --execution Specify the execution method (default: service)"
18+ echo " --branch Specify the branch you want to install"
1819 echo " --neuron Specify the neuron you want to install between miner or validator (default miner)"
1920 echo " --help Show this help message"
2021 exit 0
2122}
2223
23- OPTIONS=" e:n:h"
24- LONGOPTIONS=" execution:,neurone :,help:"
24+ OPTIONS=" e:n:b: h"
25+ LONGOPTIONS=" execution:,neuron:,branch :,help:"
2526
2627# Parse the options and their arguments
2728PARSED=" $( getopt -o $OPTIONS -l $LONGOPTIONS : --name " $0 " -- " $@ " ) "
@@ -35,6 +36,7 @@ eval set -- "$PARSED"
3536# Set defaults from env (can be overridden by arguments)
3637EXECUTION=" service"
3738NEURON=" miner"
39+ BRANCH=" "
3840
3941# Parse arguments
4042while true ; do
@@ -47,6 +49,10 @@ while true; do
4749 NEURON=" $2 "
4850 shift 2
4951 ;;
52+ -b |--branch)
53+ BRANCH=" $2 "
54+ shift 2
55+ ;;
5056 -h | --help)
5157 show_help
5258 exit 0
@@ -78,6 +84,33 @@ get_version() {
7884 fi
7985}
8086
87+ stop_auto_upgrader () {
88+ echo " 🛑 Attempting to stop auto upgrader (subvortex-auto-upgrader)..."
89+
90+ # Try PM2
91+ if command -v pm2 & > /dev/null && pm2 list | grep -q " subvortex-auto-upgrader" ; then
92+ echo " ⚙️ Stopping via PM2"
93+ pm2 stop subvortex-auto-upgrader || true
94+ return
95+ fi
96+
97+ # Try systemd
98+ if systemctl list-units --type=service --all | grep -q " subvortex-auto-upgrader.service" ; then
99+ echo " ⚙️ Stopping via systemd"
100+ sudo systemctl stop subvortex-auto-upgrader.service || true
101+ return
102+ fi
103+
104+ # Try Docker
105+ if command -v docker & > /dev/null && docker ps -a --format ' {{.Names}}' | grep -q " ^subvortex-auto-upgrader$" ; then
106+ echo " ⚙️ Stopping via Docker"
107+ docker stop subvortex-auto-upgrader || true
108+ return
109+ fi
110+
111+ echo " ⚠️ Auto upgrader not running via PM2, systemd, or Docker."
112+ }
113+
81114download_and_unzip_assets () {
82115 local role=" $1 "
83116 local version=" $2 "
@@ -132,14 +165,227 @@ download_and_unzip_assets() {
132165 echo " ✅ Asset ready in: $target_dir "
133166}
134167
135- # Clean workspace?
136- " ./../cleaner/clean_worspace.sh --remove"
168+ clone_branch () {
169+ local branch=" $1 "
170+ local repo=" https://github.com/eclipsevortex/SubVortex.git"
171+ local base_dir=" /var/tmp/subvortex"
172+ local clone_dir=" ${base_dir} /subvortex-${branch} "
173+
174+ echo " 🌱 Cloning branch '$branch ' into: $clone_dir "
175+ mkdir -p " $base_dir "
176+ [[ -d " $clone_dir " ]] && rm -rf " $clone_dir "
177+
178+ git clone --branch " $branch " --depth 1 " $repo " " $clone_dir " || {
179+ echo " ❌ Failed to clone branch '$branch '"
180+ exit 1
181+ }
182+
183+ # Locate version file
184+ local version_file=" $clone_dir /VERSION"
185+ if [[ ! -f " $version_file " ]]; then
186+ echo " ❌ Error: Could not find version file in $clone_dir "
187+ exit 1
188+ fi
189+
190+ # Read and normalize version
191+ local version
192+ version=" $( < " $version_file " tr -d ' [:space:]' ) "
193+ [[ -z " $version " ]] && { echo " ❌ Error: Version file is empty" ; exit 1; }
194+
195+ local norm_version=" ${version// alpha/ a} "
196+ norm_version=" ${norm_version// -rc/ -rc} "
197+
198+ # Append branch name to directory
199+ local target_dir=" ${base_dir} /subvortex-${norm_version} -${branch} "
200+
201+ echo " 🔁 Renaming $clone_dir → $target_dir "
202+ rm -rf " $target_dir "
203+ mv " $clone_dir " " $target_dir "
204+
205+ # Optionally copy the neuron-specific pyproject.toml
206+ local py_src=" ${target_dir} /pyproject-${NEURON} .toml"
207+ local py_dst=" ${target_dir} /pyproject.toml"
208+ if [[ -f " $py_src " ]]; then
209+ echo " 📄 Copying $py_src → $py_dst "
210+ cp " $py_src " " $py_dst "
211+ else
212+ echo " ⚠️ $py_src not found, skipping pyproject.toml override"
213+ fi
214+
215+ # Set global variable for neuron path
216+ SUBVORTEX_DIR=" ${target_dir} /subvortex"
217+ echo " ✅ Branch ready in: $SUBVORTEX_DIR "
218+ }
219+
220+ copy_env_files () {
221+ local source_dir=" ./subvortex/auto_upgrader/environment"
222+ local prefix=" env.subvortex.${NEURON} ."
223+
224+ echo " 📁 Searching for env files in: $source_dir matching $prefix *"
225+ for env_file in " $source_dir " /${prefix} * ; do
226+ [[ -f " $env_file " ]] || continue
227+
228+ local filename
229+ filename=" $( basename " $env_file " ) "
230+ local component=" ${filename# $prefix } " # Extract component name
231+
232+ local target_dir=" $SUBVORTEX_DIR /$NEURON /$component "
233+ local target_path=" ${target_dir} /.env"
234+
235+ echo " 📄 Copying $filename → $target_path "
236+ mkdir -p " $target_dir "
237+ cp " $env_file " " $target_path "
238+ done
239+ }
240+
241+ get_sorted_components () {
242+ local source_dir=" ./subvortex/auto_upgrader/environment"
243+ local prefix=" env.subvortex.${NEURON} ."
244+ local components=()
245+ declare -A dependencies
246+
247+ for env_file in " $source_dir " /${prefix} * ; do
248+ [[ -f " $env_file " ]] || continue
249+ local filename=" $( basename " $env_file " ) "
250+ local component=" ${filename# $prefix } "
251+ components+=(" $component " )
252+
253+ local manifest=" $SUBVORTEX_DIR /${NEURON} /${component} /manifest.json"
254+ if [[ -f " $manifest " ]]; then
255+ local deps
256+ deps=$( jq -r ' .depends_on[]?' " $manifest " )
257+ dependencies[" $component " ]=" $deps "
258+ else
259+ dependencies[" $component " ]=" "
260+ fi
261+ done
137262
138- # Download and unzip the assets
139- VERSION=$( get_version)
140- download_and_unzip_assets " $NEURON " " $VERSION "
263+ local sorted=()
264+ declare -A visited
265+
266+ visit () {
267+ local comp=" $1 "
268+ [[ ${visited[$comp]} == 1 ]] && return
269+ visited[$comp ]=1
270+
271+ for dep in ${dependencies[$comp]} ; do
272+ local dep_name=" ${dep# ${NEURON} -} "
273+ visit " $dep_name "
274+ done
275+ sorted+=(" $comp " )
276+ }
277+
278+ for comp in " ${components[@]} " ; do
279+ visit " $comp "
280+ done
281+
282+ echo " ${sorted[@]} "
283+ }
284+
285+ setup_components () {
286+ local source_dir=" ./subvortex/auto_upgrader/environment"
287+ local prefix=" env.subvortex.${NEURON} ."
288+
289+ echo " 🛠️ Setting up components for neuron: $NEURON "
290+
291+ for env_file in " $source_dir " /${prefix} * ; do
292+ [[ -f " $env_file " ]] || continue
293+
294+ local filename
295+ filename=" $( basename " $env_file " ) "
296+ local component=" ${filename# $prefix } "
297+
298+ # Get absolute path to /var/tmp/subvortex/... repo
299+ local full_repo_path
300+ full_repo_path=" $( dirname " $SUBVORTEX_DIR " ) "
301+
302+ local script=" ${full_repo_path} /subvortex/${NEURON} /${component} /scripts/${component} _setup.sh"
303+
304+ if [[ -x " $script " ]]; then
305+ echo " ⚙️ Setting up component: $component "
306+ " $script " --execution " $EXECUTION "
307+ else
308+ echo " ⚠️ Setup script not found or not executable: $script "
309+ fi
310+ done
311+ }
312+
313+ start_components () {
314+ local sorted_components=( $( get_sorted_components) )
315+
316+ echo " 🚀 Starting components for neuron: $NEURON "
317+ for component in " ${sorted_components[@]} " ; do
318+ local script=" /root/subvortex/subvortex/${NEURON} /${component} /scripts/${component} _start.sh"
319+ if [[ -x " $script " ]]; then
320+ echo " ➡️ Starting component: $component "
321+ " $script " --execution " $EXECUTION "
322+ else
323+ echo " ⚠️ Start script not found or not executable: $script "
324+ fi
325+ done
326+ }
327+
328+ stop_components () {
329+ local sorted_components=( $( get_sorted_components) )
330+ local reversed_components=( $( for (( idx= ${# sorted_components[@]} - 1 ; idx>= 0 ; idx-- )) ; do echo " ${sorted_components[idx]} " ; done) )
331+
332+ echo " 🛑 Stopping existing components for neuron: $NEURON "
333+ for (( idx= ${# sorted_components[@]} - 1 ; idx>= 0 ; idx-- )) ; do
334+ local component=" ${sorted_components[idx]} "
335+ local script=" /root/subvortex/subvortex/${NEURON} /${component} /scripts/${component} _stop.sh"
336+ if [[ -x " $script " ]]; then
337+ echo " ➡️ Stopping component: $component "
338+ " $script " --execution " $EXECUTION "
339+ else
340+ echo " ⚠️ Stop script not found or not executable: $script "
341+ fi
342+ done
343+ }
344+
345+ # Ask the user for migration confirmation
346+ echo " ⚠️ WARNING: This script does not handle data migration between versions."
347+ echo " You are about to proceed with installation without preserving or migrating previous data."
348+ read -rp " Do you want to continue? [y/N]: " confirm
349+ if [[ ! " $confirm " =~ ^[Yy]$ ]]; then
350+ echo " ❌ Operation cancelled. Migration step must be handled manually."
351+ exit 1
352+ fi
353+
354+ # Stop auto upgader
355+ stop_auto_upgrader
356+
357+ # Download the assets or git pull a specific branch
358+ if [[ -n " $BRANCH " ]]; then
359+ # Clone the version
360+ clone_branch " $BRANCH "
361+ else
362+ # Download and unzip the assets
363+ VERSION=$( get_version)
364+ download_and_unzip_assets " $NEURON " " $VERSION "
365+ fi
141366
142367# Copy the env file
368+ copy_env_files
369+
370+ # Setup components (new version)
371+ setup_components
372+
373+ # Stop components (old version)
374+ stop_components
375+
376+ # Update or create /root/subvortex symlink
377+ echo " 🔗 Managing symlink: /root/subvortex"
378+ if [[ -L /root/subvortex || -e /root/subvortex ]]; then
379+ echo " 🔄 Updating existing symlink or file"
380+ rm -rf /root/subvortex
381+ fi
382+ ln -s " $( dirname " $SUBVORTEX_DIR " ) " /root/subvortex
383+ echo " ✅ /root/subvortex → $( readlink -f /root/subvortex) "
384+
385+ # Start component (new version)
386+ start_components
387+
388+ # TODO: implement the migration
143389
144- # Setup/Start the neuron
145- " ./ $HOME /subvortex/subvortex/ $NEURON / scripts/quick_start .sh --execution \" $EXECUTION \" "
390+ # Clean prune version
391+ ./ scripts/quick_clean .sh --workspace
0 commit comments