Remove claw push and payloads directory with related docs

This commit is contained in:
2026-05-16 21:52:19 +08:00
parent 24d32cc34b
commit bd482b3301
5 changed files with 84 additions and 49 deletions
+17 -19
View File
@@ -1,6 +1,6 @@
# Claw
云主机管理工具,命令行搞定 SSH 连接、脚本执行、文件分发。
云主机管理工具,命令行搞定 SSH 连接、脚本执行。
## 目录结构
@@ -8,10 +8,9 @@
Claw/
├── claw.bat # 入口 (PowerShell 包装器)
├── claw.ps1 # 主控脚本
├── hosts/ # 主机描述文件
├── hosts/ # 主机描述文件 (.yml)
├── keys/ # SSH 私钥 (.pem)
├── scripts/ # 可执行脚本
└── payloads/ # 待分发文件
└── scripts/ # 可执行脚本 (.sh)
```
## 命令
@@ -20,7 +19,6 @@ Claw/
claw list # 列出所有主机
claw ssh <主机名> # SSH 连接
claw run <主机名> <脚本名> # 执行脚本
claw push <主机名> <文件或目录> # 推送文件到 /tmp/
claw key add <名称> <pem文件路径> # 注册密钥
claw key list # 列出密钥
```
@@ -30,19 +28,21 @@ claw key list # 列出密钥
### hosts/ — 主机描述
```
<主机标识>-<操作系统>-<用户名>
<主机标识>-<操作系统>-<用户名>.yml
```
例:`tx-ubuntu-ubuntu` = 腾讯云主机 · Ubuntu · ubuntu 用户
例:`tx-ubuntu-ubuntu.yml` = 腾讯云主机 · Ubuntu · ubuntu 用户
同一台机器的不同用户用独立文件:
```
tx-ubuntu-ubuntu # → 62.234.90.54 用户 ubuntu
tx-ubuntu-hugo # → 62.234.90.54 用户 hugo
tx-ubuntu-ubuntu.yml # → 62.234.90.54 用户 ubuntu
tx-ubuntu-hugo.yml # → 62.234.90.54 用户 hugo
tx-ubuntu-cmcc.yml # → 62.234.90.54 用户 cmcc
tx-ubuntu-git.yml # → 62.234.90.54 用户 git
```
YAML 格式(.yml 后缀),新建主机复制下面模板改:
YAML 格式,新建主机复制下面模板改:
```yaml
# ╔══════════════════════════════════════════════════╗
@@ -53,7 +53,7 @@ host:
ip: 1.2.3.4
user: root
port: 22
key: keys/example.pem
key: keys/example-ubuntu-root.pem
info:
name: example-server
@@ -90,16 +90,15 @@ billing:
### keys/ — 密钥
与 hosts 文件名一一对应:
```
<主机名>.pem
tx-ubuntu-ubuntu.pem
tx-ubuntu-hugo.pem
tx-ubuntu-cmcc.pem
tx-ubuntu-git.pem
```
例:`tx-ubuntu.pem`、`tx-ubuntu-hugo.pem`
### payloads/ — 发射区
把要发上主机的文件或目录扔进来,`claw push` 会走 SCP 发到主机的 `/tmp/` 下。
## 快速开始
```cmd
@@ -112,7 +111,6 @@ notepad hosts\my-host-ubuntu-root.yml
# 3. 开工
claw ssh my-host-ubuntu-root
claw run my-host-ubuntu-root sysinfo@my-host-ubuntu-root.sh
claw push my-host-ubuntu-root my-project
```
## 全局命令
-28
View File
@@ -15,7 +15,6 @@ Commands:
list List all hosts
ssh <host> SSH into a host
run <host> <script> Run a script on a host (from scripts\)
push <host> <file/dir> Push file/dir to host (from payloads\)
key add <name> <pem> Register a PEM key into keys\
key list List all registered keys
@@ -23,7 +22,6 @@ Examples:
claw list
claw ssh my-server
claw run my-server hello.sh
claw push my-server my-app
claw key add my-server C:\Users\me\Downloads\key.pem
"@
}
@@ -66,7 +64,6 @@ function Parse-Yaml($Path) {
function Load-Host($Name) {
$HostFile = Join-Path $ClawRoot "hosts\$Name.yml"
if (-not (Test-Path $HostFile)) {
# fallback: try without .yml extension (old format)
$HostFile = Join-Path $ClawRoot "hosts\$Name"
if (-not (Test-Path $HostFile)) {
Write-Host "ERROR: host '$Name' not found (hosts\$Name.yml)" -ForegroundColor Red
@@ -99,7 +96,6 @@ function Load-Host($Name) {
Write-Host "ERROR: key file not found: $HostKey" -ForegroundColor Red
exit 1
}
# Fix Windows permissions (SSH requires key NOT readable by other users)
icacls $HostKey /inheritance:r /grant "${env:USERNAME}:(R)" 2>$null | Out-Null
}
}
@@ -167,29 +163,6 @@ function Invoke-Run($Name, $Script) {
(Get-Content $sp -Raw) | & ssh @sa "$HostUser@$HostIP" "tr -d '\r' | bash -s"
}
# ============================================================
# Push files to host
# ============================================================
function Invoke-Push($Name, $Target) {
Load-Host $Name
$src = Join-Path $ClawRoot "payloads\$Target"
if (-not (Test-Path $src)) {
Write-Host "ERROR: '$Target' not found (payloads\$Target)" -ForegroundColor Red
Write-Host "Available payloads:" -ForegroundColor Yellow
Get-ChildItem (Join-Path $ClawRoot "payloads") | ForEach-Object { Write-Host " $($_.Name)" }
exit 1
}
$sca = @("-o", "StrictHostKeyChecking=accept-new")
if ($HostPort) { $sca += "-P"; $sca += $HostPort }
if ($HostKey) { $sca += "-i"; $sca += $HostKey }
if (Test-Path $src -PathType Container) { $sca += "-r" }
Write-Host ">>> Pushing $Target -> $Name`:$HostUser@$HostIP`:/tmp/" -ForegroundColor Green
& scp @sca $src "$HostUser@$HostIP`:/tmp/"
Write-Host ">>> Done. Files at /tmp/$Target" -ForegroundColor Green
}
# ============================================================
# Key management
# ============================================================
@@ -234,7 +207,6 @@ switch ($Command) {
"list" { Write-Host "Hosts:" -ForegroundColor Yellow; List-Hosts }
"ssh" { Invoke-Ssh $Arg1 }
"run" { Invoke-Run $Arg1 $Arg2 }
"push" { Invoke-Push $Arg1 $Arg2 }
"key" { Invoke-Key $Arg1 $Arg2 $Arg3 }
{ $_ -in @("-h", "--help", "help", "", $null) } { Usage }
default { Write-Host "Unknown command: $Command" -ForegroundColor Red; Usage; exit 1 }
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# ============================================================
# git-repo-create@tx-ubuntu-git.sh
# 在 git 用户下创建裸仓库(bare repo),作为本地 git push 的目标
#
# 用法: claw run tx-ubuntu-git git-repo-create@tx-ubuntu-git.sh
# 适用: Ubuntu 24.04
#
# 前置条件:
# - git 用户已创建,SSH 密钥已配置
# - /home/git/repos 目录可写
#
# 路径约定:
# - 裸仓库: /home/git/repos/<项目名>.git
# - 通过 SSH git@62.234.90.54 访问
#
# 如需新增其他项目,复制此脚本,修改 REPO 变量即可
# ============================================================
set -e
# ---- 配置(新增项目改这里) ----
BASEDIR="/home/git/repos" # 裸仓库根目录
REPO="Work" # 项目名
# -------------------------------
REPO_PATH="$BASEDIR/$REPO.git"
if [ -d "$REPO_PATH" ]; then
echo "仓库已存在: $REPO_PATH"
else
mkdir -p "$BASEDIR"
git init --bare "$REPO_PATH"
echo "仓库创建完成: $REPO_PATH"
fi
echo ""
echo "=== 本地使用 ==="
echo " git remote add tx ssh://git@62.234.90.54$REPO_PATH"
echo " git push -u tx main"
+16 -1
View File
@@ -1,5 +1,20 @@
#!/usr/bin/env bash
# sync-blog: pull + rebuild
# ============================================================
# sync-blog@tx-ubuntu-hugo.sh
# 拉取 Hugo 博客最新代码并重新构建静态页面
#
# 用法: claw run tx-ubuntu-hugo sync-blog@tx-ubuntu-hugo.sh
# 适用: Ubuntu 24.04, Hugo 0.161+
#
# 前置条件:
# - ~/hugo-blog 已 git clone 且 remote 指向 github.com:fukunee/Hugo
# - hugo 已安装
# - nginx 指向 ~/hugo-blog/public
#
# 流程:
# 1. git pull — 拉取最新文章和配置
# 2. hugo build — 重建静态页面到 public/
# ============================================================
set -e
cd ~/hugo-blog
+12 -1
View File
@@ -1,13 +1,24 @@
#!/usr/bin/env bash
# 示例脚本 - 查看主机基本信息
# ============================================================
# sysinfo@tx-ubuntu-ubuntu.sh
# 主机健康速览:系统信息、磁盘、内存
#
# 用法: claw run tx-ubuntu-ubuntu sysinfo@tx-ubuntu-ubuntu.sh
# 适用: Ubuntu 24.04
# ============================================================
set -e
echo "===== 主机信息 ====="
echo "主机名: $(hostname)"
echo "系统: $(cat /etc/os-release | grep PRETTY_NAME | cut -d= -f2 | tr -d '"')"
echo "内核: $(uname -r)"
echo "运行时间: $(uptime -p)"
echo ""
echo "===== 磁盘 ====="
# 仅显示根分区,如需全部分区改成 df -h
df -h /
echo ""
echo "===== 内存 ====="
free -h