@@ -18,6 +18,8 @@ dashboard_version="v3.1"
18
18
19
19
# 0: do not reinstall, 1: reinstall
20
20
reinstall=0
21
+ # 0: do not upgrade, 1: upgrade
22
+ upgrade=0
21
23
# 0: must be root or sudo, 1: regular unprivileged user
22
24
unprivileged=0
23
25
# url to the config file
@@ -49,6 +51,7 @@ function print_usage {
49
51
printf " --config <Url> Specify a url to the config file\n"
50
52
printf " --base <Path> Specify a path to the gaianet base directory\n"
51
53
printf " --reinstall Install and download all required deps\n"
54
+ printf " --upgrade Upgrade the gaianet node\n"
52
55
printf " --tmpdir <Path> Specify a path to the temporary directory [default: /tmp]\n"
53
56
printf " --ggmlcuda [11/12] Install a specific CUDA enabled GGML plugin version [Possible values: 11, 12].\n"
54
57
# printf " --unprivileged: install the gaianet CLI tool into base directory instead of system directory\n"
@@ -74,6 +77,10 @@ while [[ $# -gt 0 ]]; do
74
77
reinstall=1
75
78
shift
76
79
;;
80
+ --upgrade)
81
+ upgrade=1
82
+ shift
83
+ ;;
77
84
--tmpdir)
78
85
tmp_dir=" $2 "
79
86
shift
@@ -151,10 +158,86 @@ EOF
151
158
152
159
printf " \n\n"
153
160
154
- # if need to reinstall, remove the $gaianet_base_dir directory
155
- if [ " $reinstall " -eq 1 ] && [ -d " $gaianet_base_dir " ]; then
156
- printf " [+] Removing the existing $gaianet_base_dir directory ...\n\n"
157
- rm -rf $gaianet_base_dir
161
+ # If need to upgrade, remove the all existing files and subdirectories in the base directory, except for the backup subdirectory and its contents
162
+ # If need to reinstall, remove the $gaianet_base_dir directory
163
+ if [ -d " $gaianet_base_dir " ]; then
164
+ if [ " $upgrade " -eq 1 ]; then
165
+
166
+ # check version
167
+ if ! command -v gaianet & > /dev/null; then
168
+ current_version=" "
169
+ else
170
+ current_version=$( gaianet --version)
171
+ fi
172
+
173
+ if [ -n " $current_version " ] && [ " GaiaNet CLI Tool v$version " = " $current_version " ]; then
174
+ info " The current version ($current_version ) is the same as the target version (GaiaNet CLI Tool v$version ). Skip the upgrade process."
175
+ exit 0
176
+
177
+ else
178
+ read -p " The gaianet node will be upgraded to v$version . It is stongly recommended to (1) STOP the running node and (2) backup $gaianet_base_dir directory before continue the upgrade process. Continue? (y/n): " answer
179
+ case $answer in
180
+ [Yy]* ) printf " \n" ;;
181
+ [Nn]* ) printf " Exiting upgrade process.\n" ; exit ;;
182
+ * ) printf " Please answer y or n.\n" ; exit ;;
183
+ esac
184
+ fi
185
+
186
+ printf " [+] Performing backup before upgrading to v$version ...\n\n"
187
+
188
+ if [ ! -d " $gaianet_base_dir /backup" ]; then
189
+ printf " * Create $gaianet_base_dir /backup\n"
190
+ mkdir -p " $gaianet_base_dir /backup"
191
+ fi
192
+
193
+ # backup keystore file
194
+ keystore_filename=$( grep ' "keystore":' $gaianet_base_dir /nodeid.json | awk -F' "' ' {print $4}' )
195
+ if [ -z " $keystore_filename " ]; then
196
+ error " Failed to read the 'keystore' field from $gaianet_base_dir /nodeid.json."
197
+ exit 1
198
+ else
199
+ if [ -f " $gaianet_base_dir /$keystore_filename " ]; then
200
+ printf " * Copy $keystore_filename to $gaianet_base_dir /backup/\n"
201
+ cp $gaianet_base_dir /$keystore_filename $gaianet_base_dir /backup/
202
+ else
203
+ error " Failed to copy the keystore file. Reason: the keystore file does not exist in $gaianet_base_dir ."
204
+ exit 1
205
+ fi
206
+ fi
207
+ # backup config.json
208
+ if [ -f " $gaianet_base_dir /config.json" ]; then
209
+ printf " * Copy config.json to $gaianet_base_dir /backup/\n"
210
+ cp $gaianet_base_dir /config.json $gaianet_base_dir /backup/
211
+ else
212
+ error " Failed to copy the config.json. Reason: the config.json does not exist in $gaianet_base_dir ."
213
+ exit 1
214
+ fi
215
+ # backup nodeid.json
216
+ if [ -f " $gaianet_base_dir /nodeid.json" ]; then
217
+ printf " * Copy nodeid.json to $gaianet_base_dir /backup/\n"
218
+ cp $gaianet_base_dir /nodeid.json $gaianet_base_dir /backup/
219
+ else
220
+ error " Failed to copy the nodeid.json. Reason: the nodeid.json does not exist in $gaianet_base_dir ."
221
+ exit 1
222
+ fi
223
+ # backup frpc.toml
224
+ if [ -f " $gaianet_base_dir /gaianet-domain/frpc.toml" ]; then
225
+ printf " * Copy frpc.toml to $gaianet_base_dir /backup/\n"
226
+ cp $gaianet_base_dir /gaianet-domain/frpc.toml $gaianet_base_dir /backup/
227
+ else
228
+ error " Failed to copy the frpc.toml. Reason: the frpc.toml does not exist in $gaianet_base_dir /gaianet-domain."
229
+ exit 1
230
+ fi
231
+
232
+ # remove the all existing files and subdirectories in the base directory, except for the backup subdirectory and its contents
233
+ find " $gaianet_base_dir " -mindepth 1 -not -name ' backup' -not -path ' */backup/*' -not -name ' *.gguf' -exec rm -rf {} +
234
+
235
+ printf " \n"
236
+
237
+ elif [ " $reinstall " -eq 1 ]; then
238
+ printf " [+] Removing the existing $gaianet_base_dir directory ...\n\n"
239
+ rm -rf $gaianet_base_dir
240
+ fi
158
241
fi
159
242
160
243
# Check if $gaianet_base_dir directory exists
@@ -184,21 +267,78 @@ chmod u+x $bin_dir/gaianet
184
267
info " * gaianet CLI tool is installed in $bin_dir "
185
268
186
269
# 2. Download default `config.json`
187
- printf " [+] Downloading default config file ...\n"
188
- if [ ! -f " $gaianet_base_dir /config.json" ]; then
189
- check_curl https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /config.json $gaianet_base_dir /config.json
270
+ if [ " $upgrade " -eq 1 ]; then
271
+ printf " [+] Recovering config.json ...\n"
272
+
273
+ if [ -f " $gaianet_base_dir /backup/config.json" ]; then
274
+ cp $gaianet_base_dir /backup/config.json $gaianet_base_dir /config.json
275
+
276
+ if ! grep -q ' "chat_batch_size":' $gaianet_base_dir /config.json; then
277
+ # Prepend the field to the beginning of the JSON object
278
+ if [ " $( uname) " == " Darwin" ]; then
279
+ sed -i ' ' ' 2i\
280
+ "chat_batch_size": "512",
281
+ ' " $gaianet_base_dir /config.json"
282
+
283
+ elif [ " $( expr substr $( uname -s) 1 5) " == " Linux" ]; then
284
+ sed -i ' 2i\
285
+ "chat_batch_size": "512",
286
+ ' " $gaianet_base_dir /config.json"
287
+
288
+ elif [ " $( expr substr $( uname -s) 1 10) " == " MINGW32_NT" ]; then
289
+ error " * For Windows users, please run this script in WSL."
290
+ exit 1
291
+ else
292
+ error " * Only support Linux, MacOS and Windows."
293
+ exit 1
294
+ fi
295
+ fi
296
+
297
+ if ! grep -q ' "embedding_batch_size":' $gaianet_base_dir /config.json; then
298
+ # Prepend the field to the beginning of the JSON object
299
+ if [ " $( uname) " == " Darwin" ]; then
300
+ sed -i ' ' ' 2i\
301
+ "embedding_batch_size": "512",
302
+ ' " $gaianet_base_dir /config.json"
303
+
304
+ elif [ " $( expr substr $( uname -s) 1 5) " == " Linux" ]; then
305
+ sed -i ' 2i\
306
+ "embedding_batch_size": "512",
307
+ ' " $gaianet_base_dir /config.json"
308
+
309
+ elif [ " $( expr substr $( uname -s) 1 10) " == " MINGW32_NT" ]; then
310
+ error " * For Windows users, please run this script in WSL."
311
+ exit 1
312
+ else
313
+ error " * Only support Linux, MacOS and Windows."
314
+ exit 1
315
+ fi
316
+ fi
317
+
318
+ info " * The config.json is recovered in $gaianet_base_dir "
319
+ else
320
+ error " * Failed to recover the config.json. Reason: the config.json does not exist in $gaianet_base_dir /backup/."
321
+ exit 1
322
+ fi
190
323
191
- info " * The default config file is downloaded in $gaianet_base_dir "
192
324
else
193
- warning " * Use the cached config file in $gaianet_base_dir "
194
- fi
325
+ printf " [+] Downloading default config.json ...\n"
326
+
327
+ if [ ! -f " $gaianet_base_dir /config.json" ]; then
328
+ check_curl https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /config.json $gaianet_base_dir /config.json
195
329
196
- # 3. download nodeid.json
197
- if [ ! -f " $gaianet_base_dir /nodeid.json" ]; then
198
- printf " [+] Downloading nodeid.json ...\n"
199
- check_curl https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /nodeid.json $gaianet_base_dir /nodeid.json
330
+ info " * The default config file is downloaded in $gaianet_base_dir "
331
+ else
332
+ warning " * Use the cached config file in $gaianet_base_dir "
333
+ fi
334
+
335
+ # 3. download nodeid.json
336
+ if [ ! -f " $gaianet_base_dir /nodeid.json" ]; then
337
+ printf " [+] Downloading nodeid.json ...\n"
338
+ check_curl https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /nodeid.json $gaianet_base_dir /nodeid.json
200
339
201
- info " * The nodeid.json is downloaded in $gaianet_base_dir "
340
+ info " * The nodeid.json is downloaded in $gaianet_base_dir "
341
+ fi
202
342
fi
203
343
204
344
# 4. Install vector and download vector config file
@@ -380,21 +520,45 @@ else
380
520
warning " * Use the cached dashboard in $gaianet_base_dir "
381
521
fi
382
522
383
- # 9. Generate node ID and copy config to dashboard
384
- printf " [+] Generating node ID ...\n"
523
+ # 9. Download registry.wasm
385
524
if [ ! -f " $gaianet_base_dir /registry.wasm" ] || [ " $reinstall " -eq 1 ]; then
386
- printf " * Download registry.wasm\n"
525
+ printf " [+] Downloading registry.wasm ... \n"
387
526
check_curl https://github.com/GaiaNet-AI/gaianet-node/raw/main/utils/registry/registry.wasm $gaianet_base_dir /registry.wasm
388
- info " The registry.wasm is downloaded in $gaianet_base_dir "
527
+ info " * The registry.wasm is downloaded in $gaianet_base_dir "
389
528
else
390
529
warning " * Use the cached registry.wasm in $gaianet_base_dir "
391
530
fi
392
- printf " * Generate node ID\n"
393
- cd $gaianet_base_dir
394
- wasmedge --dir .:. registry.wasm
395
- printf " \n"
396
531
397
- # 10. Install gaianet-domain
532
+ # 10. Generate node ID
533
+ if [ " $upgrade " -eq 1 ]; then
534
+ printf " [+] Recovering node ID ...\n"
535
+
536
+ # recover the keystore file
537
+ if [ -f " $gaianet_base_dir /backup/$keystore_filename " ]; then
538
+ cp $gaianet_base_dir /backup/$keystore_filename $gaianet_base_dir /
539
+ info " * The keystore file is recovered in $gaianet_base_dir "
540
+ else
541
+ error " Failed to recover the keystore file. Reason: the keystore file does not exist in $gaianet_base_dir /backup/."
542
+ exit 1
543
+ fi
544
+
545
+ # recover the nodeid.json
546
+ if [ -f " $gaianet_base_dir /backup/nodeid.json" ]; then
547
+ cp $gaianet_base_dir /backup/nodeid.json $gaianet_base_dir /nodeid.json
548
+ info " * The node ID is recovered in $gaianet_base_dir "
549
+ else
550
+ error " Failed to recover the node ID. Reason: the nodeid.json does not exist in $gaianet_base_dir /backup/."
551
+ exit 1
552
+ fi
553
+
554
+ else
555
+ printf " [+] Generating node ID ...\n"
556
+ cd $gaianet_base_dir
557
+ wasmedge --dir .:. registry.wasm
558
+ printf " \n"
559
+ fi
560
+
561
+ # 11. Install gaianet-domain
398
562
printf " [+] Installing gaianet-domain...\n"
399
563
# Check if the directory exists, if not, create it
400
564
if [ ! -d " $gaianet_base_dir /gaianet-domain" ]; then
@@ -452,17 +616,27 @@ else
452
616
exit 1
453
617
fi
454
618
455
- # Copy frpc from $gaianet_base_dir/gaianet-domain to $gaianet_base_dir/bin
619
+ # Copy frpc binary from $gaianet_base_dir/gaianet-domain to $gaianet_base_dir/bin
456
620
printf " * Install frpc binary\n"
457
621
cp $gaianet_base_dir /gaianet-domain/frpc $gaianet_base_dir /bin/
458
622
info " frpc binary is installed in $gaianet_base_dir /bin"
459
623
460
- # 11. Download frpc.toml, generate a subdomain and print it
461
- printf " * Download frpc.toml\n"
462
-
463
- check_curl_silent https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /frpc.toml $gaianet_base_dir /gaianet-domain/frpc.toml
464
-
465
- info " frpc.toml is downloaded in $gaianet_base_dir /gaianet-domain"
624
+ # 12. Download frpc.toml, generate a subdomain and print it
625
+ if [ " $upgrade " -eq 1 ]; then
626
+ # recover the frpc.toml
627
+ if [ -f " $gaianet_base_dir /backup/frpc.toml" ]; then
628
+ printf " * Recover frpc.toml\n"
629
+ cp $gaianet_base_dir /backup/frpc.toml $gaianet_base_dir /gaianet-domain/frpc.toml
630
+ info " frpc.toml is recovered in $gaianet_base_dir /gaianet-domain"
631
+ else
632
+ error " Failed to recover the frpc.toml. Reason: the frpc.toml does not exist in $gaianet_base_dir /backup/."
633
+ exit 1
634
+ fi
635
+ else
636
+ printf " * Download frpc.toml\n"
637
+ check_curl_silent https://github.com/GaiaNet-AI/gaianet-node/releases/download/$version /frpc.toml $gaianet_base_dir /gaianet-domain/frpc.toml
638
+ info " frpc.toml is downloaded in $gaianet_base_dir /gaianet-domain"
639
+ fi
466
640
467
641
# Read address from config.json as node subdomain
468
642
subdomain=$( awk -F' "' ' /"address":/ {print $4}' $gaianet_base_dir /config.json)
@@ -495,48 +669,56 @@ $sed_i_cmd "s/name = \".*\"/name = \"$subdomain.$gaianet_domain\"/g" $gaianet_ba
495
669
$sed_i_cmd " s/metadatas.deviceId = \" .*\" /metadatas.deviceId = \" $device_id \" /g" $gaianet_base_dir /gaianet-domain/frpc.toml
496
670
497
671
# Remove all files in the directory except for frpc and frpc.toml
498
- find $gaianet_base_dir /gaianet-domain -type f -not -name ' frpc' -not -name ' frpc .toml' -exec rm -f {} \;
672
+ find $gaianet_base_dir /gaianet-domain -type f -not -name ' frpc.toml' -exec rm -f {} \;
499
673
500
- printf " [+] COMPLETED! The gaianet node has been installed successfully.\n\n "
674
+ if [ " $upgrade " -eq 1 ] ; then
501
675
502
- info " Your node ID is $subdomain . Please register it in your portal account to receive awards! "
676
+ printf " [+] COMPLETED! The gaianet node has been upgraded to v $version .\n\n "
503
677
504
- # Command to append
505
- cmd=" export PATH=\" $bin_dir :\$ PATH\" "
678
+ info " >>> Next, you should run the command 'gaianet init' to initialize the GaiaNet node."
506
679
507
- shell= " ${SHELL # ${SHELL %/* } / } "
508
- shell_rc= " . " " $shell " " rc "
680
+ else
681
+ printf " [+] COMPLETED! The gaianet node has been installed successfully.\n\n "
509
682
510
- # Check if the shell is zsh or bash
511
- if [[ $shell == * ' zsh' * ]]; then
512
- # If zsh, append to .zprofile
513
- if ! grep -Fxq " $cmd " $HOME /.zprofile
514
- then
515
- echo " $cmd " >> $HOME /.zprofile
516
- fi
683
+ info " Your node ID is $subdomain . Please register it in your portal account to receive awards!"
517
684
518
- # If zsh, append to .zshrc
519
- if ! grep -Fxq " $cmd " $HOME /.zshrc
520
- then
521
- echo " $cmd " >> $HOME /.zshrc
522
- fi
685
+ # Command to append
686
+ cmd=" export PATH=\" $bin_dir :\$ PATH\" "
523
687
524
- elif [[ $shell == * ' bash' * ]]; then
688
+ shell=" ${SHELL# ${SHELL%/* } / } "
689
+ shell_rc=" ." " $shell " " rc"
525
690
526
- # If bash, append to .bash_profile
527
- if ! grep -Fxq " $cmd " $HOME /.bash_profile
528
- then
529
- echo " $cmd " >> $HOME /.bash_profile
530
- fi
691
+ # Check if the shell is zsh or bash
692
+ if [[ $shell == * ' zsh' * ]]; then
693
+ # If zsh, append to .zprofile
694
+ if ! grep -Fxq " $cmd " $HOME /.zprofile
695
+ then
696
+ echo " $cmd " >> $HOME /.zprofile
697
+ fi
698
+
699
+ # If zsh, append to .zshrc
700
+ if ! grep -Fxq " $cmd " $HOME /.zshrc
701
+ then
702
+ echo " $cmd " >> $HOME /.zshrc
703
+ fi
531
704
532
- # If bash, append to .bashrc
533
- if ! grep -Fxq " $cmd " $HOME /.bashrc
534
- then
535
- echo " $cmd " >> $HOME /.bashrc
705
+ elif [[ $shell == * ' bash' * ]]; then
706
+
707
+ # If bash, append to .bash_profile
708
+ if ! grep -Fxq " $cmd " $HOME /.bash_profile
709
+ then
710
+ echo " $cmd " >> $HOME /.bash_profile
711
+ fi
712
+
713
+ # If bash, append to .bashrc
714
+ if ! grep -Fxq " $cmd " $HOME /.bashrc
715
+ then
716
+ echo " $cmd " >> $HOME /.bashrc
717
+ fi
536
718
fi
537
- fi
538
719
539
- info " >>> Next, you should initialize the GaiaNet node with the LLM and knowledge base. To initialize the GaiaNet node, you need to\n>>> * Run the command 'source $HOME /$shell_rc ' to make the gaianet CLI tool available in the current shell;\n>>> * Run the command 'gaianet init' to initialize the GaiaNet node."
720
+ info " >>> Next, you should initialize the GaiaNet node with the LLM and knowledge base. To initialize the GaiaNet node, you need to\n>>> * Run the command 'source $HOME /$shell_rc ' to make the gaianet CLI tool available in the current shell;\n>>> * Run the command 'gaianet init' to initialize the GaiaNet node."
540
721
722
+ fi
541
723
542
724
exit 0
0 commit comments