alist-proxy/index.sh
2024-10-13 16:38:06 +08:00

47 lines
1.2 KiB
Bash

#!/bin/bash
# 检查是否传入端口参数,如果没有则使用默认端口 6001
if [ $# -eq 0 ]; then
PORT=6001
echo "未提供端口号,使用默认端口 $PORT"
else
PORT=$1 # 从命令行参数获取端口号
fi
# 定义文件
FILE="index.js"
# 检查 index.js 是否存在,如果存在则删除
if [ -f "$FILE" ]; then
echo "$FILE 存在,正在删除..."
rm -f "$FILE"
echo "$FILE 已删除"
fi
# 检查指定端口是否被占用
if lsof -i:$PORT; then
echo "端口 $PORT 被占用,正在杀死相关进程..."
# 获取占用端口的进程 ID 并杀死它
lsof -ti:$PORT | xargs kill -9
echo "端口 $PORT 已释放"
else
echo "端口 $PORT 未被占用"
fi
# 检查 Node.js 是否安装
if ! command -v node &> /dev/null; then
echo "Node.js 未安装,请先安装 Node.js。"
exit 1
fi
# 下载 index.js 并执行
echo "正在下载 index.js..."
curl -o $FILE https://x-mo.cn:9009/XiaoMo/alist-proxy/raw/branch/master/index.js
if [ $? -eq 0 ]; then
echo "下载完成,正在执行 node $FILE --port=$PORT ..."
node $FILE --port=$PORT # 使用 --port=6001 传递参数
else
echo "下载失败"
fi