Files
dock/测速软件
2026-01-12 16:28:28 +08:00

73 lines
1.5 KiB
Plaintext
Raw Permalink 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.
cat > librespeed_install.sh << 'EOF'
#!/usr/bin/env bash
set -e
APP_NAME="librespeed"
DEFAULT_PORT=8000
WORKDIR="/root/librespeed"
echo "======================================="
echo " LibreSpeed 内网测速 Docker 一键部署"
echo "======================================="
# root 检查
if [ "$(id -u)" -ne 0 ]; then
echo "❌ 请使用 root 运行"
exit 1
fi
# 端口选择
read -p "请输入访问端口(默认 ${DEFAULT_PORT},直接回车使用默认): " PORT
PORT=${PORT:-$DEFAULT_PORT}
# 端口简单校验
if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1 ] || [ "$PORT" -gt 65535 ]; then
echo "❌ 端口不合法"
exit 1
fi
echo "▶ 使用端口: $PORT"
# Docker 检查
if ! command -v docker >/dev/null 2>&1; then
echo "❌ 未检测到 Docker请先安装 Docker"
exit 1
fi
# docker compose 检查
if ! docker compose version >/dev/null 2>&1; then
echo "❌ 未检测到 docker compose 插件"
exit 1
fi
# 创建目录
mkdir -p "$WORKDIR"
cd "$WORKDIR"
# 生成 docker-compose.yml
cat > docker-compose.yml <<YAML
version: '3'
services:
librespeed:
image: librespeed/speedtest:latest
container_name: librespeed
restart: always
ports:
- "${PORT}:80"
YAML
# 启动
echo "▶ 启动 LibreSpeed 容器..."
docker compose up -d
# 验证
sleep 1
if docker ps | grep -q librespeed; then
echo "✅ LibreSpeed 启动成功"
echo "🌐 访问地址: http://$(hostname -I | awk '{print $1}'):${PORT}"
else
echo "❌ LibreSpeed 启动失败"
docker compose logs
fi
EOF