forked from buzzhub/lsyupdate
1
This commit is contained in:
parent
72a2de4b2c
commit
13f0eb48aa
@ -11,7 +11,7 @@ function get_cloud_config() {
|
||||
mac_address=$(cat /sys/class/net/eth0/address)
|
||||
echo "MAC Address: $mac_address"
|
||||
|
||||
# 尝试获取云端端口,最多重试 3 次
|
||||
# 尝试获取云端端口,最多重试 5 次
|
||||
retries=5
|
||||
for ((i=1; i<=retries; i++)); do
|
||||
response=$(curl -s -X 'POST' \
|
||||
@ -48,11 +48,12 @@ function check_config() {
|
||||
local cloud_mac_address="$2"
|
||||
|
||||
# 从配置文件中读取现有的 MAC 地址和端口
|
||||
current_mac_address=$(grep -o '\[.*\]' "$CONFIG_FILE" | tr -d '[]')
|
||||
current_port=$(grep -o 'remote_port = [0-9]*' "$CONFIG_FILE" | awk '{print $3}')
|
||||
current_mac_address=$(grep -o '\[.*\]' "$CONFIG_FILE" | tr -d '[]' | xargs) # 用 xargs 去掉两端空格
|
||||
current_port=$(grep -o 'remote_port = [0-9]*' "$CONFIG_FILE" | awk '{print $3}' | xargs) # 用 xargs 去掉两端空格
|
||||
|
||||
echo "Current MAC Address in frpc.ini: $current_mac_address $cloud_mac_address "
|
||||
echo "Current Port in frpc.ini: $current_port $cloud_port"
|
||||
# 输出调试信息
|
||||
echo "Current MAC Address in frpc.ini: '$current_mac_address' '$cloud_mac_address'"
|
||||
echo "Current Port in frpc.ini: '$current_port' '$cloud_port'"
|
||||
|
||||
# 比较配置文件中的 MAC 地址和端口是否与云端匹配
|
||||
if [ "$current_mac_address" != "$cloud_mac_address" ] || [ "$current_port" != "$cloud_port" ]; then
|
||||
@ -71,7 +72,7 @@ local_port = 22
|
||||
remote_port = $cloud_port
|
||||
EOF
|
||||
echo "[INFO] Configuration updated. Restarting frpc..."
|
||||
sudo systemctl restart lsyfrpc.service
|
||||
sudo systemctl restart lsyfrpc.service
|
||||
|
||||
else
|
||||
echo "[INFO] Configuration is up to date."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user