Skip to content

Commit 8647fbd

Browse files
shuguangshuguang
authored andcommitted
fix: 修复部分环境http服务启动报错
1 parent 052bfb5 commit 8647fbd

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

install.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,22 @@ start_http_server() {
290290
return 1
291291
fi
292292

293-
# 获取本机IP地址
293+
# 获取本机IP地址(兼容Linux与macOS)
294294
local server_ip=""
295-
if command -v hostname >/dev/null 2>&1; then
296-
server_ip=$(hostname -I | awk '{print $1}' 2>/dev/null || echo "localhost")
295+
if command -v hostname >/dev/null 2>&1 && hostname -I >/dev/null 2>&1; then
296+
# Linux 常见方式
297+
server_ip=$(hostname -I | awk '{print $1}' 2>/dev/null)
298+
elif [[ "$(uname)" == "Darwin" ]]; then
299+
# macOS:优先尝试en0,其次en1;若失败则从ifconfig解析
300+
server_ip=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null)
301+
if [[ -z "$server_ip" ]]; then
302+
server_ip=$(ifconfig 2>/dev/null | awk '/inet / && $2 != "127.0.0.1" {print $2; exit}')
303+
fi
297304
else
305+
# 其他环境兜底
306+
server_ip=$(hostname -I 2>/dev/null | awk '{print $1}')
307+
fi
308+
if [[ -z "$server_ip" ]]; then
298309
server_ip="localhost"
299310
fi
300311

@@ -1233,8 +1244,9 @@ main() {
12331244
exit 1
12341245
fi
12351246

1236-
# 检查备份目录中是否有备份文件
1237-
local backup_count=$(find "$BACKUP_DIR" -maxdepth 1 -type d -name "*_*" | wc -l)
1247+
# 检查备份目录中是否有备份文件(兼容macOS的BSD find,无 -maxdepth)
1248+
# 仅统计一级目录,名称形如 *_*
1249+
local backup_count=$(find "$BACKUP_DIR" -type d -name "*_*" -prune -print | wc -l)
12381250
if [[ $backup_count -eq 0 ]]; then
12391251
log_error "备份目录中没有找到备份文件: $BACKUP_DIR"
12401252
exit 1

0 commit comments

Comments
 (0)