Update ElixirV3.sh
This commit is contained in:
parent
7aabb02362
commit
503ea5d6b8
103
ElixirV3.sh
103
ElixirV3.sh
@ -3,7 +3,6 @@
|
|||||||
# 检查是否以root用户运行脚本
|
# 检查是否以root用户运行脚本
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "此脚本需要以root用户权限运行。"
|
echo "此脚本需要以root用户权限运行。"
|
||||||
echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -26,62 +25,57 @@ function check_and_install_docker() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 节点安装功能
|
# 检查并更新Docker镜像
|
||||||
function install_node() {
|
function check_and_update_docker_image() {
|
||||||
check_and_install_docker
|
local current_version="v3.4.4" # 当前版本
|
||||||
|
local latest_version=$(curl -s https://registry.hub.docker.com/v2/repositories/elixirprotocol/validator/tags | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) # 获取最新版本
|
||||||
|
|
||||||
# 提示用户输入环境变量的值
|
if [ "$current_version" != "$latest_version" ]; then
|
||||||
read -p "请输入验证者节点设备的IP地址: " ip_address
|
echo "发现新版本 $latest_version,正在更新..."
|
||||||
read -p "请输入验证者节点的显示名称: " validator_name
|
docker pull elixirprotocol/validator:$latest_version
|
||||||
read -p "请输入验证者节点的奖励收取地址: " safe_public_address
|
echo "Docker 镜像已更新到版本 $latest_version。"
|
||||||
read -p "请输入签名者私钥,无需0x: " private_key
|
|
||||||
|
|
||||||
# 将环境变量保存到 validator.env 文件
|
# 更新当前的容器
|
||||||
cat <<EOF > validator.env
|
echo "正在更新当前的容器..."
|
||||||
ENV=testnet-3
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c --run-once elixir
|
||||||
|
|
||||||
STRATEGY_EXECUTOR_IP_ADDRESS=${ip_address}
|
|
||||||
STRATEGY_EXECUTOR_DISPLAY_NAME=${validator_name}
|
|
||||||
STRATEGY_EXECUTOR_BENEFICIARY=${safe_public_address}
|
|
||||||
SIGNER_PRIVATE_KEY=${private_key}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
echo "环境变量已设置并保存到 validator.env 文件。"
|
|
||||||
|
|
||||||
# 拉取 Docker 镜像
|
|
||||||
docker pull elixirprotocol/validator:v3
|
|
||||||
|
|
||||||
# 提示用户选择平台
|
|
||||||
read -p "您是否在Apple/ARM架构上运行?(y/n): " is_arm
|
|
||||||
|
|
||||||
if [[ "$is_arm" == "y" ]]; then
|
|
||||||
# 在Apple/ARM架构上运行
|
|
||||||
docker run -it -d \
|
|
||||||
--env-file validator.env \
|
|
||||||
--name elixir \
|
|
||||||
--platform linux/amd64 \
|
|
||||||
elixirprotocol/validator:v3
|
|
||||||
else
|
else
|
||||||
# 默认运行
|
echo "当前已是最新版本 $current_version。"
|
||||||
docker run -it -d \
|
|
||||||
--env-file validator.env \
|
|
||||||
--name elixir \
|
|
||||||
elixirprotocol/validator:v3
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 查看Docker日志功能
|
# 创建更新检查脚本
|
||||||
function check_docker_logs() {
|
function create_update_script() {
|
||||||
echo "查看Elixir Docker容器的日志..."
|
cat << 'EOF' > /usr/local/bin/check_update.sh
|
||||||
docker logs -f elixir
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 检查并更新Docker镜像
|
||||||
|
function check_and_update_docker_image() {
|
||||||
|
local current_version="v3.4.4" # 当前版本
|
||||||
|
local latest_version=$(curl -s https://registry.hub.docker.com/v2/repositories/elixirprotocol/validator/tags | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) # 获取最新版本
|
||||||
|
|
||||||
|
if [ "$current_version" != "$latest_version" ]; then
|
||||||
|
echo "发现新版本 $latest_version,正在更新..."
|
||||||
|
docker pull elixirprotocol/validator:$latest_version
|
||||||
|
echo "Docker 镜像已更新到版本 $latest_version。"
|
||||||
|
|
||||||
|
# 更新当前的容器
|
||||||
|
echo "正在更新当前的容器..."
|
||||||
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c --run-once elixir
|
||||||
|
else
|
||||||
|
echo "当前已是最新版本 $current_version。"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 删除Docker容器功能
|
# 执行更新检查
|
||||||
function delete_docker_container() {
|
check_and_update_docker_image
|
||||||
echo "删除Elixir Docker容器..."
|
EOF
|
||||||
docker stop elixir
|
|
||||||
docker rm elixir
|
chmod +x /usr/local/bin/check_update.sh
|
||||||
echo "Elixir Docker容器已删除。"
|
}
|
||||||
|
|
||||||
|
# 设置crontab
|
||||||
|
function setup_crontab() {
|
||||||
|
(crontab -l 2>/dev/null; echo "0 * * * * /usr/local/bin/check_update.sh >> /var/log/check_update.log 2>&1") | crontab -
|
||||||
}
|
}
|
||||||
|
|
||||||
# 主菜单
|
# 主菜单
|
||||||
@ -89,19 +83,22 @@ function main_menu() {
|
|||||||
clear
|
clear
|
||||||
echo "脚本以及教程由推特用户大赌哥 @y95277777 编写,免费开源,请勿相信收费"
|
echo "脚本以及教程由推特用户大赌哥 @y95277777 编写,免费开源,请勿相信收费"
|
||||||
echo "=====================Elixir V3节点安装========================="
|
echo "=====================Elixir V3节点安装========================="
|
||||||
echo "节点社区 Telegram 群组:https://t.me/niuwuriji"
|
|
||||||
echo "节点社区 Telegram 频道:https://t.me/niuwuriji"
|
|
||||||
echo "节点社区 Discord 社群:https://discord.gg/GbMV5EcNWF"
|
|
||||||
echo "请选择要执行的操作:"
|
echo "请选择要执行的操作:"
|
||||||
echo "1. 安装Elixir V3节点"
|
echo "1. 安装Elixir V3节点"
|
||||||
echo "2. 查看Docker日志"
|
echo "2. 查看Docker日志"
|
||||||
echo "3. 删除Elixir Docker容器"
|
echo "3. 删除Elixir Docker容器"
|
||||||
read -p "请输入选项(1-3): " OPTION
|
echo "4. 启用自动更新"
|
||||||
|
read -p "请输入选项(1-4): " OPTION
|
||||||
|
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
1) install_node ;;
|
1) install_node ;;
|
||||||
2) check_docker_logs ;;
|
2) check_docker_logs ;;
|
||||||
3) delete_docker_container ;;
|
3) delete_docker_container ;;
|
||||||
|
4)
|
||||||
|
create_update_script
|
||||||
|
setup_crontab
|
||||||
|
echo "自动更新检查已设置。"
|
||||||
|
;;
|
||||||
*) echo "无效选项。" ;;
|
*) echo "无效选项。" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user