migrate 第5步:密碼 base64 過 SSH(特殊字符不再被壳层拆烂)+顯示遠端真實輸出

This commit is contained in:
王性驊 2026-11-19 17:28:14 +08:00
parent f3fc047a0e
commit d9cf57ef13
3 changed files with 10 additions and 5 deletions

View File

@ -143,7 +143,11 @@ if [ -z "$BIN" ]; then
echo " ANYBOT_ACCOUNT_PASSWORD='密碼' 你的anybot路徑 setup --server $NEW_URL --user $OLD_USER --brain --no-service"
else
[ -n "$DDIR" ] && ENVDIR="ANYBOT_DATA_DIR='$DDIR' "
ssh -o BatchMode=yes "$SSH_TARGET" "ANYBOT_ACCOUNT_PASSWORD='$P1' ${ENVDIR:-}$BIN setup --server $NEW_URL --user $OLD_USER --brain --no-service" >/dev/null && ok "大腦已改接新帳號伺服器" || bad "大腦改接失敗——去那台手動跑上面提示的指令"
# 密码经 base64 过 SSH:任何特殊字符(引号、$、反引号)都不会在传输中被壳层吃掉。
P_B64=$(printf '%s' "$P1" | base64)
OUT=$(ssh -o BatchMode=yes "$SSH_TARGET" "ANYBOT_ACCOUNT_PASSWORD=\$(printf %s $P_B64 | base64 -d) ${ENVDIR:-}$BIN setup --server $NEW_URL --user $OLD_USER --brain --no-service" 2>&1)
printf '%s\n' "$OUT" | sed 's/^/ /' | tail -4
printf '%s' "$OUT" | grep -q '已接上\|完成\|✓' && ok "大腦已改接新帳號伺服器" || bad "大腦改接失敗——看上方原因(密码含 2FA 的話請直接用手機 App 的大腦選單,或那台手動跑:ANYBOT_ACCOUNT_PASSWORD='密碼' $BIN setup --server $NEW_URL --user $OLD_USER --brain --no-service)"
fi
# ---------- 6. 这台 Mac 的 App 改网址 ----------

View File

@ -36,7 +36,7 @@ pub fn config() -> ureq::config::ConfigBuilder<ureq::typestate::AgentScope> {
/// 连不上」、按下停止或任何按钮后的长转圈,都是这 30 秒。快失败、快重试。
pub fn agent(secs: u64) -> ureq::Agent {
static AGENTS: OnceLock<Mutex<HashMap<u64, ureq::Agent>>> = OnceLock::new();
AGENTS.get_or_init(Mutex::default).lock().unwrap_or_else(|e| e.into_inner()).entry(secs).or_insert_with(|| config().timeout_global(Some(Duration::from_secs(secs))).timeout_connect(Some(Duration::from_secs(5))).http_status_as_error(false).build().into()).clone()
AGENTS.get_or_init(Mutex::default).lock().unwrap_or_else(|e| e.into_inner()).entry(secs).or_insert_with(|| config().timeout_global(Some(Duration::from_secs(secs))).timeout_connect(Some(Duration::from_secs(15))).http_status_as_error(false).build().into()).clone()
}
#[cfg(test)]
@ -54,8 +54,9 @@ mod tests {
#[test]
fn connecting_dies_fast_everywhere() {
// 連接 5 秒封顶(不是 ureq 默认的 30):重开、断网、tailnet 未就绪时不卡 30 秒。
// 連接 15 秒封顶(不是 ureq 默认的 30):普通网络几秒见分晓;经 Tailscale 中继(DERP)
// 绕路的 TLS 握手实测可达 10 秒,5 秒会把中继用户锁在门外——15 秒两者都顾。
let a = super::agent(40);
assert_eq!(a.config().timeouts().connect, Some(std::time::Duration::from_secs(5)), "連接超時 5 秒");
assert_eq!(a.config().timeouts().connect, Some(std::time::Duration::from_secs(15)), "連接超時 15 秒");
}
}

View File

@ -2143,7 +2143,7 @@ pub(crate) fn relay_agent(secs: u64, url: &str) -> ureq::Agent {
.unwrap_or_else(|e| e.into_inner())
.entry(secs)
.or_insert_with(|| {
let config = crate::net::config().timeout_global(Some(Duration::from_secs(secs))).timeout_connect(Some(Duration::from_secs(5))).http_status_as_error(false).proxy(None).max_idle_connections(0).max_idle_connections_per_host(0).build();
let config = crate::net::config().timeout_global(Some(Duration::from_secs(secs))).timeout_connect(Some(Duration::from_secs(15))).http_status_as_error(false).proxy(None).max_idle_connections(0).max_idle_connections_per_host(0).build();
ureq::Agent::with_parts(config, ureq::unversioned::transport::DefaultConnector::new(), OffTheAir(Default::default()))
})
.clone()