Skip to content

Commit 6fc0f70

Browse files
committed
change example to bin, and prepare to release v0.3
1 parent c85b9cd commit 6fc0f70

File tree

13 files changed

+140
-65
lines changed

13 files changed

+140
-65
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ jobs:
5252
run: ${{ matrix.settings.build }}
5353

5454
- name: Upload artifact
55-
uses: svenstaro/upload-release-action@v2
55+
uses: actions/upload-artifact@v2
5656
with:
57-
asset_name: mproxy-${{ matrix.settings.target }}
58-
file: release/mproxy
59-
tag: ${{ github.ref }}
60-
repo_token: ${{ secrets.GITHUB_TOKEN
61-
draft: true
57+
name: mproxy-${{ matrix.settings.target }}
58+
path: release/*
59+
if-no-files-found: error

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
.PHONY: release-mac-x86_64, release-mac-aarch64, release-linux, release-linux-aarch64
22

33
name = mproxy
4+
ctrl_name = mpublish
45
rust_path = agent
56
release-mac-x86_64:
67
mkdir -p release
78
cd $(rust_path) && cargo build --release --target=x86_64-apple-darwin
89
strip $(rust_path)/target/x86_64-apple-darwin/release/$(name)
910
otool -L $(rust_path)/target/x86_64-apple-darwin/release/$(name)
10-
cp $(rust_path)/target/x86_64-apple-darwin/release/mproxy ./release/
11+
cp $(rust_path)/target/x86_64-apple-darwin/release/$(name) ./release/
12+
strip $(rust_path)/target/x86_64-apple-darwin/release/$(ctrl_name)
13+
otool -L $(rust_path)/target/x86_64-apple-darwin/release/$(ctrl_name)
14+
cp $(rust_path)/target/x86_64-apple-darwin/release/$(ctrl_name) ./release/
1115

1216
# brew install wget
1317
release-mac-aarch64:
@@ -16,18 +20,27 @@ release-mac-aarch64:
1620
strip $(rust_path)/target/aarch64-apple-darwin/release/$(name)
1721
otool -L $(rust_path)/target/aarch64-apple-darwin/release/$(name)
1822
cp $(rust_path)/target/aarch64-apple-darwin/release/$(name) ./release/
23+
strip $(rust_path)/target/aarch64-apple-darwin/release/$(ctrl_name)
24+
otool -L $(rust_path)/target/aarch64-apple-darwin/release/$(ctrl_name)
25+
cp $(rust_path)/target/aarch64-apple-darwin/release/$(ctrl_name) ./release/
1926

2027
release-linux-aarch64:
2128
sudo apt-get install -y build-essential
2229
mkdir release
2330
cd $(rust_path) && cargo build --release --target=aarch64-unknown-linux-gnu
2431
strip $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(name)
2532
cp $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(name) ./release/
33+
cd $(rust_path) && cargo build --release --target=aarch64-unknown-linux-gnu
34+
strip $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(ctrl_name)
35+
cp $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(ctrl_name) ./release/
36+
2637

2738

2839
release-linux:
2940
sudo apt-get install -y build-essential
3041
mkdir release
3142
cd $(rust_path) && cargo build --release --target=x86_64-unknown-linux-gnu
3243
strip $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(name)
33-
cp $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(name) ./release
44+
cp $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(name) ./release
45+
strip $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(ctrl_name)
46+
cp $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(ctrl_name) ./release

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33

44
相比于VPN,该项目代码可集成到只有 MQTT 交互的设备上,本项目的价值在于参考实现。
55

6+
## 快速开始
7+
1. 下载bin文件:[release page](./releases), `mproxy` `mpublish`
8+
2. 跑mqtt server, [这里](./tree/master/shell) 有如何快速跑测试 rmqtt 的例子,执行 `run_rmqtt.sh` 即可,生产环境参考 prod 目录下的配置。
9+
3. 编写配置文件:`mproxy.yml`,`mpublish.yml`, 可参考[agent](./tree/master/agent) 目录下的同名文件,两者要和并文件放在同一个目录下。
10+
```sh
11+
# 执行 mproxy
12+
./mproxy
13+
# or run with config
14+
./mproxy mproxy.yml
15+
16+
# 向 mproxy 分发指令
17+
./mpublish ls -ls
18+
# or run with config
19+
./mpublish --config=mpublish.conf ls -ls
20+
21+
```
22+
623
## 实现原理
724

825
在宿主上运行 `mproxy` 命令行可执行程序,通过 MQTT 连接 MQTT Server,并订阅 command 主题消息。
@@ -38,7 +55,7 @@
3855
}
3956
```
4057
### 配置文件
41-
参考 [config.yml](./agent/config.yml)
58+
参考 [mproxy.yml](./agent/mproxy.yml)[mpublish.yml](./agent/mpublish.yml)
4259

4360
### 开发
4461
Install [Rust 1.70+](https://www.rust-lang.org/),
@@ -50,11 +67,11 @@ cd shell && ./run_mqtt.sh && cd ../
5067
mprocs
5168

5269
# Check MQTT agent if is OK
53-
cd agent && cargo run --example publish_command.rs
70+
cd agent && cargo run --bin mpublish -- --config=mpublish.yml ls -ls
5471
```
5572
Web [Figma UI](https://www.figma.com/design/iyL4dms3B8AWGZS14FCRuf/RMQTT-EXEC?node-id=0%3A1&t=rnIL1LSWwQIXfZdf-1)
5673
## 限制
57-
目前只支持普通的命令, 不支持 `sudo xxx` 之类命令
74+
目前只支持普通的命令, 不支持 `sudo xxx` 需要额外输入,以及 `ls | grep xx` 使用 pipeline 的指令
5875

5976
### 应用场景举例
6077
1. 执行 `sshx`, 暴露 shell 给远端。

agent/Cargo.lock

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mproxy"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55

66
[dependencies]
@@ -19,7 +19,7 @@ anyhow = "1"
1919
serde_yml = "0.0.7"
2020
serde = { version = "1.0.202", features = ["derive"] }
2121
serde_json = "1.0"
22-
etcetera = "0.8"
22+
#etcetera = "0.8"
2323

2424
shellish_parse = "2"
2525

agent/config.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

agent/ctrl_config.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

agent/mproxy.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
server: 'mqtt://127.0.0.1:1883' # MQTT Server
2+
client_id: test_client #MQTT Client ID
3+
#username: test #MQTT Username
4+
#password: password #MQTT Password
5+
#command_topic: cmd/$client_id #subscribe MQTT topic, listen command message, default value is cmd/$client_id
6+
#response_command_topic: cmd/$client_id/resp #the topic to publish the command result

agent/mpublish.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server: 'mqtt://127.0.0.1:1883' # MQTT Server
2+
client_id: test_ctrl #MQTT Client ID
3+
#username: test_ctrl_username #MQTT Username
4+
#password: password #MQTT Password
5+
6+
subscribe_client_id: test_client #MQTT Subscribe Client ID
7+
#publish_command_topic: cmd/$client_id #the topic mpublish to pubish
8+
#response_command_topic: cmd/$client_id/resp #the topic mpublish to subscribe

agent/src/main.rs renamed to agent/src/bin/mproxy.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing_subscriber::EnvFilter;
77

88
#[derive(Parser, Debug)]
99
#[clap(name = mproxy::config::APP_NAME, version = env!("CARGO_PKG_VERSION"))]
10-
#[clap(group(ArgGroup::new("cmds").required(true).args(&["CONFIG"]),))]
10+
#[clap(group(ArgGroup::new("cmds").args(&["CONFIG"]),))]
1111
struct Cli {
1212
#[clap(value_parser, name = "CONFIG")]
1313
pub config_path: Option<PathBuf>,
@@ -54,9 +54,16 @@ mod test {
5454
fn parse_cli() {
5555
let result = Cli::parse_from([APP_NAME, "config.yaml"]);
5656
println!("{:?}", result);
57-
let result = Cli::parse_from([APP_NAME, "--version"]);
57+
//let result = Cli::parse_from([APP_NAME, "--version"]);
58+
//println!("{:?}", result);
59+
//let result = Cli::parse_from([APP_NAME, "--help"]);
60+
//println!("{:?}", result);
61+
62+
let result = Cli::parse_from([APP_NAME, "--", "config.yaml"]);
5863
println!("{:?}", result);
59-
let result = Cli::parse_from([APP_NAME, "--help"]);
64+
65+
let result = Cli::parse_from([APP_NAME, "--config=config.yaml"]);
6066
println!("{:?}", result);
67+
6168
}
6269
}

0 commit comments

Comments
 (0)