This commit is contained in:
zqiushi 2025-01-09 13:58:41 +08:00
parent 1ad2ceda65
commit 7b25144e2e

View File

@ -1,7 +1,7 @@
#!/bin/bash
# FRPC 配置目录和文件路径
FLAG_FILE="/tmp/lsyfrpc_check_config_running"
LOCK_FILE="/tmp/lsyfrpc_check_config_running.lock"
FRPC_FILE="/data/lsyfrpc/frpc"
FRPC_DIR="/data/lsyfrpc"
CONFIG_FILE="$FRPC_DIR/frpc.ini"
@ -12,7 +12,7 @@ function get_cloud_config() {
echo "MAC Address: $mac_address"
# 尝试获取云端端口,最多重试 5 次
retries=5
retries=1
for ((i=1; i<=retries; i++)); do
response=$(curl -s -X 'POST' \
'https://frp-box.jxm.cool/request_port/' \
@ -58,7 +58,6 @@ function check_config() {
# 比较配置文件中的 MAC 地址和端口是否与云端匹配
if [ "$current_mac_address" != "$cloud_mac_address" ] || [ "$current_port" != "$cloud_port" ]; then
echo "[INFO] Configuration mismatch detected. Re-running install.sh..."
# sudo /bin/bash $FRPC_DIR/frp_install.sh
cat > "$FRPC_DIR/frpc.ini" <<EOF
[common]
server_addr = box.jxm.cool
@ -81,6 +80,19 @@ EOF
# 主函数,获取云端配置并检查配置
main() {
# 检查锁文件
if [ -f "$LOCK_FILE" ]; then
echo "[INFO] Lock file exists. Script is already running."
exit 0
fi
# 创建锁文件
touch "$LOCK_FILE"
# 设置脚本在退出时删除锁文件
trap "rm -f $LOCK_FILE" EXIT
# 主逻辑
get_cloud_config
check_config "$cloud_port" "$cloud_mac_address"
}