From a92ed65e3d8fda40d0ced6fa2c5b55114f9ee7ff Mon Sep 17 00:00:00 2001 From: howard Date: Tue, 2 Dec 2025 01:39:58 +0800 Subject: [PATCH 1/5] =?UTF-8?q?README.md=E4=B8=AD=E5=A2=9E=E5=8A=A0macos?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=9C=8D=E5=8A=A1=E5=92=8C=E8=87=AA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 97 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 3bfded5..a4506e0 100644 --- a/README.md +++ b/README.md @@ -36,40 +36,79 @@ bash main.sh 在首次运行或重新生成配置文件时,脚本会自动生成配置文件 `config.toml` ,之后脚本会自动退出,在你编辑好配置文件后重新启动脚本即可 -3.注册服务 +3.注册服务 / 设置自启动 -创建服务文件 +**Linux(systemd)** -``` -touch /etc/systemd/system/oucshell.service -``` +- 创建服务文件 + ``` + touch /etc/systemd/system/oucshell.service + ``` +- 编辑服务文件(按实际路径替换) + ``` + # 这只是一个systemd服务注册示例,不要直接拿来用 + [Unit] + Description=Campus Helper Service (Electricity & More) + After=network.target -编辑服务文件 + [Service] + Type=simple + User=root + WorkingDirectory=/绝对路径/到/OUC_Shell # 替换为你的仓库路径 + ExecStart=/bin/bash /绝对路径/到/OUC_Shell/main.sh # 替换为你的 main.sh 路径 + Restart=always + RestartSec=10 -``` -# 这只是一个systemd服务注册示例,不要直接拿来用 -[Unit] -Description=Campus Helper Service (Electricity & More) -After=network.target + [Install] + WantedBy=multi-user.target + ``` +- 启动并设置开机自启 + ``` + systemctl start oucshell.service + systemctl enable oucshell.service + ``` -[Service] -Type=simple -User=root -WorkingDirectory=/path/to/your/repo # 这里改成你克隆的本仓库的路径 -ExecStart=/bin/bash /path/to/main.sh # 这里改成你的main.sh的路径 -Restart=always -RestartSec=10 +**macOS(LaunchAgent,随用户登录启动)** -[Install] -WantedBy=multi-user.target -``` - -4.启动服务和设置自启动 - -``` -systemctl start oucshell.service -systemctl enable oucshell.service -``` +- 安装依赖(macOS 自带 curl,需安装 jq 与 bc) + ``` + brew install jq bc + ``` +- 运行脚本(首次生成 config.toml,按需填写后再运行) + ``` + cd OUC_Shell + bash main.sh + ``` +- 创建 LaunchAgent(把路径换成你自己的绝对路径) + ``` + cat > ~/Library/LaunchAgents/cn.ouc.shell.plist <<'EOF' + + + + + Labelcn.ouc.shell + ProgramArguments + + /bin/bash + /绝对路径/到/OUC_Shell/main.sh + + WorkingDirectory/绝对路径/到/OUC_Shell + StandardOutPath/绝对路径/到/OUC_Shell/service.log + StandardErrorPath/绝对路径/到/OUC_Shell/service.log + RunAtLoad + KeepAlive + + + EOF + + launchctl load ~/Library/LaunchAgents/cn.ouc.shell.plist + ``` + - 请将 `/绝对路径/到/OUC_Shell` 替换为你的实际仓库路径(例如 `/Users/yourname/github_project/OUC_Shell`)。 + - 停止/重载:`launchctl unload ~/Library/LaunchAgents/cn.ouc.shell.plist` 后再 `load`。 +- 查看运行日志 + ``` + tail -f /绝对路径/到/OUC_Shell/service.log + ``` # 效果演示 @@ -91,4 +130,4 @@ systemctl enable oucshell.service - \ No newline at end of file + From 37b86af53236d59181ebd7fb8b9510e175c2798d Mon Sep 17 00:00:00 2001 From: Howard-aile <156976283+Howard-aile@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:40:54 +0800 Subject: [PATCH 2/5] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4506e0..4ed5d32 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,8 @@ bash main.sh EOF - - launchctl load ~/Library/LaunchAgents/cn.ouc.shell.plist + +launchctl load ~/Library/LaunchAgents/cn.ouc.shell.plist ``` - 请将 `/绝对路径/到/OUC_Shell` 替换为你的实际仓库路径(例如 `/Users/yourname/github_project/OUC_Shell`)。 - 停止/重载:`launchctl unload ~/Library/LaunchAgents/cn.ouc.shell.plist` 后再 `load`。 From e36dd200dcbedee847ffecececdcfbe3c1301b4f Mon Sep 17 00:00:00 2001 From: Howard-aile <156976283+Howard-aile@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:42:51 +0800 Subject: [PATCH 3/5] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ed5d32..4e92fa3 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,8 @@ bash main.sh cd OUC_Shell bash main.sh ``` +> **注意**:下方 plist 文件中的所有 `/绝对路径/到/OUC_Shell` 都需要替换为你的实际仓库绝对路径(例如 `/Users/yourname/github_project/OUC_Shell`),否则服务无法正常运行。 - 创建 LaunchAgent(把路径换成你自己的绝对路径) - ``` cat > ~/Library/LaunchAgents/cn.ouc.shell.plist <<'EOF' From 367dd8cdcb60ad0f956261d489001dc2aca93b52 Mon Sep 17 00:00:00 2001 From: Howard-aile <156976283+Howard-aile@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:43:49 +0800 Subject: [PATCH 4/5] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 4e92fa3..c4a9724 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,6 @@ bash main.sh ``` brew install jq bc ``` -- 运行脚本(首次生成 config.toml,按需填写后再运行) - ``` - cd OUC_Shell - bash main.sh - ``` > **注意**:下方 plist 文件中的所有 `/绝对路径/到/OUC_Shell` 都需要替换为你的实际仓库绝对路径(例如 `/Users/yourname/github_project/OUC_Shell`),否则服务无法正常运行。 - 创建 LaunchAgent(把路径换成你自己的绝对路径) cat > ~/Library/LaunchAgents/cn.ouc.shell.plist <<'EOF' From 22a48fea5c3f8ba29f1f16b17bec0dcc998c1d12 Mon Sep 17 00:00:00 2001 From: Howard-aile <156976283+Howard-aile@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:44:47 +0800 Subject: [PATCH 5/5] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4a9724..57b3a15 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,8 @@ bash main.sh - Labelcn.ouc.shell + Label + cn.ouc.shell ProgramArguments /bin/bash