2024-03-15 10:31:28 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-03-18 08:46:50 +00:00
|
|
|
|
# 检查是否以root用户运行脚本
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "此脚本需要以root用户权限运行。"
|
2024-03-18 10:12:21 +00:00
|
|
|
|
echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。"
|
2024-03-18 08:46:50 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-03-15 10:38:39 +00:00
|
|
|
|
echo "脚本以及教程由推特用户大赌哥 @y95277777 编写,免费开源,请勿相信收费"
|
|
|
|
|
echo "================================================================"
|
|
|
|
|
echo "节点社区 Telegram 群组:https://t.me/niuwuriji"
|
|
|
|
|
echo "节点社区 Telegram 频道:https://t.me/niuwuriji"
|
2024-03-15 10:31:28 +00:00
|
|
|
|
|
|
|
|
|
# 读取加载身份码信息
|
|
|
|
|
read -p "输入你的身份码: " id
|
|
|
|
|
|
2024-03-18 08:46:50 +00:00
|
|
|
|
# 让用户输入想要创建的容器数量
|
2024-03-18 10:49:55 +00:00
|
|
|
|
read -p "请输入你想要创建的节点数量,单IP限制最多5个节点: " container_count
|
2024-03-18 08:20:48 +00:00
|
|
|
|
|
2024-03-24 16:24:38 +00:00
|
|
|
|
# 让用户输入想要分配的空间大小
|
2024-03-24 16:42:11 +00:00
|
|
|
|
read -p "请输入你想要分配每个节点的存储空间大小(GB): " storage_gb
|
2024-03-24 16:24:38 +00:00
|
|
|
|
|
2024-03-15 10:31:28 +00:00
|
|
|
|
apt update
|
|
|
|
|
|
|
|
|
|
# 检查 Docker 是否已安装
|
|
|
|
|
if ! command -v docker &> /dev/null
|
|
|
|
|
then
|
|
|
|
|
echo "未检测到 Docker,正在安装..."
|
2024-03-18 09:15:55 +00:00
|
|
|
|
apt-get install ca-certificates curl gnupg lsb-release
|
2024-03-17 08:04:41 +00:00
|
|
|
|
|
2024-03-15 10:31:28 +00:00
|
|
|
|
# 安装 Docker 最新版本
|
2024-03-18 09:15:55 +00:00
|
|
|
|
apt-get install docker.io -y
|
2024-03-15 10:31:28 +00:00
|
|
|
|
else
|
|
|
|
|
echo "Docker 已安装。"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 拉取Docker镜像
|
2024-03-24 16:24:38 +00:00
|
|
|
|
docker pull nezha123/titan-edge
|
2024-03-15 10:31:28 +00:00
|
|
|
|
|
2024-03-18 08:46:50 +00:00
|
|
|
|
|
2024-03-18 08:20:48 +00:00
|
|
|
|
# 创建用户指定数量的容器
|
|
|
|
|
for i in $(seq 1 $container_count)
|
2024-03-15 10:31:28 +00:00
|
|
|
|
do
|
|
|
|
|
# 为每个容器创建一个存储卷
|
|
|
|
|
storage="titan_storage_$i"
|
|
|
|
|
mkdir -p "$storage"
|
2024-03-24 16:24:38 +00:00
|
|
|
|
# 检查 ~/.titanedge 目录是否存在,如果不存在,则创建它
|
|
|
|
|
if [ ! -d "$HOME/.titanedge" ]; then
|
|
|
|
|
mkdir "$HOME/.titanedge"
|
|
|
|
|
fi
|
2024-03-15 10:31:28 +00:00
|
|
|
|
|
|
|
|
|
# 运行容器,并设置重启策略为always
|
2024-03-24 16:24:38 +00:00
|
|
|
|
container_id=$(docker run -d --restart always -v "$PWD/$storage:/root/.titanedge/storage" --name "titan$i" nezha123/titan-edge)
|
2024-03-15 10:31:28 +00:00
|
|
|
|
|
2024-03-19 03:51:33 +00:00
|
|
|
|
echo "节点 titan$i 已经启动 容器ID $container_id"
|
2024-03-15 10:31:28 +00:00
|
|
|
|
|
2024-03-19 03:51:33 +00:00
|
|
|
|
sleep 30
|
2024-03-16 04:17:10 +00:00
|
|
|
|
|
2024-03-15 10:31:28 +00:00
|
|
|
|
# 进入容器并执行绑定和其他命令
|
|
|
|
|
docker exec -it $container_id bash -c "\
|
|
|
|
|
titan-edge bind --hash=$id https://api-test1.container1.titannet.io/api/v2/device/binding"
|
|
|
|
|
done
|
|
|
|
|
|
2024-03-24 16:24:38 +00:00
|
|
|
|
# 等待足够时间以确保所有容器都已启动并且config.toml文件已经生成
|
|
|
|
|
echo "等待所有容器启动并生成配置文件..."
|
|
|
|
|
sleep 60
|
|
|
|
|
|
|
|
|
|
# 修改宿主机上的config.toml文件以设置StorageGB值
|
|
|
|
|
config_path="$HOME/.titanedge/config.toml"
|
|
|
|
|
if [ -f "$config_path" ]; then
|
2024-03-24 16:40:51 +00:00
|
|
|
|
sed -i '/StorageGB =/c\ StorageGB = '$storage_gb'' "$config_path"
|
2024-03-24 16:24:38 +00:00
|
|
|
|
echo "已将存储空间设置为 $storage_gb GB"
|
|
|
|
|
else
|
|
|
|
|
echo "配置文件未找到,可能需要手动设置StorageGB。请检查容器是否正确启动并生成了配置文件。"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2024-03-24 16:40:51 +00:00
|
|
|
|
|
2024-03-19 03:51:33 +00:00
|
|
|
|
echo "==============================所有节点均已设置并启动===================================."
|