2024-10-09 11:43:21 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-10-09 11:49:38 +00:00
|
|
|
|
# 定义服务名称和文件路径
|
|
|
|
|
SERVICE_NAME="nexus"
|
2024-10-09 12:14:31 +00:00
|
|
|
|
SERVICE_FILE="/etc/systemd/system/nexus.service" # 更新服务文件路径
|
2024-10-09 11:49:38 +00:00
|
|
|
|
|
2024-10-09 12:54:44 +00:00
|
|
|
|
# 脚本保存路径
|
|
|
|
|
SCRIPT_PATH="$HOME/nexus.sh"
|
|
|
|
|
|
|
|
|
|
# 检查是否以root用户运行脚本
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "此脚本需要以root用户权限运行。"
|
|
|
|
|
echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 主菜单函数
|
|
|
|
|
function main_menu() {
|
|
|
|
|
while true; do
|
|
|
|
|
clear
|
|
|
|
|
echo "脚本由大赌社区哈哈哈哈编写,推特 @ferdie_jhovie,免费开源,请勿相信收费"
|
|
|
|
|
echo "如有问题,可联系推特,仅此只有一个号"
|
|
|
|
|
echo "新建了一个电报群,方便大家交流:t.me/Sdohua"
|
|
|
|
|
echo "================================================================"
|
|
|
|
|
echo "退出脚本,请按键盘 ctrl + C 退出即可"
|
|
|
|
|
echo "请选择要执行的操作:"
|
|
|
|
|
echo "1. 启动节点"
|
|
|
|
|
echo "2. 查看 Prover 状态"
|
|
|
|
|
echo "3. 查看日志"
|
|
|
|
|
echo "4. 删除节点"
|
2024-10-09 12:02:23 +00:00
|
|
|
|
echo "5. 显示 ID" # 新增选项
|
2024-10-11 01:26:21 +00:00
|
|
|
|
echo "6) 退出"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
|
2024-10-09 15:09:07 +00:00
|
|
|
|
read -p "请输入选项 (1-7): " choice
|
2024-10-09 11:43:21 +00:00
|
|
|
|
|
|
|
|
|
case $choice in
|
|
|
|
|
1)
|
|
|
|
|
start_node # 调用启动节点函数
|
|
|
|
|
;;
|
|
|
|
|
2)
|
|
|
|
|
check_prover_status # 调用查看 Prover 状态函数
|
|
|
|
|
;;
|
|
|
|
|
3)
|
|
|
|
|
view_logs # 调用查看日志函数
|
|
|
|
|
;;
|
|
|
|
|
4)
|
|
|
|
|
delete_node # 调用删除节点函数
|
|
|
|
|
;;
|
|
|
|
|
5)
|
2024-10-09 12:02:23 +00:00
|
|
|
|
show_id # 调用显示 ID 函数
|
|
|
|
|
;;
|
|
|
|
|
6)
|
2024-10-09 15:09:07 +00:00
|
|
|
|
echo "退出脚本。"
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
2024-10-09 11:43:21 +00:00
|
|
|
|
*)
|
|
|
|
|
echo "无效选项,请重新选择。"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 12:02:23 +00:00
|
|
|
|
# 显示 ID 的函数
|
|
|
|
|
function show_id() {
|
|
|
|
|
if [ -f /root/.nexus/prover-id ]; then
|
|
|
|
|
echo "Prover ID 内容:"
|
2024-10-09 12:03:21 +00:00
|
|
|
|
echo "$(</root/.nexus/prover-id)" # 使用 echo 显示文件内容
|
2024-10-09 12:02:23 +00:00
|
|
|
|
else
|
|
|
|
|
echo "文件 /root/.nexus/prover-id 不存在。"
|
|
|
|
|
fi
|
2024-10-09 12:04:23 +00:00
|
|
|
|
|
2024-10-09 12:06:36 +00:00
|
|
|
|
# 等待用户按任意键返回主菜单
|
|
|
|
|
read -p "按任意键返回主菜单"
|
2024-10-09 12:02:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 启动节点的函数
|
|
|
|
|
function start_node() {
|
2024-10-11 01:26:21 +00:00
|
|
|
|
# 检查服务是否正在运行
|
|
|
|
|
if systemctl is-active --quiet nexus.service; then
|
|
|
|
|
echo "nexus.service 当前正在运行。正在停止并禁用它..."
|
|
|
|
|
sudo systemctl stop nexus.service
|
|
|
|
|
sudo systemctl disable nexus.service
|
|
|
|
|
else
|
|
|
|
|
echo "nexus.service 当前未运行。"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 12:49:37 +00:00
|
|
|
|
# 确保目录存在
|
|
|
|
|
mkdir -p /root/.nexus # 创建目录(如果不存在)
|
2024-10-11 02:11:01 +00:00
|
|
|
|
|
|
|
|
|
# 更新系统并安装必要的软件包
|
|
|
|
|
echo "更新系统并安装必要的软件包..."
|
2024-10-27 13:08:11 +00:00
|
|
|
|
if ! sudo apt update && sudo apt upgrade -y && sudo apt install curl iptables git wget lz4 jq make gcc nano automake autoconf tmux htop nvme-cli pkg-config libssl-dev libleveldb-dev tar clang bsdmainutils ncdu unzip -y; then
|
2024-10-13 08:15:58 +00:00
|
|
|
|
echo "安装软件包失败。" # 错误信息
|
|
|
|
|
exit 1
|
2024-10-11 02:11:01 +00:00
|
|
|
|
fi
|
2024-10-13 08:15:58 +00:00
|
|
|
|
|
2024-10-27 13:08:11 +00:00
|
|
|
|
# 单独安装 build-essential
|
|
|
|
|
if ! sudo apt install build-essential -y; then
|
|
|
|
|
echo "安装 build-essential 失败。" # 错误信息
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 检查并安装 Git
|
|
|
|
|
if ! command -v git &> /dev/null; then
|
|
|
|
|
echo "Git 未安装。正在安装 Git..."
|
|
|
|
|
if ! sudo apt install git -y; then
|
|
|
|
|
echo "安装 Git 失败。" # 错误信息
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "Git 已安装。" # 成功信息
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查 Rust 是否已安装
|
2024-10-11 01:52:40 +00:00
|
|
|
|
if command -v rustc &> /dev/null; then
|
|
|
|
|
echo "Rust 已安装,版本为: $(rustc --version)"
|
|
|
|
|
else
|
|
|
|
|
echo "Rust 未安装,正在安装 Rust..."
|
|
|
|
|
# 使用 rustup 安装 Rust
|
|
|
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
|
|
|
echo "Rust 安装完成。"
|
|
|
|
|
|
|
|
|
|
# 加载 Rust 环境
|
|
|
|
|
source $HOME/.cargo/env
|
2024-10-11 02:12:45 +00:00
|
|
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
2024-10-11 01:52:40 +00:00
|
|
|
|
echo "Rust 环境已加载。"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2024-10-11 01:44:44 +00:00
|
|
|
|
if [ -d "$HOME/network-api" ]; then
|
|
|
|
|
show "正在删除现有的仓库..." "progress"
|
|
|
|
|
rm -rf "$HOME/network-api"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 克隆指定的 GitHub 仓库
|
|
|
|
|
echo "正在克隆仓库..."
|
2024-10-11 01:37:46 +00:00
|
|
|
|
cd
|
2024-10-09 11:43:21 +00:00
|
|
|
|
git clone https://github.com/nexus-xyz/network-api.git
|
|
|
|
|
|
|
|
|
|
# 安装依赖项
|
|
|
|
|
cd $HOME/network-api/clients/cli
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "安装所需的依赖项..."
|
2024-10-09 11:43:21 +00:00
|
|
|
|
if ! sudo apt install pkg-config libssl-dev -y; then
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "安装依赖项失败。" # 错误信息
|
2024-10-09 11:43:21 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-10-11 01:26:21 +00:00
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 创建 systemd 服务文件
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "创建 systemd 服务..."
|
2024-10-09 11:43:21 +00:00
|
|
|
|
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
|
2024-10-11 07:14:30 +00:00
|
|
|
|
Environment=PATH=/root/.cargo/bin:$PATH
|
2024-10-09 11:43:21 +00:00
|
|
|
|
ExecStart=$HOME/.cargo/bin/cargo run --release --bin prover -- beta.orchestrator.nexus.xyz
|
|
|
|
|
Restart=always
|
|
|
|
|
RestartSec=10
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
EOF"; then
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "创建 systemd 服务文件失败。"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 重新加载 systemd 并启动服务
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "重新加载 systemd 并启动服务..."
|
2024-10-09 11:43:21 +00:00
|
|
|
|
if ! sudo systemctl daemon-reload; then
|
2024-10-09 12:14:31 +00:00
|
|
|
|
echo "重新加载 systemd 失败。"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 12:14:31 +00:00
|
|
|
|
if ! sudo systemctl start nexus.service; then
|
|
|
|
|
echo "启动服务失败。"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-09 12:14:31 +00:00
|
|
|
|
if ! sudo systemctl enable nexus.service; then
|
|
|
|
|
echo "启用服务失败。"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "节点启动成功!"
|
2024-10-09 12:06:36 +00:00
|
|
|
|
|
|
|
|
|
# 等待用户按任意键返回主菜单
|
|
|
|
|
read -p "按任意键返回主菜单"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查看 Prover 状态的函数
|
|
|
|
|
function check_prover_status() {
|
|
|
|
|
echo "查看 Prover 状态..."
|
2024-10-09 12:14:31 +00:00
|
|
|
|
systemctl status nexus.service
|
2024-10-09 11:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查看日志的函数
|
|
|
|
|
function view_logs() {
|
|
|
|
|
echo "查看 Prover 日志..."
|
2024-10-09 12:14:31 +00:00
|
|
|
|
journalctl -u nexus.service -f -n 50
|
2024-10-09 11:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 删除节点的函数
|
|
|
|
|
function delete_node() {
|
|
|
|
|
echo "正在删除节点..."
|
2024-10-09 12:14:31 +00:00
|
|
|
|
sudo systemctl stop nexus.service
|
|
|
|
|
sudo systemctl disable nexus.service
|
2024-10-11 01:30:57 +00:00
|
|
|
|
rm -rf /root/network-api
|
2024-10-11 01:35:31 +00:00
|
|
|
|
rm -rf /etc/systemd/system/nexus.service
|
2024-10-09 11:43:21 +00:00
|
|
|
|
echo "成功删除节点,按任意键返回主菜单。"
|
2024-10-09 12:06:36 +00:00
|
|
|
|
|
|
|
|
|
# 等待用户按任意键返回主菜单
|
|
|
|
|
read -p "按任意键返回主菜单"
|
2024-10-09 11:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 15:06:09 +00:00
|
|
|
|
# 显示状态的函数
|
|
|
|
|
function show_status() {
|
|
|
|
|
echo "\$1"
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 11:43:21 +00:00
|
|
|
|
# 调用主菜单函数
|
|
|
|
|
main_menu
|