update-ipv4-input

This commit is contained in:
xubiaolin 2024-01-06 18:26:56 +08:00
parent dfd1cc5790
commit b4c4bc636a

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
function install(){ function install() {
echo "开始安装如果你已经安装了将会删除旧的数据10s后开始安装..." echo "开始安装如果你已经安装了将会删除旧的数据10s后开始安装..."
sleep 10 sleep 10
@ -34,7 +34,6 @@ function install(){
echo "端口${ZT_PORT}已被占用,请重新输入" echo "端口${ZT_PORT}已被占用,请重新输入"
exit 1 exit 1
fi fi
read -p "请输入zerotier-planet的API端口号,例如3443: " API_PORT read -p "请输入zerotier-planet的API端口号,例如3443: " API_PORT
while [[ ! "$API_PORT" =~ ^[0-9]+$ ]]; do while [[ ! "$API_PORT" =~ ^[0-9]+$ ]]; do
@ -46,7 +45,6 @@ function install(){
exit 1 exit 1
fi fi
read -p "请输入zerotier-planet的FILE端口号,例如3000: " FILE_PORT read -p "请输入zerotier-planet的FILE端口号,例如3000: " FILE_PORT
while [[ ! "$FILE_PORT" =~ ^[0-9]+$ ]]; do while [[ ! "$FILE_PORT" =~ ^[0-9]+$ ]]; do
read -p "端口号必须是数字,请重新输入: " FILE_PORT read -p "端口号必须是数字,请重新输入: " FILE_PORT
@ -57,7 +55,6 @@ function install(){
exit 1 exit 1
fi fi
read -p "是否自动获取公网IP地址?(y/n)" use_auto_ip read -p "是否自动获取公网IP地址?(y/n)" use_auto_ip
use_auto_ip=${use_auto_ip:-y} use_auto_ip=${use_auto_ip:-y}
if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then
@ -69,8 +66,8 @@ function install(){
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} 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
fi fi
else else
read -p "请输入IPv4地址: " ipv4 read -p "请输入IPv4地址: " ipv4
@ -86,26 +83,24 @@ function install(){
echo "IPv6地址为${ipv6}" echo "IPv6地址为${ipv6}"
echo "---------------------------" echo "---------------------------"
docker run -d --name myztplanet\ docker run -d --name myztplanet -p ${ZT_PORT}:${ZT_PORT} \
-p ${ZT_PORT}:${ZT_PORT} \ -p ${ZT_PORT}:${ZT_PORT}/udp \
-p ${ZT_PORT}:${ZT_PORT}/udp \ -p ${API_PORT}:${API_PORT} \
-p ${API_PORT}:${API_PORT}\ -p ${FILE_PORT}:${FILE_PORT} \
-p ${FILE_PORT}:${FILE_PORT} \ -e IP_ADDR4=${ipv4} \
-e ZT_PORT=${ZT_PORT} \ -e IP_ADDR6=${ipv6} \
-e API_PORT=${API_PORT} \ -e ZT_PORT=${ZT_PORT} \
-e FILE_SERVER_PORT=${FILE_PORT} \ -e API_PORT=${API_PORT} \
-v $(pwd)/data/zerotier/dist:/app/dist \ -e FILE_SERVER_PORT=${FILE_PORT} \
-v $(pwd)/data/zerotier/ztncui:/app/ztncui\ -v $(pwd)/data/zerotier/dist:/app/dist \
-v $(pwd)/data/zerotier/one:/var/lib/zerotier-one\ -v $(pwd)/data/zerotier/ztncui:/app/ztncui -v $(pwd)/data/zerotier/one:/var/lib/zerotier-one -v $(pwd)/data/zerotier/config:/app/config xubiaolin/zerotier-planet:latest
-v $(pwd)/data/zerotier/config:/app/config\
xubiaolin/zerotier-planet:latest
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "安装失败" echo "安装失败"
exit 1 exit 1
fi fi
sleep 10 sleep 10
KEY=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.key') KEY=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.key')
MOON_NAME=$(docker exec -it myztplanet sh -c 'ls /app/dist |grep moon') MOON_NAME=$(docker exec -it myztplanet sh -c 'ls /app/dist |grep moon')
@ -132,7 +127,7 @@ function install(){
echo "---------------------------" echo "---------------------------"
} }
function info(){ function info() {
docker inspect myztplanet >/dev/null 2>&1 docker inspect myztplanet >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "容器myztplanet不存在请先安装" echo "容器myztplanet不存在请先安装"
@ -145,7 +140,7 @@ function info(){
FILE_PORT=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.port' | tr -d '\r') FILE_PORT=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.port' | tr -d '\r')
MOON_NAME=$(docker exec -it myztplanet sh -c 'ls /app/dist |grep moon' | tr -d '\r') MOON_NAME=$(docker exec -it myztplanet sh -c 'ls /app/dist |grep moon' | tr -d '\r')
ZT_PORT=$(docker exec -it myztplanet sh -c 'cat /app/config/zerotier-one.port' | tr -d '\r') ZT_PORT=$(docker exec -it myztplanet sh -c 'cat /app/config/zerotier-one.port' | tr -d '\r')
KEY=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.key' |tr -d '\r') KEY=$(docker exec -it myztplanet sh -c 'cat /app/config/file_server.key' | tr -d '\r')
echo "---------------------------" echo "---------------------------"
echo "以下端口的tcp和udp协议请放行${ZT_PORT}${API_PORT}${FILE_PORT}" echo "以下端口的tcp和udp协议请放行${ZT_PORT}${API_PORT}${FILE_PORT}"
@ -162,7 +157,7 @@ function info(){
} }
function uninstall(){ function uninstall() {
echo "开始卸载..." echo "开始卸载..."
docker stop myztplanet docker stop myztplanet
@ -179,7 +174,7 @@ function uninstall(){
echo "卸载完成" echo "卸载完成"
} }
function update(){ function update() {
docker inspect myztplanet >/dev/null 2>&1 docker inspect myztplanet >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "容器myztplanet不存在请先安装" echo "容器myztplanet不存在请先安装"
@ -193,7 +188,7 @@ function update(){
if [ ! -d "$(pwd)/data/zerotier" ]; then if [ ! -d "$(pwd)/data/zerotier" ]; then
echo "目录$(pwd)/data/zerotier不存在无法更新" echo "目录$(pwd)/data/zerotier不存在无法更新"
exit 0 exit 0
fi fi
ipv4=$(docker exec -it myztplanet sh -c 'cat /app/config/ip_addr4' | tr -d '\r') ipv4=$(docker exec -it myztplanet sh -c 'cat /app/config/ip_addr4' | tr -d '\r')
@ -208,29 +203,25 @@ function update(){
echo "API端口号为${API_PORT}" echo "API端口号为${API_PORT}"
echo "FILE端口号为${FILE_PORT}" echo "FILE端口号为${FILE_PORT}"
echo "ZT端口号为${ZT_PORT}" echo "ZT端口号为${ZT_PORT}"
docker stop myztplanet docker stop myztplanet
docker pull xubiaolin/zerotier-planet:latest docker pull xubiaolin/zerotier-planet:latest
docker rm myztplanet docker rm myztplanet
docker run -d --name myztplanet\ docker run -d --name myztplanet -p ${ZT_PORT}:${ZT_PORT} \
-p ${ZT_PORT}:${ZT_PORT} \ -p ${ZT_PORT}:${ZT_PORT}/udp \
-p ${ZT_PORT}:${ZT_PORT}/udp \ -p ${API_PORT}:${API_PORT} \
-p ${API_PORT}:${API_PORT}\ -p ${FILE_PORT}:${FILE_PORT} \
-p ${FILE_PORT}:${FILE_PORT} \ -e IP_ADDR4=${ipv4} \
-e IP_ADDR4=${ipv4} \ -e IP_ADDR6=${ipv6} \
-e IP_ADDR6=${ipv6} \ -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 $(pwd)/data/zerotier/dist:/app/dist \ -v $(pwd)/data/zerotier/ztncui:/app/ztncui -v $(pwd)/data/zerotier/one:/var/lib/zerotier-one -v /data/config:/app/config xubiaolin/zerotier-planet:latest
-v $(pwd)/data/zerotier/ztncui:/app/ztncui\
-v $(pwd)/data/zerotier/one:/var/lib/zerotier-one\
-v /data/config:/app/config\
xubiaolin/zerotier-planet:latest
} }
function menu(){ function menu() {
echo "欢迎使用zerotier-planet脚本请选择需要执行的操作" echo "欢迎使用zerotier-planet脚本请选择需要执行的操作"
echo "1. 安装" echo "1. 安装"
echo "2. 卸载" echo "2. 卸载"
@ -239,13 +230,13 @@ function menu(){
echo "5. 退出" echo "5. 退出"
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] ) exit;; [5]) exit ;;
*) echo "请输入正确数字 [1-5]";; *) echo "请输入正确数字 [1-5]" ;;
esac esac
} }
menu menu