Skip to content

Commit

Permalink
fix: shell bug
Browse files Browse the repository at this point in the history
  • Loading branch information
1995chen committed May 7, 2024
1 parent 5a3d214 commit bcf2ef6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions build/dnf_data/ddns.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#! /bin/bash

# 一直循环检测IP是否变更, 变更后重新设置配置文件并重启服务
while $DDNS_ENABLE;
while [ "$DDNS_ENABLE" = true ] && [ -n "$DDNS_DOMAIN" ];
do
nslookup_output=$(nslookup -debug $DDNS_DOMAIN 2>/dev/null || true)
ddns_ip=$(echo "$nslookup_output" | awk '/^Address: / { print $2 }')
echo "found ddns_ip is $ddns_ip"
if [ "$ddns_ip" != "$(cat /data/ddns/DDNS_IP_RECORD 2>/dev/null || true)" ] ; then
echo "ip changed, new ip is $ddns_ip"
PUBLIC_IP=$ddns_ip
# 复制配置文件
rm -rf /data/ddns/*.cfg
cp -r /home/template/neople/channel/cfg/channel.cfg /data/ddns/channel.cfg
cp -r /home/template/neople/game/cfg/siroco11.cfg /data/ddns/siroco11.cfg
cp -r /home/template/neople/game/cfg/siroco52.cfg /data/ddns/siroco52.cfg
cp /home/template/neople/channel/cfg/channel.cfg /data/ddns/channel.cfg
cp /home/template/neople/game/cfg/siroco11.cfg /data/ddns/siroco11.cfg
cp /home/template/neople/game/cfg/siroco52.cfg /data/ddns/siroco52.cfg
# 重设PUBLIC_IP
find /data/ddns -type f -name "*.cfg" -print0 | xargs -0 sed -i "s/PUBLIC_IP/$PUBLIC_IP/g"
mv /data/ddns/channel.cfg /home/neople/channel/cfg/channel.cfg
Expand All @@ -22,7 +23,11 @@ do
supervisorctl restart dnf:channel dnf:game_siroco11 dnf:game_siroco52
# 保存本次IP记录
echo "$PUBLIC_IP" >> /data/ddns/DDNS_IP_RECORD
else
echo "public ip: $ddns_ip is not change"
fi
sleep $DDNS_INTERVAL
wait_time=${DDNS_INTERVAL:-10}
echo "wait $wait_time seconds, sleep..."
sleep $wait_time
done
echo "ddns disabled"
7 changes: 4 additions & 3 deletions build/dnf_data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cp -r /home/template/neople /home/template/neople-tmp
cp -r /home/template/root /home/template/root-tmp

# 自动获取公网ip
if [ -z "$PUBLIC_IP" ] && $AUTO_PUBLIC_IP;
if [ -z "$PUBLIC_IP" ] && [ "$AUTO_PUBLIC_IP" = true ];
then
# 等待60秒,如果无法成功获得ip直接退出
counter=0
Expand Down Expand Up @@ -65,9 +65,10 @@ fi
# 检查Netbird IP
if [ -z "$PUBLIC_IP" ] && [ -n "$NB_SETUP_KEY" ] && [ -n "$NB_MANAGEMENT_URL" ]; then
# 重新安装netbird service
if [ ! -f "/etc/init.d/netbird" ];then
if [ -f "/etc/init.d/netbird" ];then
echo "uninstall old netbird service"
netbird service uninstall
fi
echo "install new netbird service"
netbird service install --config /data/netbird/config.json
echo "starting netbird service[$NB_MANAGEMENT_URL] use setup_key: $NB_SETUP_KEY"
Expand Down Expand Up @@ -106,7 +107,7 @@ else
fi

# 检查DDNS
if [ -z "$PUBLIC_IP" ] && [ -n "$DDNS_ENABLE" ] && [ -n "$DDNS_DOMAIN" ]; then
if [ -z "$PUBLIC_IP" ] && [ "$DDNS_ENABLE" = true ] && [ -n "$DDNS_DOMAIN" ]; then
# 等待60秒,如果无法成功获得ip直接退出
counter=0
while [ $counter -lt 60 ]
Expand Down

0 comments on commit bcf2ef6

Please sign in to comment.