forked from zunxbt/nexus-prover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nexus.sh
118 lines (97 loc) · 2.92 KB
/
nexus.sh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
curl -s https://raw.githubusercontent.com/zunxbt/logo/main/logo.sh | bash
sleep 5
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
PINK='\033[1;35m'
show() {
case $2 in
"error")
echo -e "${PINK}${BOLD}❌ $1${NORMAL}"
;;
"progress")
echo -e "${PINK}${BOLD}⏳ $1${NORMAL}"
;;
*)
echo -e "${PINK}${BOLD}✅ $1${NORMAL}"
;;
esac
}
SERVICE_NAME="nexus"
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
show "Installing Rust..." "progress"
if ! source <(wget -O - https://raw.githubusercontent.com/zunxbt/installation/main/rust.sh); then
show "Failed to install Rust." "error"
exit 1
fi
show "Updating package list..." "progress"
if ! sudo apt update; then
show "Failed to update package list." "error"
exit 1
fi
if ! command -v git &> /dev/null; then
show "Git is not installed. Installing git..." "progress"
if ! sudo apt install git -y; then
show "Failed to install git." "error"
exit 1
fi
else
show "Git is already installed."
fi
if [ -d "$HOME/network-api" ]; then
show "Deleting existing repository..." "progress"
rm -rf "$HOME/network-api"
fi
sleep 3
show "Cloning Nexus-XYZ network API repository..." "progress"
if ! git clone https://github.com/nexus-xyz/network-api.git "$HOME/network-api"; then
show "Failed to clone the repository." "error"
exit 1
fi
cd $HOME/network-api/clients/cli
show "Installing required dependencies..." "progress"
if ! sudo apt install pkg-config libssl-dev protobuf-compiler -y; then
show "Failed to install dependencies." "error"
exit 1
fi
if systemctl is-active --quiet nexus.service; then
show "nexus.service is currently running. Stopping and disabling it..."
sudo systemctl stop nexus.service
sudo systemctl disable nexus.service
else
show "nexus.service is not running."
fi
show "Creating systemd service..." "progress"
if ! sudo bash -c "cat > $SERVICE_FILE <<EOF
[Unit]
Description=Nexus XYZ Prover Service
After=network.target
[Service]
User=$USER
WorkingDirectory=$HOME/network-api/clients/cli
Environment=NONINTERACTIVE=1
ExecStart=$HOME/.cargo/bin/cargo run --release --bin prover -- beta.orchestrator.nexus.xyz
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF"; then
show "Failed to create the systemd service file." "error"
exit 1
fi
show "Reloading systemd and starting the service..." "progress"
if ! sudo systemctl daemon-reload; then
show "Failed to reload systemd." "error"
exit 1
fi
if ! sudo systemctl start $SERVICE_NAME.service; then
show "Failed to start the service." "error"
exit 1
fi
if ! sudo systemctl enable $SERVICE_NAME.service; then
show "Failed to enable the service." "error"
exit 1
fi
show "Nexus Prover installation and service setup complete!"
show "You can check Nexus Prover logs using this command : journalctl -u nexus.service -fn 50"
echo