mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-01-22 12:48:14 -05:00
refactorcode
This commit is contained in:
parent
f5538d300d
commit
0f81b585f1
213
deploy.sh
213
deploy.sh
@ -1,68 +1,67 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CONTAINER_NAME=myztplanet
|
|
||||||
|
|
||||||
# 如果是centos 且内核版本小于5.*,提示内核版本太低
|
CONTAINER_NAME="myztplanet"
|
||||||
|
ZEROTIER_PATH="$(pwd)/data/zerotier"
|
||||||
|
CONFIG_PATH="${ZEROTIER_PATH}/config"
|
||||||
|
DIST_PATH="${ZEROTIER_PATH}/dist"
|
||||||
|
ZTNCUI_PATH="${ZEROTIER_PATH}/ztncui"
|
||||||
|
DOCKER_IMAGE="xubiaolin/zerotier-planet:latest"
|
||||||
|
|
||||||
|
# 检查内核版本
|
||||||
kernel_check() {
|
kernel_check() {
|
||||||
os_name=$(cat /etc/os-release | grep ^ID= | cut -d'=' -f2)
|
os_name=$(grep ^ID= /etc/os-release | cut -d'=' -f2)
|
||||||
kernel_version=$(uname -r | cut -d'.' -f1)
|
kernel_version=$(uname -r | cut -d'.' -f1)
|
||||||
if [[ "$kernel_version" -lt 5 ]]; then
|
if [[ "$kernel_version" -lt 5 ]]; then
|
||||||
if [[ "$os_name" == "\"centos\"" ]]; then
|
if [[ "$os_name" == "\"centos\"" ]]; then
|
||||||
echo -e "\033[31m内核版本太低,请在菜单中选择CentOS内核升级\033[0m"
|
echo -e "\033[31m内核版本太低,请在菜单中选择CentOS内核升级\033[0m"
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
echo -e "\033[31m请自行升级系统内核到5.*及其以上版本\033[0m"
|
echo -e "\033[31m请自行升级系统内核到5.*及其以上版本\033[0m"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
echo "当前内核版本为:$kernel_version"
|
echo -e "\033[32m系统和内核版本检查通过,当前内核版本为:$kernel_version\033[0m"
|
||||||
echo -e "\033[32m系统和内核版本检查通过。\033[0m"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_centos_kernal(){
|
# 升级CentOS内核
|
||||||
|
update_centos_kernel() {
|
||||||
echo "请注意备份数据,升级内核有风险"
|
echo "请注意备份数据,升级内核有风险"
|
||||||
read -p "是否继续升级内核?(y/n) " continue_update
|
read -p "是否继续升级内核?(y/n) " continue_update
|
||||||
continue_update=${continue_update:-n}
|
|
||||||
if [[ "$continue_update" =~ ^[Yy]$ ]]; then
|
if [[ "$continue_update" =~ ^[Yy]$ ]]; then
|
||||||
echo "如果配置较低,可能升级时间较长,请耐心等待!开始升级内核..."
|
echo "升级时间较长,请耐心等待!开始升级内核..."
|
||||||
yum update -y
|
yum update -y
|
||||||
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
|
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
|
||||||
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm -y
|
yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
|
||||||
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
|
yum --disablerepo="*" --enablerepo="elrepo-kernel" install -y kernel-lt-devel kernel-lt
|
||||||
yum --enablerepo=elrepo-kernel install kernel-lt-devel kernel-lt -y
|
|
||||||
sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
|
sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
|
||||||
grub2-set-default 0
|
grub2-set-default 0
|
||||||
grub2-mkconfig -o /boot/grub2/grub.cfg
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
|
||||||
read -p "内核升级完成,请重启系统,是否立刻重启?(y/n) " reboot
|
read -p "内核升级完成,请重启系统,是否立刻重启?(y/n) " reboot
|
||||||
reboot=${reboot:-n}
|
|
||||||
if [[ "$reboot" =~ ^[Yy]$ ]]; then
|
if [[ "$reboot" =~ ^[Yy]$ ]]; then
|
||||||
reboot now
|
reboot now
|
||||||
else
|
else
|
||||||
echo "已取消重启"
|
echo "已取消重启"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "内核升级完成,请重启系统"
|
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
echo "已取消升级内核"
|
echo "已取消升级内核"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 安装lsof工具
|
||||||
install_lsof() {
|
install_lsof() {
|
||||||
if [ ! -f "/usr/bin/lsof" ]; then
|
if [ ! -f "/usr/bin/lsof" ]; then
|
||||||
echo "开始安装lsof工具..."
|
echo "开始安装lsof工具..."
|
||||||
[ -f "/usr/bin/apt" ] && (
|
if [ -f "/usr/bin/apt" ]; then
|
||||||
apt update
|
apt update && apt install -y lsof
|
||||||
apt install -y lsof
|
elif [ -f "/usr/bin/yum" ]; then
|
||||||
)
|
yum install -y lsof
|
||||||
[ -f "/usr/bin/yum" ] && yum install -y lsof
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 检查端口是否被占用
|
||||||
check_port() {
|
check_port() {
|
||||||
local port=$1
|
local port=$1
|
||||||
if [ $(lsof -i:${port} | wc -l) -gt 0 ]; then
|
if [ $(lsof -i:${port} | wc -l) -gt 0 ]; then
|
||||||
@ -71,6 +70,7 @@ check_port() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 读取端口号
|
||||||
read_port() {
|
read_port() {
|
||||||
local port
|
local port
|
||||||
local prompt=$1
|
local prompt=$1
|
||||||
@ -82,21 +82,7 @@ read_port() {
|
|||||||
echo $port
|
echo $port
|
||||||
}
|
}
|
||||||
|
|
||||||
install() {
|
# 获取IP地址
|
||||||
kernel_check
|
|
||||||
|
|
||||||
echo "开始安装,如果你已经安装了,将会删除旧的数据,10s后开始安装..."
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
install_lsof
|
|
||||||
|
|
||||||
docker rm -f ${CONTAINER_NAME}
|
|
||||||
rm -rf $(pwd)/data/zerotier
|
|
||||||
|
|
||||||
ZT_PORT=$(read_port "请输入zerotier-planet要使用的端口号,例如9994: ")
|
|
||||||
API_PORT=$(read_port "请输入zerotier-planet的API端口号,例如3443: ")
|
|
||||||
FILE_PORT=$(read_port "请输入zerotier-planet的FILE端口号,例如3000: ")
|
|
||||||
|
|
||||||
configure_ip() {
|
configure_ip() {
|
||||||
ipv4=$(curl -s https://ipv4.icanhazip.com/)
|
ipv4=$(curl -s https://ipv4.icanhazip.com/)
|
||||||
ipv6=$(curl -s https://ipv6.icanhazip.com/)
|
ipv6=$(curl -s https://ipv6.icanhazip.com/)
|
||||||
@ -104,13 +90,26 @@ install() {
|
|||||||
echo "获取到的IPv6地址为: $ipv6"
|
echo "获取到的IPv6地址为: $ipv6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 安装zerotier-planet
|
||||||
|
install() {
|
||||||
|
kernel_check
|
||||||
|
|
||||||
|
echo "开始安装,如果你已经安装了,将会删除旧的数据,10秒后开始安装..."
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
install_lsof
|
||||||
|
|
||||||
|
docker rm -f ${CONTAINER_NAME} || true
|
||||||
|
rm -rf ${ZEROTIER_PATH}
|
||||||
|
|
||||||
|
ZT_PORT=$(read_port "请输入zerotier-planet要使用的端口号,例如9994: ")
|
||||||
|
API_PORT=$(read_port "请输入zerotier-planet的API端口号,例如3443: ")
|
||||||
|
FILE_PORT=$(read_port "请输入zerotier-planet的FILE端口号,例如3000: ")
|
||||||
|
|
||||||
read -p "是否自动获取公网IP地址?(y/n) " use_auto_ip
|
read -p "是否自动获取公网IP地址?(y/n) " use_auto_ip
|
||||||
use_auto_ip=${use_auto_ip:-y}
|
|
||||||
if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then
|
if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then
|
||||||
configure_ip
|
configure_ip
|
||||||
|
|
||||||
read -p "是否使用上面获取到的IP地址?(y/n) " use_auto_ip_result
|
read -p "是否使用上面获取到的IP地址?(y/n) " use_auto_ip_result
|
||||||
use_auto_ip_result=${use_auto_ip_result:-y}
|
|
||||||
if [[ "$use_auto_ip_result" =~ ^[Nn]$ ]]; then
|
if [[ "$use_auto_ip_result" =~ ^[Nn]$ ]]; then
|
||||||
read -p "请输入IPv4地址: " ipv4
|
read -p "请输入IPv4地址: " ipv4
|
||||||
read -p "请输入IPv6地址(可留空): " ipv6
|
read -p "请输入IPv6地址(可留空): " ipv6
|
||||||
@ -139,32 +138,17 @@ install() {
|
|||||||
-e ZT_PORT=${ZT_PORT} \
|
-e ZT_PORT=${ZT_PORT} \
|
||||||
-e API_PORT=${API_PORT} \
|
-e API_PORT=${API_PORT} \
|
||||||
-e FILE_SERVER_PORT=${FILE_PORT} \
|
-e FILE_SERVER_PORT=${FILE_PORT} \
|
||||||
-v $(pwd)/data/zerotier/dist:/app/dist \
|
-v ${DIST_PATH}:/app/dist \
|
||||||
-v $(pwd)/data/zerotier/ztncui:/app/ztncui \
|
-v ${ZTNCUI_PATH}:/app/ztncui \
|
||||||
-v $(pwd)/data/zerotier/one:/var/lib/zerotier-one -v $(pwd)/data/zerotier/config:/app/config --restart unless-stopped xubiaolin/zerotier-planet:latest
|
-v ${ZEROTIER_PATH}/one:/var/lib/zerotier-one \
|
||||||
|
-v ${CONFIG_PATH}:/app/config \
|
||||||
if [ $? -ne 0 ]; then
|
--restart unless-stopped \
|
||||||
echo "安装失败"
|
${DOCKER_IMAGE}
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
retrieve_keys() {
|
KEY=$(docker exec -it ${CONTAINER_NAME} sh -c 'cat /app/config/file_server.key' | tr -d '\r')
|
||||||
KEY=$(docker exec -it ${CONTAINER_NAME} sh -c 'cat /app/config/file_server.key')
|
MOON_NAME=$(docker exec -it ${CONTAINER_NAME} sh -c 'ls /app/dist | grep moon' | tr -d '\r')
|
||||||
MOON_NAME=$(docker exec -it ${CONTAINER_NAME} sh -c 'ls /app/dist | grep moon')
|
|
||||||
}
|
|
||||||
|
|
||||||
retrieve_keys
|
|
||||||
|
|
||||||
clean_vars() {
|
|
||||||
ipv4=$(echo $ipv4 | tr -d '\r')
|
|
||||||
FILE_PORT=$(echo $FILE_PORT | tr -d '\r')
|
|
||||||
KEY=$(echo $KEY | tr -d '\r')
|
|
||||||
MOON_NAME=$(echo $MOON_NAME | tr -d '\r')
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_vars
|
|
||||||
|
|
||||||
echo "安装完成"
|
echo "安装完成"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
@ -173,22 +157,17 @@ install() {
|
|||||||
echo "默认密码:password"
|
echo "默认密码:password"
|
||||||
echo "请及时修改密码"
|
echo "请及时修改密码"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
|
echo "moon配置和planet配置在 ${DIST_PATH} 目录下"
|
||||||
echo "moon配置和planet配置在 $(pwd)/data/zerotier/dist 目录下"
|
echo "moons 文件下载: http://${ipv4}:${FILE_PORT}/${MOON_NAME}?key=${KEY} "
|
||||||
echo -e "moons 文件下载: http://${ipv4}:${FILE_PORT}/${MOON_NAME}?key=${KEY} "
|
echo "planet文件下载: http://${ipv4}:${FILE_PORT}/planet?key=${KEY} "
|
||||||
echo -e "planet文件下载: http://${ipv4}:${FILE_PORT}/planet?key=${KEY} "
|
|
||||||
|
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo "请放行以下端口请:${ZT_PORT}/tcp,${ZT_PORT}/udp,${API_PORT}/tcp,${FILE_PORT}/tcp"
|
echo "请放行以下端口:${ZT_PORT}/tcp,${ZT_PORT}/udp,${API_PORT}/tcp,${FILE_PORT}/tcp"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 查看信息
|
||||||
info() {
|
info() {
|
||||||
docker inspect ${CONTAINER_NAME} >/dev/null 2>&1
|
docker inspect ${CONTAINER_NAME} >/dev/null 2>&1 || { echo "容器${CONTAINER_NAME}不存在,请先安装"; exit 1; }
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "容器${CONTAINER_NAME}不存在,请先安装"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
extract_config() {
|
extract_config() {
|
||||||
local config_name=$1
|
local config_name=$1
|
||||||
@ -201,7 +180,6 @@ info() {
|
|||||||
FILE_PORT=$(extract_config "file_server.port")
|
FILE_PORT=$(extract_config "file_server.port")
|
||||||
ZT_PORT=$(extract_config "zerotier-one.port")
|
ZT_PORT=$(extract_config "zerotier-one.port")
|
||||||
KEY=$(extract_config "file_server.key")
|
KEY=$(extract_config "file_server.key")
|
||||||
|
|
||||||
MOON_NAME=$(docker exec -it ${CONTAINER_NAME} sh -c "ls /app/dist | grep moon" | tr -d '\r')
|
MOON_NAME=$(docker exec -it ${CONTAINER_NAME} sh -c "ls /app/dist | grep moon" | tr -d '\r')
|
||||||
|
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
@ -212,82 +190,28 @@ info() {
|
|||||||
echo "默认密码:password"
|
echo "默认密码:password"
|
||||||
echo "请及时修改密码"
|
echo "请及时修改密码"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo "moon配置和planet配置在 $(pwd)/data/zerotier/dist 目录下"
|
echo "moon配置和planet配置在 ${DIST_PATH} 目录下"
|
||||||
echo ""
|
|
||||||
echo "planet文件下载: http://${ipv4}:${FILE_PORT}/planet?key=${KEY} "
|
echo "planet文件下载: http://${ipv4}:${FILE_PORT}/planet?key=${KEY} "
|
||||||
echo "moon文件下载: http://${ipv4}:${FILE_PORT}/${MOON_NAME}?key=${KEY} "
|
echo "moon文件下载: http://${ipv4}:${FILE_PORT}/${MOON_NAME}?key=${KEY} "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 卸载zerotier-planet
|
||||||
uninstall() {
|
uninstall() {
|
||||||
echo "开始卸载..."
|
echo "开始卸载..."
|
||||||
|
|
||||||
docker stop ${CONTAINER_NAME}
|
docker stop ${CONTAINER_NAME}
|
||||||
docker rm ${CONTAINER_NAME}
|
docker rm ${CONTAINER_NAME}
|
||||||
docker rmi xubiaolin/zerotier-planet:latest
|
docker rmi ${DOCKER_IMAGE}
|
||||||
|
|
||||||
read -p "是否删除数据?(y/n) " delete_data
|
read -p "是否删除数据?(y/n) " delete_data
|
||||||
delete_data=${delete_data:-n}
|
|
||||||
if [[ "$delete_data" =~ ^[Yy]$ ]]; then
|
if [[ "$delete_data" =~ ^[Yy]$ ]]; then
|
||||||
rm -rf $(pwd)/data/zerotier
|
rm -rf ${ZEROTIER_PATH}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "卸载完成"
|
echo "卸载完成"
|
||||||
}
|
}
|
||||||
|
|
||||||
# update() {
|
# 重置密码
|
||||||
# docker inspect ${CONTAINER_NAME} >/dev/null 2>&1
|
|
||||||
# if [ $? -ne 0 ]; then
|
|
||||||
# echo "容器${CONTAINER_NAME}不存在,请先安装"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# echo "如果用于生产环境,请先备份数据,不建议直接更新,10s后开始更新..."
|
|
||||||
# sleep 10
|
|
||||||
|
|
||||||
# if [ ! -d "$(pwd)/data/zerotier" ]; then
|
|
||||||
# echo "目录$(pwd)/data/zerotier不存在,无法更新"
|
|
||||||
# exit 0
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# extract_config() {
|
|
||||||
# local config_name=$1
|
|
||||||
# docker exec -it ${CONTAINER_NAME} sh -c "cat /app/config/${config_name}" | tr -d '\r'
|
|
||||||
# }
|
|
||||||
|
|
||||||
# ipv4=$(extract_config "ip_addr4")
|
|
||||||
# ipv6=$(extract_config "ip_addr6")
|
|
||||||
# API_PORT=$(extract_config "ztncui.port")
|
|
||||||
# FILE_PORT=$(extract_config "ztncui.port")
|
|
||||||
# ZT_PORT=$(extract_config "zerotier-one.port")
|
|
||||||
|
|
||||||
# echo "---------------------------"
|
|
||||||
# echo "ipv4地址为:${ipv4}"
|
|
||||||
# echo "ipv6地址为:${ipv6}"
|
|
||||||
# echo "API端口号为:${API_PORT}"
|
|
||||||
# echo "FILE端口号为:${FILE_PORT}"
|
|
||||||
# echo "ZT端口号为:${ZT_PORT}"
|
|
||||||
|
|
||||||
# docker stop ${CONTAINER_NAME}
|
|
||||||
# docker rm ${CONTAINER_NAME}
|
|
||||||
|
|
||||||
# docker pull xubiaolin/zerotier-planet:latest
|
|
||||||
# docker run -d --name ${CONTAINER_NAME} -p ${ZT_PORT}:${ZT_PORT} \
|
|
||||||
# -p ${ZT_PORT}:${ZT_PORT}/udp \
|
|
||||||
# -p ${API_PORT}:${API_PORT} \
|
|
||||||
# -p ${FILE_PORT}:${FILE_PORT} \
|
|
||||||
# -e IP_ADDR4=${ipv4} \
|
|
||||||
# -e IP_ADDR6=${ipv6} \
|
|
||||||
# -e ZT_PORT=${ZT_PORT} \
|
|
||||||
# -e API_PORT=${API_PORT} \
|
|
||||||
# -e FILE_SERVER_PORT=${FILE_PORT} \
|
|
||||||
# -v $(pwd)/data/zerotier/dist:/app/dist \
|
|
||||||
# -v $(pwd)/data/zerotier/ztncui:/app/ztncui \
|
|
||||||
# -v $(pwd)/data/zerotier/one:/var/lib/zerotier-one \
|
|
||||||
# -v $(pwd)/data/zerotier/config:/app/config \
|
|
||||||
# --restart unless-stopped \
|
|
||||||
# xubiaolin/zerotier-planet:latest
|
|
||||||
# }
|
|
||||||
|
|
||||||
resetpwd() {
|
resetpwd() {
|
||||||
docker exec -it ${CONTAINER_NAME} sh -c 'cp /app/ztncui/src/etc/default.passwd /app/ztncui/src/etc/passwd'
|
docker exec -it ${CONTAINER_NAME} sh -c 'cp /app/ztncui/src/etc/default.passwd /app/ztncui/src/etc/passwd'
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -307,6 +231,7 @@ resetpwd() {
|
|||||||
echo "--------------------------------"
|
echo "--------------------------------"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 菜单
|
||||||
menu() {
|
menu() {
|
||||||
echo "欢迎使用zerotier-planet脚本,请选择需要执行的操作:"
|
echo "欢迎使用zerotier-planet脚本,请选择需要执行的操作:"
|
||||||
echo "1. 安装"
|
echo "1. 安装"
|
||||||
@ -318,14 +243,14 @@ menu() {
|
|||||||
echo "0. 退出"
|
echo "0. 退出"
|
||||||
read -p "请输入数字:" num
|
read -p "请输入数字:" num
|
||||||
case "$num" in
|
case "$num" in
|
||||||
[1]) install ;;
|
1) install ;;
|
||||||
[2]) uninstall ;;
|
2) uninstall ;;
|
||||||
# [3]) update ;;
|
# 3) update ;;
|
||||||
[4]) info ;;
|
4) info ;;
|
||||||
[5]) resetpwd ;;
|
5) resetpwd ;;
|
||||||
[6]) update_centos_kernal ;;
|
6) update_centos_kernel ;;
|
||||||
[0]) exit ;;
|
0) exit ;;
|
||||||
*) echo "请输入正确数字 [1-5]" ;;
|
*) echo "请输入正确数字 [0-6]" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,63 +2,66 @@
|
|||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
# 配置路径和端口
|
||||||
|
ZEROTIER_PATH="/var/lib/zerotier-one"
|
||||||
|
APP_PATH="/app"
|
||||||
|
CONFIG_PATH="${APP_PATH}/config"
|
||||||
|
BACKUP_PATH="/bak"
|
||||||
|
ZTNCUI_PATH="${APP_PATH}/ztncui"
|
||||||
|
ZTNCUI_SRC_PATH="${ZTNCUI_PATH}/src"
|
||||||
|
|
||||||
|
# 启动 ZeroTier 和 ztncui
|
||||||
function start() {
|
function start() {
|
||||||
echo "start ztncui and zerotier"
|
echo "Start ztncui and zerotier"
|
||||||
cd /var/lib/zerotier-one && ./zerotier-one -p$(cat /app/config/zerotier-one.port) -d || exit 1
|
cd $ZEROTIER_PATH && ./zerotier-one -p$(cat ${CONFIG_PATH}/zerotier-one.port) -d || exit 1
|
||||||
nohup node /app/http_server.js &> /app/server.log &
|
nohup node ${APP_PATH}/http_server.js &> ${APP_PATH}/server.log &
|
||||||
cd /app/ztncui/src && npm start || exit 1
|
cd $ZTNCUI_SRC_PATH && npm start || exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 检查文件服务器端口配置文件
|
||||||
function check_file_server() {
|
function check_file_server() {
|
||||||
if [ ! -f "/app/config/file_server.port" ]; then
|
if [ ! -f "${CONFIG_PATH}/file_server.port" ]; then
|
||||||
echo "file_server.port is not exist, generate it"
|
echo "file_server.port does not exist, generating it"
|
||||||
echo "${FILE_SERVER_PORT}" >/app/config/file_server.port
|
echo "${FILE_SERVER_PORT}" > ${CONFIG_PATH}/file_server.port
|
||||||
echo "${FILE_SERVER_PORT}"
|
|
||||||
else
|
else
|
||||||
echo "file_server.port is exist, read it"
|
echo "file_server.port exists, reading it"
|
||||||
FILE_SERVER_PORT=$(cat /app/config/file_server.port)
|
FILE_SERVER_PORT=$(cat ${CONFIG_PATH}/file_server.port)
|
||||||
echo "${FILE_SERVER_PORT}"
|
|
||||||
fi
|
fi
|
||||||
|
echo "${FILE_SERVER_PORT}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_zerotier() {
|
# 初始化 ZeroTier 数据
|
||||||
mkdir -p /var/lib/zerotier-one
|
function init_zerotier_data() {
|
||||||
if [ "$(ls -A /var/lib/zerotier-one)" ]; then
|
echo "Initializing ZeroTier data"
|
||||||
echo "/var/lib/zerotier-one is not empty, start directly"
|
echo "${ZT_PORT}" > ${CONFIG_PATH}/zerotier-one.port
|
||||||
else
|
cp -r ${BACKUP_PATH}/zerotier-one/* $ZEROTIER_PATH
|
||||||
mkdir -p /app/config
|
|
||||||
echo "/var/lib/zerotier-one is empty, init data"
|
|
||||||
echo "${ZT_PORT}" >/app/config/zerotier-one.port
|
|
||||||
cp -r /bak/zerotier-one/* /var/lib/zerotier-one/
|
|
||||||
|
|
||||||
cd /var/lib/zerotier-one
|
cd $ZEROTIER_PATH
|
||||||
echo "start mkmoonworld"
|
|
||||||
openssl rand -hex 16 > authtoken.secret
|
openssl rand -hex 16 > authtoken.secret
|
||||||
|
|
||||||
./zerotier-idtool generate identity.secret identity.public
|
./zerotier-idtool generate identity.secret identity.public
|
||||||
./zerotier-idtool initmoon identity.public > moon.json
|
./zerotier-idtool initmoon identity.public > moon.json
|
||||||
|
|
||||||
if [ -z "$IP_ADDR4" ]; then IP_ADDR4=$(curl -s https://ipv4.icanhazip.com/); fi
|
IP_ADDR4=${IP_ADDR4:-$(curl -s https://ipv4.icanhazip.com/)}
|
||||||
if [ -z "$IP_ADDR6" ]; then IP_ADDR6=$(curl -s https://ipv6.icanhazip.com/); fi
|
IP_ADDR6=${IP_ADDR6:-$(curl -s https://ipv6.icanhazip.com/)}
|
||||||
|
|
||||||
echo "IP_ADDR4=$IP_ADDR4"
|
echo "IP_ADDR4=$IP_ADDR4"
|
||||||
echo "IP_ADDR6=$IP_ADDR6"
|
echo "IP_ADDR6=$IP_ADDR6"
|
||||||
|
ZT_PORT=$(cat ${CONFIG_PATH}/zerotier-one.port)
|
||||||
ZT_PORT=$(cat /app/config/zerotier-one.port)
|
|
||||||
|
|
||||||
echo "ZT_PORT=$ZT_PORT"
|
echo "ZT_PORT=$ZT_PORT"
|
||||||
|
|
||||||
if [ -z "$IP_ADDR4" ]; then stableEndpoints="[\"$IP_ADDR6/${ZT_PORT}\"]"; fi
|
if [ -n "$IP_ADDR4" ] && [ -n "$IP_ADDR6" ]; then
|
||||||
if [ -z "$IP_ADDR6" ]; then stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\"]"; fi
|
stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\",\"$IP_ADDR6/${ZT_PORT}\"]"
|
||||||
if [ -n "$IP_ADDR4" ] && [ -n "$IP_ADDR6" ]; then stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\",\"$IP_ADDR6/${ZT_PORT}\"]"; fi
|
elif [ -n "$IP_ADDR4" ]; then
|
||||||
if [ -z "$IP_ADDR4" ] && [ -z "$IP_ADDR6" ]; then
|
stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\"]"
|
||||||
|
elif [ -n "$IP_ADDR6" ]; then
|
||||||
|
stableEndpoints="[\"$IP_ADDR6/${ZT_PORT}\"]"
|
||||||
|
else
|
||||||
echo "IP_ADDR4 and IP_ADDR6 are both empty!"
|
echo "IP_ADDR4 and IP_ADDR6 are both empty!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$IP_ADDR4">/app/config/ip_addr4
|
echo "$IP_ADDR4" > ${CONFIG_PATH}/ip_addr4
|
||||||
echo "$IP_ADDR6">/app/config/ip_addr6
|
echo "$IP_ADDR6" > ${CONFIG_PATH}/ip_addr6
|
||||||
|
|
||||||
echo "stableEndpoints=$stableEndpoints"
|
echo "stableEndpoints=$stableEndpoints"
|
||||||
|
|
||||||
jq --argjson newEndpoints "$stableEndpoints" '.roots[0].stableEndpoints = $newEndpoints' moon.json > temp.json && mv temp.json moon.json
|
jq --argjson newEndpoints "$stableEndpoints" '.roots[0].stableEndpoints = $newEndpoints' moon.json > temp.json && mv temp.json moon.json
|
||||||
@ -70,38 +73,53 @@ function check_zerotier() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p /app/dist/
|
mkdir -p ${APP_PATH}/dist/
|
||||||
mv world.bin /app/dist/planet
|
mv world.bin ${APP_PATH}/dist/planet
|
||||||
cp *.moon /app/dist/
|
cp *.moon ${APP_PATH}/dist/
|
||||||
echo -e "mkmoonworld success!\n"
|
echo "mkmoonworld success!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查并初始化 ZeroTier
|
||||||
|
function check_zerotier() {
|
||||||
|
mkdir -p $ZEROTIER_PATH
|
||||||
|
if [ "$(ls -A $ZEROTIER_PATH)" ]; then
|
||||||
|
echo "$ZEROTIER_PATH is not empty, starting directly"
|
||||||
|
else
|
||||||
|
init_zerotier_data
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_ztncui() {
|
# 初始化 ztncui 数据
|
||||||
mkdir -p /app/ztncui
|
function init_ztncui_data() {
|
||||||
if [ "$(ls -A /app/ztncui)" ]; then
|
echo "Initializing ztncui data"
|
||||||
echo "${API_PORT}" >/app/config/ztncui.port
|
cp -r ${BACKUP_PATH}/ztncui/* $ZTNCUI_PATH
|
||||||
echo "/app/ztncui is not empty, start directly"
|
|
||||||
else
|
|
||||||
echo "/app/ztncui is empty, init data"
|
|
||||||
cp -r /bak/ztncui/* /app/ztncui/
|
|
||||||
|
|
||||||
echo "config ztncui"
|
echo "Configuring ztncui"
|
||||||
mkdir -p /app/config
|
mkdir -p ${CONFIG_PATH}
|
||||||
echo "${API_PORT}" >/app/config/ztncui.port
|
echo "${API_PORT}" > ${CONFIG_PATH}/ztncui.port
|
||||||
cd /app/ztncui/src
|
cd $ZTNCUI_SRC_PATH
|
||||||
echo "HTTP_PORT=${API_PORT}" >.env &&
|
echo "HTTP_PORT=${API_PORT}" > .env
|
||||||
echo 'NODE_ENV=production' >>.env &&
|
echo 'NODE_ENV=production' >> .env
|
||||||
echo 'HTTP_ALL_INTERFACES=true' >>.env &&
|
echo 'HTTP_ALL_INTERFACES=true' >> .env
|
||||||
echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env && echo "${ZT_PORT}" >/app/config/zerotier-one.port &&
|
echo "ZT_ADDR=localhost:${ZT_PORT}" >> .env
|
||||||
cp -v etc/default.passwd etc/passwd && TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret) &&
|
cp -v etc/default.passwd etc/passwd
|
||||||
echo "ZT_TOKEN=$TOKEN" >>.env &&
|
TOKEN=$(cat ${ZEROTIER_PATH}/authtoken.secret)
|
||||||
echo "make ztncui success!"
|
echo "ZT_TOKEN=$TOKEN" >> .env
|
||||||
|
echo "ztncui configuration successful!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查并初始化 ztncui
|
||||||
|
function check_ztncui() {
|
||||||
|
mkdir -p $ZTNCUI_PATH
|
||||||
|
if [ "$(ls -A $ZTNCUI_PATH)" ]; then
|
||||||
|
echo "${API_PORT}" > ${CONFIG_PATH}/ztncui.port
|
||||||
|
echo "$ZTNCUI_PATH is not empty, starting directly"
|
||||||
|
else
|
||||||
|
init_ztncui_data
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_file_server
|
check_file_server
|
||||||
check_zerotier
|
check_zerotier
|
||||||
check_ztncui
|
check_ztncui
|
||||||
|
|
||||||
start
|
start
|
Loading…
Reference in New Issue
Block a user