Files
node-ws/setup.sh
2025-05-10 01:02:04 +08:00

58 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
if [ -z "$1" ]; then
echo "Error: 参数为你的域名!"
echo "Usage: $0 domain"
exit 1
fi
domain=$1
username=$(whoami)
random_port=$((RANDOM % 40001 + 20000))
echo "to /home/$username/domains/$domain/public_html/index.js"
curl -s -o "/home/$username/domains/$domain/public_html/index.js" "https://raw.githubusercontent.com/frankiejun/node-ws/main/index.js"
if [ $? -ne 0 ]; then
echo "Error: 下载脚本 index.js 失败!"
exit 1
fi
sed -i "s/1234.abc.com/$domain/g" "/home/$username/domains/$domain/public_html/index.js"
sed -i "s/3000;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js"
cat > "/home/$username/domains/$domain/public_html/package.json" << EOF
{
"name": "node-ws",
"version": "1.0.0",
"description": "Node.js Server",
"main": "index.js",
"author": "eoovve",
"repository": "https://github.com/eoovve/node-ws",
"license": "MIT",
"private": false,
"scripts": {
"start": "node index.js"
},
"dependencies": {
"ws": "^8.14.2",
"axios": "^1.6.2"
},
"engines": {
"node": ">=14"
}
}
EOF
cd "/home/$username/domains/$domain/public_html/"
if [ $? -ne 0 ]; then
echo "Error: 切换到public_html目录失败"
exit 1
fi
echo "安装完毕"