forked from phucbmt/tech
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun.sh
More file actions
91 lines (81 loc) · 3.71 KB
/
run.sh
File metadata and controls
91 lines (81 loc) · 3.71 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
#!/bin/sh
# -----------------------------------------------------------------------------
# 1) Ensure Rust is installed.
# - First, check if rustc is available. If not, install Rust non-interactively
# using the official rustup script.
# -----------------------------------------------------------------------------
rustc --version || curl https://sh.rustup.rs -sSf | sh
# -----------------------------------------------------------------------------
# 2) Define environment variables and colors for terminal output.
# -----------------------------------------------------------------------------
NEXUS_HOME="/root/.nexus"
GREEN='\033[1;32m'
ORANGE='\033[1;33m'
NC='\033[0m' # No Color
# Ensure the $NEXUS_HOME directory exists.
[ -d "$NEXUS_HOME" ] || mkdir -p "$NEXUS_HOME"
# -----------------------------------------------------------------------------
# 3) Display a message if we're interactive (NONINTERACTIVE is not set) and the
# $NODE_ID is not a 28-character ID. This is for Testnet II info.
# -----------------------------------------------------------------------------
if [ -z "$NONINTERACTIVE" ] && [ "${#NODE_ID}" -ne "28" ]; then
echo ""
echo "${ORANGE}The Nexus network is currently in Testnet II. You can now earn Nexus Points.${NC}"
echo ""
fi
# -----------------------------------------------------------------------------
# 4) Prompt the user to agree to the Nexus Beta Terms of Use if we're in an
# interactive mode (i.e., NONINTERACTIVE is not set) and no node-id file exists.
# We explicitly read from /dev/tty to ensure user input is requested from the
# terminal rather than the script's standard input.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# 5) Check for 'git' availability. If not found, prompt the user to install it.
# -----------------------------------------------------------------------------
git --version 2>&1 >/dev/null
GIT_IS_AVAILABLE=$?
if [ "$GIT_IS_AVAILABLE" != 0 ]; then
echo "Unable to find git. Please install it and try again."
exit 1
fi
# -----------------------------------------------------------------------------
# 6) Clone or update the network-api repository in $NEXUS_HOME.
# -----------------------------------------------------------------------------
REPO_PATH="$NEXUS_HOME/network-api"
if [ -d "$REPO_PATH" ]; then
echo "$REPO_PATH exists. Updating."
(
cd "$REPO_PATH" || exit
git stash
git fetch --tags
)
else
(
cd "$NEXUS_HOME" || exit
git clone https://github.com/ddao2604/network-api
)
fi
# -----------------------------------------------------------------------------
# 7) Check out the latest tagged commit in the repository.
# -----------------------------------------------------------------------------
(
cd "$REPO_PATH" || exit
git -c advice.detachedHead=false checkout "$(git rev-list --tags --max-count=1)"
)
# -----------------------------------------------------------------------------
# 8) Finally, run the Rust CLI in interactive mode. We explicitly attach
# /dev/tty to cargo's stdin so it can prompt the user, even if the script
# itself was piped in or otherwise redirected.
# -----------------------------------------------------------------------------
(
cd "$REPO_PATH/clients/cli" || exit
cargo run -r -- start --env beta >> log.txt
)
# -----------------------------------------------------------------------------
# For local testing (e.g., staging mode), comment out the above cargo run line
# and uncomment the line below.
#
# echo "Current location: $(pwd)"
# (cd clients/cli && cargo run -r -- start --env beta
# )
# -----------------------------------------------------------------------------