Skip to content

Commit d0a0592

Browse files
author
William Yang
committed
feat: 添加一键安装脚本 install.sh
1 parent 796e745 commit d0a0592

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

scripts/install.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# BootCS CLI 安装脚本
3+
# 用法: curl -fsSL https://bootcs.cn/install.sh | bash
4+
5+
set -e
6+
7+
# 颜色定义
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
NC='\033[0m' # No Color
12+
13+
echo -e "${GREEN}🚀 Installing BootCS CLI...${NC}"
14+
15+
# 检查 Docker 是否安装
16+
if ! command -v docker &> /dev/null; then
17+
echo -e "${RED}❌ Docker is not installed. Please install Docker first.${NC}"
18+
echo " Visit: https://docs.docker.com/get-docker/"
19+
exit 1
20+
fi
21+
22+
# 检查 Docker 是否运行
23+
if ! docker info &> /dev/null; then
24+
echo -e "${RED}❌ Docker is not running. Please start Docker first.${NC}"
25+
exit 1
26+
fi
27+
28+
# 确定安装目录
29+
INSTALL_DIR="${HOME}/.local/bin"
30+
mkdir -p "$INSTALL_DIR"
31+
32+
# 创建 bootcs 脚本
33+
BOOTCS_SCRIPT="$INSTALL_DIR/bootcs"
34+
35+
cat > "$BOOTCS_SCRIPT" << 'EOF'
36+
#!/bin/bash
37+
# BootCS CLI Wrapper
38+
# https://bootcs.cn
39+
40+
# 默认使用 cs50 镜像,可通过环境变量覆盖
41+
BOOTCS_IMAGE="${BOOTCS_IMAGE:-ghcr.io/bootcs-cn/bootcs-cli:cs50}"
42+
43+
# 运行容器
44+
docker run --rm -v "$(pwd)":/workspace "$BOOTCS_IMAGE" "$@"
45+
EOF
46+
47+
chmod +x "$BOOTCS_SCRIPT"
48+
49+
# 检查 PATH
50+
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
51+
echo ""
52+
echo -e "${YELLOW}⚠️ Please add $INSTALL_DIR to your PATH:${NC}"
53+
echo ""
54+
55+
# 检测 shell 类型
56+
SHELL_NAME=$(basename "$SHELL")
57+
if [[ "$SHELL_NAME" == "zsh" ]]; then
58+
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc"
59+
echo " source ~/.zshrc"
60+
elif [[ "$SHELL_NAME" == "bash" ]]; then
61+
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc"
62+
echo " source ~/.bashrc"
63+
else
64+
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
65+
fi
66+
echo ""
67+
fi
68+
69+
echo -e "${GREEN}✅ BootCS CLI installed successfully!${NC}"
70+
echo ""
71+
echo "Usage:"
72+
echo " bootcs check cs50/credit # 检查作业"
73+
echo " bootcs --help # 查看帮助"
74+
echo ""
75+
echo "To use a different course image:"
76+
echo " BOOTCS_IMAGE=ghcr.io/bootcs-cn/bootcs-cli:other bootcs check ..."

0 commit comments

Comments
 (0)