From e0089fb079ab815a508387357f6569e158ec2324 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Sun, 27 Apr 2025 23:37:52 +0800 Subject: [PATCH 01/12] launcher/usage: Change ask_for_creds behavior for better privacy and currency. --- .vuepress/public/launcher.sh | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 570404b..d771a6c 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -18,23 +18,28 @@ log_W() { echo -e "\e[33m[!] $1\e[0m"; } log_E() { echo -e "\e[31m[-] $1\e[0m"; } ask_for_creds() { - read -e -p "请输入 SakuraFrp 的 访问密钥: " api_key - if [[ ${#api_key} -lt 16 ]]; then - log_E "访问密钥至少需要 16 字符, 请从管理面板直接复制粘贴" - exit 1 - fi - - read -e -p "请输入您希望使用的远程管理密码 (至少八个字符): " remote_pass - if [[ ${#remote_pass} -lt 8 ]]; then - log_E "远程管理密码至少需要 8 字符" - exit 1 - fi - - read -e -p "请再次输入远程管理密码: " remote_pass_confirm - if [[ $remote_pass != $remote_pass_confirm ]]; then + while true; do + read -e -s -p "请输入 SakuraFrp 的访问密钥, 请到 https://www.natfrp.com/user/ 获取" api_key + echo + api_key_respond=$(curl -LI -X 'GET' "https://api.natfrp.com/v4/user/info?token=${api_key}" -o /dev/null -w '%{http_code}\n' -s) + echo ${api_key_respond} + if [[ ${api_key_respond} -eq 200 ]]; then break; fi + log_E "访问密钥错误, 请到 https://www.natfrp.com/user/ 获取" + done + + while true; do + while true; do + read -e -s -p "请输入远程管理密码(至少八个字符): " remote_pass + echo + if [[ ${#remote_pass} -ge 8 ]]; then break; fi + log_E "远程管理密码至少需要 8 字符" + done + + read -e -s -p "请再次输入远程管理密码: " remote_pass_confirm + echo + if [[ "$remote_pass" == "$remote_pass_confirm" ]]; then break; fi log_E "两次输入的远程管理密码不一致, 请确认知晓自己正在输入的内容" - exit 1 - fi + done } check_executable() { From aa82090af36e7341bd19d05349339f6713f01a2d Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Mon, 28 Apr 2025 21:44:30 +0800 Subject: [PATCH 02/12] launcher/usage: stop the container gracefully --- .vuepress/public/launcher.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index d771a6c..43f2609 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -226,7 +226,7 @@ uninstall() { read -p " - 确认要卸载 SakuraFrp 启动器吗? [y/N] " -r choice if [[ $choice =~ ^[Yy]$ ]]; then if docker ps -a --format '{{.Names}}' | grep -q '^natfrp-service$'; then - docker kill natfrp-service &>/dev/null || log_W "无法停止 natfrp-service 容器, 将尝试直接删除" + docker stop natfrp-service &>/dev/null || docker kill natfrp-service &>/dev/null docker rm natfrp-service &>/dev/null && log_I "已删除 Docker 容器" fi From 58ea32419f30035715e93b6de3a45d9663127058 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Mon, 28 Apr 2025 22:14:36 +0800 Subject: [PATCH 03/12] launcher/usage: regard advice as info --- .vuepress/public/launcher.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 43f2609..bd63f82 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -276,7 +276,7 @@ if docker info &>/dev/null && [[ $1 != "direct" ]]; then fi log_W "您正在使用非 Docker 安装模式" -echo "我们建议您总是使用 Docker 安装模式, 以便于管理和减少兼容性问题" +log_I "我们建议您总是使用 Docker 安装模式, 以便于管理和减少兼容性问题" # Check SELinux if command -v getenforce &>/dev/null; then From 9b4bd934332d143502d83713b36fd64d8eab1e7d Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Mon, 28 Apr 2025 22:20:25 +0800 Subject: [PATCH 04/12] launcher/usage: make remove process more gracefully --- .vuepress/public/launcher.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index bd63f82..3a0e94c 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -67,7 +67,7 @@ docker_install() { log_W "已存在名为 natfrp-service 的容器" read -p " - 是否移除已存在的容器? [y/N] " -r choice if [[ $choice =~ ^[Yy]$ ]]; then - docker kill natfrp-service || log_W "无法停止 natfrp-service 容器, 将尝试直接移除" + docker stop natfrp-service &>/dev/null || docker kill natfrp-service &>/dev/null docker rm natfrp-service else log_E "请手动移除已存在的容器后重新运行脚本" @@ -203,7 +203,7 @@ EOF - 查看日志\tjournalctl -u natfrp.service \n请登录远程管理界面启动隧道: https://www.natfrp.com/remote/v2\n" - log_I "下方将输出启动器日志, 如需退出请按 Ctrl+C" + log_I "下方将输出启动器日志, 如需退出请按 Ctrl+C" journalctl -u natfrp.service -f } @@ -228,6 +228,9 @@ uninstall() { if docker ps -a --format '{{.Names}}' | grep -q '^natfrp-service$'; then docker stop natfrp-service &>/dev/null || docker kill natfrp-service &>/dev/null docker rm natfrp-service &>/dev/null && log_I "已删除 Docker 容器" + else + log_E "无法删除 Docker 容器, 脚本已退出" + exit 1 fi if [[ -f /etc/systemd/system/natfrp.service ]]; then From a677320946e2cb11b9e6919b0ca247404d84c962 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Mon, 28 Apr 2025 22:28:03 +0800 Subject: [PATCH 05/12] launcher/usage: add container source options --- .vuepress/public/launcher.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 3a0e94c..76fb911 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -75,9 +75,28 @@ docker_install() { fi fi - docker run -d --network=host --restart=on-failure:5 --pull=always --name=natfrp-service -v ${CONFIG_BASE}:/run -e "NATFRP_TOKEN=$api_key" -e "NATFRP_REMOTE=$remote_pass" natfrp.com/launcher || \ + log_I "Docker 安装模式选择" + echo "请选择镜像来源:" + echo "1. 官方 (natfrp.com/launcher)" + echo "2. GitHub (ghcr.io/natfrp/launcher)" + echo "3. Docker Hub (natfrp/launcher)" + read -p "请输入选项 [1-3] (默认1): " source + case $source in + 2) image="ghcr.io/natfrp/launcher" ;; + 3) image="natfrp/launcher" ;; + *) image="natfrp.com/launcher" ;; + esac + + docker run -d --network=host \ + --restart=on-failure:5 \ + --pull=always \ + --name=natfrp-service \ + -v ${CONFIG_BASE}:/run \ + -e "NATFRP_TOKEN=$api_key" \ + -e "NATFRP_REMOTE=$remote_pass" \ + $image || \ ( - log_E "Docker 模式安装失败, 请检查 Docker 在是否正常运行以及是否能正常访问 natfrp.com 拉取镜像" + log_E "Docker 模式安装失败, 请检查 Docker 在是否正常运行以及是否能正常访问镜像" exit 1 ) From fc2899d989f89bf896e85a79c26a6528bb2bbcfa Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Tue, 29 Apr 2025 22:01:16 +0800 Subject: [PATCH 06/12] launcher/usage: remove API calling for better compatibility --- .vuepress/public/launcher.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 76fb911..ee73104 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -21,9 +21,7 @@ ask_for_creds() { while true; do read -e -s -p "请输入 SakuraFrp 的访问密钥, 请到 https://www.natfrp.com/user/ 获取" api_key echo - api_key_respond=$(curl -LI -X 'GET' "https://api.natfrp.com/v4/user/info?token=${api_key}" -o /dev/null -w '%{http_code}\n' -s) - echo ${api_key_respond} - if [[ ${api_key_respond} -eq 200 ]]; then break; fi + if [[ ${#api_key} -eq 16 ]]; then log_E "访问密钥错误, 请到 https://www.natfrp.com/user/ 获取" done From 8fd308b59853dbda700a7a7c425a25771f39c7c3 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Tue, 29 Apr 2025 22:04:32 +0800 Subject: [PATCH 07/12] launcher/usage: typo fix --- .vuepress/public/launcher.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index ee73104..42a627c 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -27,7 +27,7 @@ ask_for_creds() { while true; do while true; do - read -e -s -p "请输入远程管理密码(至少八个字符): " remote_pass + read -e -s -p "请输入远程管理密码 (至少八个字符): " remote_pass echo if [[ ${#remote_pass} -ge 8 ]]; then break; fi log_E "远程管理密码至少需要 8 字符" @@ -85,14 +85,15 @@ docker_install() { *) image="natfrp.com/launcher" ;; esac - docker run -d --network=host \ - --restart=on-failure:5 \ - --pull=always \ - --name=natfrp-service \ - -v ${CONFIG_BASE}:/run \ - -e "NATFRP_TOKEN=$api_key" \ - -e "NATFRP_REMOTE=$remote_pass" \ - $image || \ + docker run -d \ + --network=host \ + --restart=on-failure:5 \ + --pull=always \ + --name=natfrp-service \ + -v ${CONFIG_BASE}:/run \ + -e "NATFRP_TOKEN=$api_key" \ + -e "NATFRP_REMOTE=$remote_pass" \ + $image || \ ( log_E "Docker 模式安装失败, 请检查 Docker 在是否正常运行以及是否能正常访问镜像" exit 1 @@ -220,7 +221,7 @@ EOF - 查看日志\tjournalctl -u natfrp.service \n请登录远程管理界面启动隧道: https://www.natfrp.com/remote/v2\n" - log_I "下方将输出启动器日志, 如需退出请按 Ctrl+C" + log_I "下方将输出启动器日志, 如需退出请按 Ctrl+C" journalctl -u natfrp.service -f } From bd93c45be950019ca88881fe89c5e6984a9a9805 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:11:24 +0800 Subject: [PATCH 08/12] launcher/usage: container will exit in 5 sec --- .vuepress/public/launcher.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 42a627c..c9638ed 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -65,7 +65,7 @@ docker_install() { log_W "已存在名为 natfrp-service 的容器" read -p " - 是否移除已存在的容器? [y/N] " -r choice if [[ $choice =~ ^[Yy]$ ]]; then - docker stop natfrp-service &>/dev/null || docker kill natfrp-service &>/dev/null + docker stop --timeout 5 &>/dev/null docker rm natfrp-service else log_E "请手动移除已存在的容器后重新运行脚本" @@ -244,7 +244,7 @@ uninstall() { read -p " - 确认要卸载 SakuraFrp 启动器吗? [y/N] " -r choice if [[ $choice =~ ^[Yy]$ ]]; then if docker ps -a --format '{{.Names}}' | grep -q '^natfrp-service$'; then - docker stop natfrp-service &>/dev/null || docker kill natfrp-service &>/dev/null + docker stop --timeout 5 &>/dev/null docker rm natfrp-service &>/dev/null && log_I "已删除 Docker 容器" else log_E "无法删除 Docker 容器, 脚本已退出" From 6ddd5959f8a15f632bb15c20835a2c2fac568834 Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:16:39 +0800 Subject: [PATCH 09/12] launcher/usage: disable/stop service will base on whether the unit presist --- .vuepress/public/launcher.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index c9638ed..1afdaf5 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -252,8 +252,11 @@ uninstall() { fi if [[ -f /etc/systemd/system/natfrp.service ]]; then - systemctl stop natfrp.service &>/dev/null - systemctl disable natfrp.service &>/dev/null + if systemctl -q is-enabled; then + systemctl disable --now natfrp.service &>/dev/null + elif systemctl -q is-active; then + systemctl stop natfrp.service &>/dev/null + fi rm -f /etc/systemd/system/natfrp.service &>/dev/null && log_I "已删除 systemd 服务" systemctl reload-daemon &>/dev/null fi From 14900e01cc295ee848586307b47d63e2b55a805d Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:22:01 +0800 Subject: [PATCH 10/12] launcher/usage: remove useless else branch --- .vuepress/public/launcher.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 1afdaf5..2aca884 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -246,9 +246,6 @@ uninstall() { if docker ps -a --format '{{.Names}}' | grep -q '^natfrp-service$'; then docker stop --timeout 5 &>/dev/null docker rm natfrp-service &>/dev/null && log_I "已删除 Docker 容器" - else - log_E "无法删除 Docker 容器, 脚本已退出" - exit 1 fi if [[ -f /etc/systemd/system/natfrp.service ]]; then From 4ef7f3943a3f6ffc27c1127db62b3f48b58a21cc Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:51:25 +0800 Subject: [PATCH 11/12] launcher/usage: fix an error --- .vuepress/public/launcher.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index 2aca884..e1bf7e6 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -21,7 +21,7 @@ ask_for_creds() { while true; do read -e -s -p "请输入 SakuraFrp 的访问密钥, 请到 https://www.natfrp.com/user/ 获取" api_key echo - if [[ ${#api_key} -eq 16 ]]; then + if [[ ${#api_key} -ne 16 ]]; then log_E "访问密钥错误, 请到 https://www.natfrp.com/user/ 获取" done From b93a6116dd50737ab6bf5f3a9bc8de840be25c3f Mon Sep 17 00:00:00 2001 From: Seele Vollerei <83913312+Seele-Vollerei32@users.noreply.github.com> Date: Thu, 1 May 2025 12:00:08 +0800 Subject: [PATCH 12/12] launcher/usage: clear sercets after asking --- .vuepress/public/launcher.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.vuepress/public/launcher.sh b/.vuepress/public/launcher.sh index e1bf7e6..f12767d 100644 --- a/.vuepress/public/launcher.sh +++ b/.vuepress/public/launcher.sh @@ -19,7 +19,7 @@ log_E() { echo -e "\e[31m[-] $1\e[0m"; } ask_for_creds() { while true; do - read -e -s -p "请输入 SakuraFrp 的访问密钥, 请到 https://www.natfrp.com/user/ 获取" api_key + read -e -p "请输入 SakuraFrp 的访问密钥, 请到 https://www.natfrp.com/user/ 获取" api_key echo if [[ ${#api_key} -ne 16 ]]; then log_E "访问密钥错误, 请到 https://www.natfrp.com/user/ 获取" @@ -27,17 +27,18 @@ ask_for_creds() { while true; do while true; do - read -e -s -p "请输入远程管理密码 (至少八个字符): " remote_pass + read -e -p "请输入远程管理密码 (至少八个字符): " remote_pass echo if [[ ${#remote_pass} -ge 8 ]]; then break; fi log_E "远程管理密码至少需要 8 字符" done - read -e -s -p "请再次输入远程管理密码: " remote_pass_confirm + read -e -p "请再次输入远程管理密码: " remote_pass_confirm echo if [[ "$remote_pass" == "$remote_pass_confirm" ]]; then break; fi log_E "两次输入的远程管理密码不一致, 请确认知晓自己正在输入的内容" done + clear } check_executable() {