diff --git a/index.sh b/index.sh index 9fcfebc..a9b5696 100644 --- a/index.sh +++ b/index.sh @@ -1,8 +1,15 @@ #!/bin/bash -# 定义文件和端口 +# 检查是否传入端口参数,如果没有则使用默认端口 6001 +if [ $# -eq 0 ]; then + PORT=6001 + echo "未提供端口号,使用默认端口 $PORT" +else + PORT=\$1 # 从命令行参数获取端口号 +fi + +# 定义文件 FILE="index.js" -PORT=9001 # 检查 index.js 是否存在,如果存在则删除 if [ -f "$FILE" ]; then @@ -11,7 +18,7 @@ if [ -f "$FILE" ]; then echo "$FILE 已删除" fi -# 检查 9001 端口是否被占用 +# 检查指定端口是否被占用 if lsof -i:$PORT; then echo "端口 $PORT 被占用,正在杀死相关进程..." # 获取占用端口的进程 ID 并杀死它 @@ -27,7 +34,7 @@ curl -o $FILE https://x-mo.cn:9009/XiaoMo/alist-proxy/raw/branch/master/index.js if [ $? -eq 0 ]; then echo "下载完成,正在执行 $FILE..." - node $FILE port=$PORT + node $FILE else echo "下载失败" fi \ No newline at end of file