Skip to main content

A command line tool to manage Alibaba Cloud ECS instances

Project description

sqnethelper - 阿里云ECS助手工具

这是一个用于管理阿里云ECS实例的命令行工具。您可以使用此工具快速创建、管理ECS实例,自动安装VPN协议,并生成SingBox客户端配置。

✨ 主要功能

  • 🚀 一键创建ECS实例:自动创建、配置网络和安全组
  • 🔒 多协议VPN支持:支持Reality、VMess、Shadowsocks等协议
  • 📱 SingBox配置生成:自动生成完整的SingBox客户端配置文件
  • 自动释放管理:设置实例自动销毁时间,避免忘记关机
  • 🔧 SSH密钥管理:自动创建和管理SSH密钥对

📦 安装方式

方式一:使用pipx安装(推荐 - macOS)

pipx是安装Python命令行工具的最佳方式,它会为每个工具创建独立的虚拟环境。

1. 安装pipx

# 使用Homebrew安装pipx(推荐)
brew install pipx

# 或者使用pip安装
python3 -m pip install --user pipx
python3 -m pipx ensurepath

2. 使用pipx安装sqnethelper

pipx install sqnethelper

3. 验证安装

sqnethelper --version

4. pipx管理命令

# 升级到最新版本
pipx upgrade sqnethelper

# 强制重新安装
pipx install --force sqnethelper

# 卸载
pipx uninstall sqnethelper

# 查看已安装的包
pipx list

方式二:使用pip安装

在虚拟环境中安装(推荐)

# 创建虚拟环境
python3 -m venv sqnethelper-env
source sqnethelper-env/bin/activate

# 安装sqnethelper
pip install sqnethelper

用户级安装

pip install --user sqnethelper

方式三:从源码安装

git clone https://github.com/weishq/sqnethelper.git
cd sqnethelper
pip install -e .

🚀 快速开始

1. 设置阿里云凭证

首次使用需要配置阿里云Access Key和Secret:

sqnethelper setup

按提示输入您的阿里云Access Key和Secret。如果您还没有,请访问 阿里云控制台 创建。

2. 一键创建VPN服务器

sqnethelper create

这个命令会:

  • 自动创建ECS实例(默认1小时后自动销毁)
  • 配置安全组和网络
  • 安装Xray VPN协议
  • 生成SingBox客户端配置文件

3. 查看现有实例

sqnethelper list

📋 命令参考

基础命令

# 查看帮助
sqnethelper --help

# 查看版本
sqnethelper --version

# 设置阿里云凭证
sqnethelper setup

# 查看/修改配置
sqnethelper config
sqnethelper config --region  # 修改区域设置

实例管理

# 创建新实例(自动安装VPN)
sqnethelper create

# 列出所有实例
sqnethelper list

# 修改自动释放时间
sqnethelper autodel

# 删除实例
sqnethelper delete

VPN管理

# 为现有实例添加VPN协议
sqnethelper addvpn

网络说明

  • 默认创建的安全组只开放必要端口
  • 支持IPv4和IPv6双栈网络
  • 自动配置合适的带宽和流量

💻 开发者文档

开发环境设置

# 克隆项目
git clone https://github.com/weishq/sqnethelper.git
cd sqnethelper

# 创建开发环境
python3 -m venv dev-env
source dev-env/bin/activate

# 安装开发依赖
pip install -e .
pip install build twine

代码测试

# 运行基本测试
python -m sqnethelper --help

# 测试配置功能
python -m sqnethelper config

# 测试连接(需要配置阿里云凭证)
python -m sqnethelper list

编译和发布

1. 更新版本号

在发布前,需要更新 setup.py 中的版本号:

# setup.py
version="0.2.9",  # 更新这里的版本号

2. 清理旧的构建文件

# 删除旧的构建文件
rm -rf build/ dist/ sqnethelper.egg-info/

3. 构建包

# 使用build模块构建
python -m build

# 或者使用传统方式
python setup.py sdist bdist_wheel

构建完成后会在 dist/ 目录下生成:

  • sqnethelper-x.x.x.tar.gz (源码包)
  • sqnethelper-x.x.x-py3-none-any.whl (wheel包)

4. 发布到PyPI

# 发布到正式PyPI
python -m twine upload dist/*

# 或者先发布到测试PyPI
python -m twine upload --repository testpypi dist/*

5. 一键发布脚本

创建 scripts/publish.sh 脚本:

#!/bin/bash
set -e

echo "🚀 开始发布 sqnethelper..."

# 检查是否在正确的目录
if [ ! -f "setup.py" ]; then
    echo "❌ 错误: 请在项目根目录运行此脚本"
    exit 1
fi

# 获取当前版本号
VERSION=$(python setup.py --version)
echo "📦 当前版本: $VERSION"

# 确认发布
read -p "确认发布版本 $VERSION? (y/N): " confirm
if [[ $confirm != [yY] ]]; then
    echo "❌ 发布已取消"
    exit 0
fi

# 清理旧文件
echo "🧹 清理旧的构建文件..."
rm -rf build/ dist/ sqnethelper.egg-info/

# 构建包
echo "🔨 构建包..."
python -m build

# 检查包
echo "🔍 检查包..."
python -m twine check dist/*

# 发布到PyPI
echo "📤 发布到PyPI..."
python -m twine upload dist/*

echo "✅ 发布完成! 版本 $VERSION 已上传到PyPI"
echo "📥 用户可以使用以下命令更新:"
echo "   pip install --upgrade sqnethelper"
echo "   pipx upgrade sqnethelper"

6. 发布后验证

# 检查PyPI页面
open https://pypi.org/project/sqnethelper/

# 测试安装新版本
pip install --upgrade sqnethelper
sqnethelper --version

开发流程

  1. 开发新功能

    git checkout -b feature/new-feature
    # 开发代码...
    git commit -m "feat: 添加新功能"
    
  2. 测试验证

    python -m sqnethelper --help
    # 运行各种测试...
    
  3. 更新版本和文档

    # 更新setup.py中的版本号
    # 更新CHANGELOG.md
    # 更新README.md(如需要)
    
  4. 发布新版本

    git tag v0.2.9
    git push origin main --tags
    ./scripts/publish.sh
    

项目结构

sqnethelper/
├── sqnethelper/          # 主包目录
│   ├── __init__.py
│   ├── __main__.py       # 命令行入口
│   ├── cli.py           # CLI界面
│   ├── ConfigManager.py # 配置管理
│   ├── ECSManager.py    # ECS实例管理
│   ├── VPCManager.py    # VPC网络管理
│   ├── ShellHelper.py   # Shell脚本助手
│   ├── SqNetHelper.py   # 核心逻辑
│   └── resources.py     # 资源配置
├── sing-box/            # SingBox脚本
├── Xray/               # Xray脚本
├── setup.py            # 包配置
├── requirements.txt    # 依赖列表
├── README.md          # 项目文档
└── CHANGELOG.md       # 更新日志

🤝 贡献指南

欢迎提交Issue和Pull Request!

  1. Fork项目
  2. 创建功能分支
  3. 提交更改
  4. 推送到分支
  5. 创建Pull Request

📄 许可证

MIT License - 详见 LICENSE 文件

🔗 相关链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqnethelper-0.3.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqnethelper-0.3.0-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file sqnethelper-0.3.0.tar.gz.

File metadata

  • Download URL: sqnethelper-0.3.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for sqnethelper-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bef726805c4978b2ae35b62426b32bd4fa80d1f87d779af08fc06445385b336f
MD5 41a11c2e5108d3aef01c0ea99e1588bf
BLAKE2b-256 6fc72025197a7ab112969f0304acb68a3cd117730700d4b753a496a9aa7f7083

See more details on using hashes here.

File details

Details for the file sqnethelper-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sqnethelper-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for sqnethelper-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 873c1c67c8e4323ee6bbdba7185845c30cc3584291a32ad70f61319fd04a409d
MD5 325ff7b322f068a81e681d71e6cc955d
BLAKE2b-256 4cd770a3f586a470fafac15dc520d17fad888b2bb633c84a16a352fb3eda85ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page