2024-03-01 11:26:44 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 脚本保存路径
|
|
|
|
|
SCRIPT_PATH="$HOME/Quilibrium.sh"
|
2024-03-01 11:26:44 +00:00
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 自动设置快捷键的功能
|
|
|
|
|
function check_and_set_alias() {
|
|
|
|
|
local alias_name="quili"
|
|
|
|
|
local shell_rc="$HOME/.bashrc"
|
|
|
|
|
|
|
|
|
|
# 对于Zsh用户,使用.zshrc
|
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
|
shell_rc="$HOME/.zshrc"
|
|
|
|
|
elif [ -n "$BASH_VERSION" ]; then
|
|
|
|
|
shell_rc="$HOME/.bashrc"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查快捷键是否已经设置
|
|
|
|
|
if ! grep -q "$alias_name" "$shell_rc"; then
|
|
|
|
|
echo "设置快捷键 '$alias_name' 到 $shell_rc"
|
|
|
|
|
echo "alias $alias_name='bash $SCRIPT_PATH'" >> "$shell_rc"
|
|
|
|
|
# 添加提醒用户激活快捷键的信息
|
|
|
|
|
echo "快捷键 '$alias_name' 已设置。请运行 'source $shell_rc' 来激活快捷键,或重新打开终端。"
|
|
|
|
|
else
|
|
|
|
|
# 如果快捷键已经设置,提供一个提示信息
|
|
|
|
|
echo "快捷键 '$alias_name' 已经设置在 $shell_rc。"
|
|
|
|
|
echo "如果快捷键不起作用,请尝试运行 'source $shell_rc' 或重新打开终端。"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 节点安装功能
|
|
|
|
|
function install_node() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 检查是否以root用户执行脚本
|
2024-03-01 11:26:44 +00:00
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "该脚本必须以root权限运行" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 增加swap空间
|
|
|
|
|
sudo mkdir /swap
|
|
|
|
|
sudo fallocate -l 24G /swap/swapfile
|
|
|
|
|
sudo chmod 600 /swap/swapfile
|
|
|
|
|
sudo mkswap /swap/swapfile
|
|
|
|
|
sudo swapon /swap/swapfile
|
|
|
|
|
echo '/swap/swapfile swap swap defaults 0 0' >> /etc/fstab
|
|
|
|
|
|
|
|
|
|
# 向/etc/sysctl.conf文件追加内容
|
2024-03-01 11:26:44 +00:00
|
|
|
|
echo -e "\n# 自定义最大接收和发送缓冲区大小" >> /etc/sysctl.conf
|
|
|
|
|
echo "net.core.rmem_max=600000000" >> /etc/sysctl.conf
|
|
|
|
|
echo "net.core.wmem_max=600000000" >> /etc/sysctl.conf
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
echo "配置已添加到/etc/sysctl.conf"
|
2024-03-01 11:26:44 +00:00
|
|
|
|
|
|
|
|
|
# 重新加载sysctl配置以应用更改
|
|
|
|
|
sysctl -p
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
echo "sysctl配置已重新加载"
|
2024-03-01 11:26:44 +00:00
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 更新并升级Ubuntu软件包
|
2024-03-01 11:26:44 +00:00
|
|
|
|
sudo apt update && sudo apt -y upgrade
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 安装wget、screen和git等组件
|
2024-03-02 03:27:27 +00:00
|
|
|
|
sudo apt install git ufw bison screen binutils gcc make -y
|
2024-03-01 11:26:44 +00:00
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 安装GVM
|
2024-03-01 11:26:44 +00:00
|
|
|
|
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
|
|
|
|
|
source /root/.gvm/scripts/gvm
|
|
|
|
|
|
|
|
|
|
gvm install go1.4 -B
|
|
|
|
|
gvm use go1.4
|
|
|
|
|
export GOROOT_BOOTSTRAP=$GOROOT
|
|
|
|
|
gvm install go1.17.13
|
|
|
|
|
gvm use go1.17.13
|
|
|
|
|
export GOROOT_BOOTSTRAP=$GOROOT
|
|
|
|
|
gvm install go1.20.2
|
|
|
|
|
gvm use go1.20.2
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 克隆仓库
|
2024-03-01 11:26:44 +00:00
|
|
|
|
git clone https://github.com/quilibriumnetwork/ceremonyclient
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 进入ceremonyclient/node目录
|
2024-03-01 11:26:44 +00:00
|
|
|
|
cd ceremonyclient/node
|
|
|
|
|
|
2024-03-03 05:20:12 +00:00
|
|
|
|
# 赋予执行权限
|
|
|
|
|
chmod +x poor_mans_cd.sh
|
|
|
|
|
|
|
|
|
|
# 创建一个screen会话并运行命令
|
|
|
|
|
screen -dmS Quili bash -c './poor_mans_cd.sh'
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:13:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 节点安装功能
|
|
|
|
|
function install_node_service() {
|
|
|
|
|
|
|
|
|
|
# 检查是否以root用户执行脚本
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "该脚本必须以root权限运行" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 增加swap空间
|
|
|
|
|
sudo mkdir /swap
|
|
|
|
|
sudo fallocate -l 24G /swap/swapfile
|
|
|
|
|
sudo chmod 600 /swap/swapfile
|
|
|
|
|
sudo mkswap /swap/swapfile
|
|
|
|
|
sudo swapon /swap/swapfile
|
|
|
|
|
echo '/swap/swapfile swap swap defaults 0 0' >> /etc/fstab
|
|
|
|
|
|
|
|
|
|
# 向/etc/sysctl.conf文件追加内容
|
|
|
|
|
echo -e "\n# 自定义最大接收和发送缓冲区大小" >> /etc/sysctl.conf
|
|
|
|
|
echo "net.core.rmem_max=600000000" >> /etc/sysctl.conf
|
|
|
|
|
echo "net.core.wmem_max=600000000" >> /etc/sysctl.conf
|
|
|
|
|
|
|
|
|
|
echo "配置已添加到/etc/sysctl.conf"
|
|
|
|
|
|
|
|
|
|
# 重新加载sysctl配置以应用更改
|
|
|
|
|
sysctl -p
|
|
|
|
|
|
|
|
|
|
echo "sysctl配置已重新加载"
|
|
|
|
|
|
|
|
|
|
# 更新并升级Ubuntu软件包
|
|
|
|
|
sudo apt update && sudo apt -y upgrade
|
|
|
|
|
|
|
|
|
|
# 安装wget、screen和git等组件
|
|
|
|
|
sudo apt install git ufw bison screen binutils gcc make -y
|
|
|
|
|
|
|
|
|
|
# 安装GVM
|
|
|
|
|
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
|
|
|
|
|
source /root/.gvm/scripts/gvm
|
|
|
|
|
|
|
|
|
|
gvm install go1.4 -B
|
|
|
|
|
gvm use go1.4
|
|
|
|
|
export GOROOT_BOOTSTRAP=$GOROOT
|
|
|
|
|
gvm install go1.17.13
|
|
|
|
|
gvm use go1.17.13
|
|
|
|
|
export GOROOT_BOOTSTRAP=$GOROOT
|
|
|
|
|
gvm install go1.20.2
|
|
|
|
|
gvm use go1.20.2
|
|
|
|
|
|
|
|
|
|
# 克隆仓库
|
|
|
|
|
git clone https://github.com/quilibriumnetwork/ceremonyclient
|
|
|
|
|
|
|
|
|
|
# 进入ceremonyclient/node目录
|
|
|
|
|
cd ceremonyclient/node
|
|
|
|
|
|
|
|
|
|
# 构建服务
|
|
|
|
|
GOEXPERIMENT=arenas go install ./...
|
|
|
|
|
|
|
|
|
|
# 写入服务
|
|
|
|
|
sudo tee /lib/systemd/system/ceremonyclient.service > /dev/null <<EOF
|
|
|
|
|
[Unit]
|
|
|
|
|
Description=Ceremony Client GO App Service
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
Type=simple
|
|
|
|
|
Restart=always
|
|
|
|
|
RestartSec=5S
|
|
|
|
|
WorkingDirectory=/root/ceremonyclient/node
|
|
|
|
|
Environment=GOEXPERIMENT=arenas
|
|
|
|
|
ExecStart=/root/.gvm/pkgsets/go1.20.2/global/bin/node ./...
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# 重新加载 systemd 并启用并启动服务
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
sudo systemctl enable ceremonyclient
|
|
|
|
|
sudo systemctl start ceremonyclient
|
|
|
|
|
|
|
|
|
|
# 完成安装提示
|
|
|
|
|
echo ====================================== 安装完成 =========================================
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 查看服务版本状态
|
|
|
|
|
function check_ceremonyclient_service_status() {
|
|
|
|
|
systemctl status ceremonyclient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 服务版本节点日志查询
|
|
|
|
|
function view_logs() {
|
|
|
|
|
sudo journalctl -f -u ceremonyclient.service
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查看常规版本节点日志
|
2024-03-03 05:20:12 +00:00
|
|
|
|
function check_service_status() {
|
|
|
|
|
screen -r Quili
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 主菜单
|
|
|
|
|
function main_menu() {
|
|
|
|
|
clear
|
|
|
|
|
echo "脚本以及教程由推特用户大赌哥 @y95277777 编写,免费开源,请勿相信收费"
|
|
|
|
|
echo "================================================================"
|
|
|
|
|
echo "节点社区 Telegram 群组:https://t.me/niuwuriji"
|
|
|
|
|
echo "节点社区 Telegram 频道:https://t.me/niuwuriji"
|
|
|
|
|
echo "请选择要执行的操作:"
|
2024-03-03 15:13:58 +00:00
|
|
|
|
echo "1. 安装常规节点"
|
|
|
|
|
echo "2. 查看常规版本节点日志"
|
|
|
|
|
echo "3. 安装服务版本节点"
|
|
|
|
|
echo "4. 查看服务版本节点日志"
|
|
|
|
|
echo "5. 查看服务版本服务状态"
|
|
|
|
|
echo "6. 设置快捷键的功能"
|
2024-03-03 05:20:12 +00:00
|
|
|
|
read -p "请输入选项(1-3): " OPTION
|
|
|
|
|
|
|
|
|
|
case $OPTION in
|
|
|
|
|
1) install_node ;;
|
2024-03-03 15:13:58 +00:00
|
|
|
|
2) check_service_status ;;
|
|
|
|
|
3) install_node_service ;;
|
|
|
|
|
4) view_logs ;;
|
|
|
|
|
5) check_ceremonyclient_service_status ;;
|
|
|
|
|
6) check_and_set_alias ;;
|
2024-03-03 05:20:12 +00:00
|
|
|
|
*) echo "无效选项。" ;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 显示主菜单
|
|
|
|
|
main_menu
|