oh-my-opencode-agents

多平台服务器初始化脚本

Multi-Platform Bash License

English 简体中文

一个功能全面的跨平台交互式服务器初始化脚本,支持 Ubuntu、CentOS、Debian、macOS 和 Windows,一键安装现代开发环境所需的核心工具。


快速开始

国内用户(推荐)

由于网络原因,国内用户建议使用 GitHub 代理加速下载:

# Ubuntu (国内推荐)
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh -o install-ubuntu.sh && chmod +x install-ubuntu.sh && ./install-ubuntu.sh

# macOS Apple Silicon (国内推荐)
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-macos-arm.sh -o install-macos-arm.sh && chmod +x install-macos-arm.sh && ./install-macos-arm.sh

# CentOS / Debian (国内推荐)
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-centos.sh -o install-centos.sh && chmod +x install-centos.sh && ./install-centos.sh

脚本会自动检测网络环境,并配置国内镜像源(清华 TUNA、阿里云、淘宝 npm)加速软件包下载。

Ubuntu

# 交互模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh -o install-ubuntu.sh && chmod +x install-ubuntu.sh && ./install-ubuntu.sh

# 全自动模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh -o install-ubuntu.sh && chmod +x install-ubuntu.sh && ./install-ubuntu.sh -y

CentOS / RHEL / OpenCloud / Alibaba Cloud

# 交互模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-centos.sh -o install-centos.sh && chmod +x install-centos.sh && ./install-centos.sh

# 全自动模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-centos.sh -o install-centos.sh && chmod +x install-centos.sh && ./install-centos.sh -y

Debian

# 交互模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-debian.sh -o install-debian.sh && chmod +x install-debian.sh && ./install-debian.sh

# 全自动模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-debian.sh -o install-debian.sh && chmod +x install-debian.sh && ./install-debian.sh -y

macOS (Intel / x86_64)

# 交互模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-macos-x86.sh -o install-macos-x86.sh && chmod +x install-macos-x86.sh && ./install-macos-x86.sh

macOS (Apple Silicon / M1/M2/M3)

# 交互模式
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-macos-arm.sh -o install-macos-arm.sh && chmod +x install-macos-arm.sh && ./install-macos-arm.sh

Windows (PowerShell)

# 以管理员身份运行 PowerShell
# 交互模式
irm https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-windows.ps1 | iex

# 如果需要保存脚本
irm https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/install-windows.ps1 -OutFile install-windows.ps1
.\install-windows.ps1

分步安装(所有平台)

# 克隆仓库
git clone https://github.com/choovin/oh-my-opencode-agents.git
cd oh-my-opencode-agents

# 根据你的平台选择脚本
chmod +x install-*.sh

# 运行对应平台的脚本
./install-ubuntu.sh    # Ubuntu
./install-centos.sh    # CentOS/RHEL/Alibaba
./install-debian.sh    # Debian
./install-macos-x86.sh # macOS Intel
./install-macos-arm.sh # macOS Apple Silicon

支持的平台

本项目提供以下平台的安装脚本:

平台 脚本文件 包管理器 说明
Ubuntu oh-my-opencode-agents.sh apt 原始脚本,支持 Ubuntu 20.04/22.04/24.04
CentOS/RHEL install-centos.sh dnf/yum 支持 CentOS 7/8, RHEL, Rocky Linux, AlmaLinux
OpenCloud/Alibaba install-centos.sh dnf 阿里云、腾讯云等国产云服务器
Debian install-debian.sh apt 支持 Debian 10/11/12
macOS (Intel) install-macos-x86.sh Homebrew 适用于 Intel 芯片的 Mac
macOS (Apple Silicon) install-macos-arm.sh Homebrew 适用于 M1/M2/M3 芯片的 Mac
Windows install-windows.ps1 winget PowerShell 脚本,支持 Windows 10/11

✨ 功能特性


📦 安装内容

核心工具

工具 版本 用途
Git 最新版 版本控制系统
Zsh + Oh-My-Zsh 最新版 增强Shell框架
Zoxide 最新版 智能cd命令
Lazygit 最新版 Git终端UI
Lazydocker 最新版 Docker终端UI
Docker CE 最新版 容器化平台
Neovim v0.10+ 现代编辑器
LuaRocks 最新版 Lua包管理器
Node.js LTS v20.x+ JavaScript运行时(含npm, yarn, pnpm)
UV 最新版 极速Python包管理器
Poetry 最新版 Python依赖管理和打包工具
GCC & 构建工具 最新版 编译器和开发基础工具

附加工具

工具 用途
btop 现代系统监控器
tmux 终端复用器
fzf 模糊查找器
ripgrep (rg) 快速grep替代品
fd 快速find替代品

🎮 使用方式

交互模式(推荐首次使用)

./oh-my-opencode-agents.sh

脚本将执行:

  1. 显示预安装状态(已安装的工具)
  2. 检查先决条件(sudo权限、网络连接)
  3. 每个组件Y/N提示
  4. 安装选定组件并显示进度
  5. 配置安装后设置
  6. 显示详细前后摘要

非交互模式(全自动)

./oh-my-opencode-agents.sh -y
# 或
./oh-my-opencode-agents.sh --yes

适用于:

显示帮助

./oh-my-opencode-agents.sh --help

📋 命令示例

快速安装(一行命令)

# 下载、授权并交互式运行
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh -o oh-my-opencode-agents.sh && chmod +x oh-my-opencode-agents.sh && ./oh-my-opencode-agents.sh

# 下载并全自动安装
curl -fsSL https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh -o oh-my-opencode-agents.sh && chmod +x oh-my-opencode-agents.sh && ./oh-my-opencode-agents.sh -y

分步安装示例

# 1. 下载脚本
curl -O https://raw.githubusercontent.com/choovin/oh-my-opencode-agents/main/oh-my-opencode-agents.sh

# 2. 添加执行权限
chmod +x oh-my-opencode-agents.sh

# 3. 运行(交互模式)
./oh-my-opencode-agents.sh

# 4. 查看日志
cat ~/ubuntu-setup-*.log

自动化示例

# 全自动安装
./oh-my-opencode-agents.sh -y

# 以root用户运行(不推荐)
sudo bash oh-my-opencode-agents.sh -y

🎯 预期输出

交互模式输出示例

========================================
Pre-Installation Status Check
========================================

[INFO] Checking what is currently installed...

  ✓ git: git version 2.43.0
  ✗ zsh: not installed
  ✗ lazygit: not installed
  ✓ docker: Docker version 24.0.7
  ...

Continue with installation? [Y/n]: y

========================================
Git Installation
========================================
[WARN] Git is already installed (git version 2.43.0)
Reinstall/upgrade git? [y/N]: n

...

========================================
Installation Summary
========================================

Newly Installed:
  ✓ zsh: zsh 5.9
  ✓ lazygit: version=0.40.2
  ✓ neovim: NVIM v0.9.5

Upgraded:
  ↑ docker: Docker version 24.0.7 → Docker version 25.0.0

Already Installed (unchanged):
  • git: git version 2.43.0
  • tmux: tmux 3.3a

Actions performed during this run:
  ✓ System Updates
  ✓ Zsh + Oh-My-Zsh
  ✓ Lazygit
  ✓ Docker CE
  ✓ Neovim
  ✓ Zsh Config

自动模式输出

./oh-my-opencode-agents.sh -y

# 所有提示显示[AUTO-YES]:
Continue with installation? [AUTO-YES]
Install/upgrade git? [AUTO-YES]
# ... 全部自动安装

🔧 安装后配置

必要步骤

  1. 重新登录(Docker组权限和Shell更改需要)
    # 或者立即刷新Docker组:
    newgrp docker
    
  2. 测试安装:
    docker --version
    docker run hello-world
    nvim --version
    lazygit --version
    lazydocker --version
    
  3. 检查Shell:
    echo $SHELL
    # 应该显示:/usr/bin/zsh
    

Zsh 特性

配置的zsh包含:

别名配置

.zshrc 中配置了以下别名:

vim='nvim'       # 使用Neovim替代Vim
vi='nvim'        # 使用Neovim替代Vi
lg='lazygit'     # 快速启动lazygit
ld='lazydocker'  # 快速启动lazydocker

📁 配置文件位置

类型 路径
日志文件 ~/ubuntu-setup-YYYYMMDD-HHMMSS.log
备份目录 ~/.config-backups/YYYYMMDD-HHMMSS/
Zsh配置 ~/.zshrc
Neovim配置 ~/.config/nvim/

Neovim 配置

脚本将从以下地址克隆您的自定义配置:

注意:SSH需要GitHub SSH密钥设置。如果SSH失败,会自动尝试HTTPS。


🛡️ 安全注意事项

Docker 用户组

⚠️ 重要docker 组成员拥有主机系统的root级权限。

备份机制

所有现有配置在修改前都会备份到 ~/.config-backups/

# 查看备份
ls -la ~/.config-backups/

# 恢复备份
cp -r ~/.config-backups/20250122-143022/nvim-143500 ~/.config/nvim

🐛 故障排除

常见问题

问题:脚本因”权限拒绝”失败

# 解决:添加执行权限
chmod +x oh-my-opencode-agents.sh

问题:Docker命令需要sudo

# 解决:重新登录或运行:
newgrp docker

问题:Neovim配置克隆失败

# 解决:设置GitHub SSH密钥
ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub
# 添加到GitHub:Settings → SSH keys

问题:Zsh未激活

# 解决:检查默认shell
echo $SHELL

# 如果不是zsh,手动更改:
chsh -s $(which zsh)
# 然后重新登录

问题:历史搜索无法使用方向键

# 解决:检查插件安装
ls ~/.oh-my-zsh/custom/plugins/zsh-history-substring-search

# 如果缺失,手动克隆:
git clone https://github.com/zsh-users/zsh-history-substring-search \
  ~/.oh-my-zsh/custom/plugins/zsh-history-substring-search

检查安装

# 查看详细日志
cat ~/ubuntu-setup-*.log

# 检查特定工具
which lazygit
lazygit --version

# 验证Docker组
groups
# 应该包含'docker'

# 测试免sudo使用Docker
docker ps

⚙️ 自定义

修改组件

编辑脚本以跳过或添加组件:

# 在main()函数中注释掉不需要的安装
# install_btop && installed_components+=("Btop")  # 禁用

更改Zsh主题

编辑 ~/.zshrc

# 从robbyrussell更改为其他主题
ZSH_THEME="agnoster"  # 或 "powerlevel10k", "spaceship" 等

添加更多插件

编辑 ~/.zshrc

plugins=(
    git
    docker
    zoxide
    fzf
    zsh-history-substring-search
    # 在此处添加更多插件
    kubectl
    terraform
    aws
)


系统要求

Ubuntu

CentOS / RHEL / Alibaba Cloud

Debian

macOS

Windows


✨ 最佳实践

本项目遵循行业最佳实践:

✅ 严格错误处理(set -euo pipefail) ✅ 仅终端使用颜色码 ✅ 完整文件日志 ✅ 修改前备份 ✅ 官方包源(PPA、仓库) ✅ 用户权限验证 ✅ 互联网连接检查 ✅ 幂等操作(可安全重运行)


📚 参考链接


📄 许可证

本项目采用 MIT 许可证发布。


作者:choovin 日期:2025-02-03 版本:0.1.0-beta


💡 快速参考

# 首次使用
chmod +x oh-my-opencode-agents.sh && ./oh-my-opencode-agents.sh

# 全自动安装
./oh-my-opencode-agents.sh -y

# 查看日志
cat ~/ubuntu-setup-*.log

# 刷新Docker权限
newgrp docker

# 测试所有工具
docker run hello-world && lazygit --version && nvim --version

# Poetry 使用指南
poetry new my-project          # 创建新项目
poetry add <package>           # 添加依赖
poetry install                 # 从poetry.lock安装
poetry run <command>           # 在虚拟环境中运行命令
poetry shell                   # 激活虚拟环境
poetry config virtualenvs.in-project true  # 虚拟环境存储在项目目录

祝您编码愉快!🚀