fix: restore missing ensure_sshpass() function in ssh.py
This commit is contained in:
@@ -24,8 +24,51 @@ def check_ssh_keyless(host, user, port, key_path, timeout=10):
|
||||
return (False, err[:120])
|
||||
|
||||
|
||||
def generate_temp_keypair(host_label):
|
||||
"""Генерирует временную пару ed25519 в /tmp/."""
|
||||
temp_dir = "/tmp/docker-migrate-ssh-keys"
|
||||
os.makedirs(temp_dir, exist_ok=True)
|
||||
priv = os.path.join(temp_dir, f"migrate_{host_label}")
|
||||
pub = priv + ".pub"
|
||||
info("Генерируем временную SSH-пару ed25519 ...")
|
||||
run(f"ssh-keygen -t ed25519 -C 'docker-migrate-temp' -f '{priv}' -N ''", check=False)
|
||||
if os.path.isfile(priv) and os.path.isfile(pub):
|
||||
os.chmod(priv, 0o600)
|
||||
success(f"Временная пара создана: {priv}")
|
||||
return {"private": priv, "public": pub, "type": "ed25519", "temp": True}
|
||||
return None
|
||||
|
||||
|
||||
def ssh_copy_id(host, user, port, pubkey_path):
|
||||
"""ssh-copy-id на новый сервер. Интерактивно (пароль нового сервера)."""
|
||||
if not exists("ssh-copy-id"):
|
||||
return False
|
||||
warn("⚠ Сейчас запустится ssh-copy-id — введите ПАРОЛЬ от НОВОГО сервера ↓")
|
||||
r = run(
|
||||
f"ssh-copy-id -p {port} -o ConnectTimeout=30 -o StrictHostKeyChecking=accept-new -i '{pubkey_path}' {user}@{host}",
|
||||
check=False, capture=False, timeout=120
|
||||
)
|
||||
return r.returncode == 0
|
||||
|
||||
|
||||
def ensure_sshpass():
|
||||
"""Устанавливает sshpass если нужно."""
|
||||
if exists("sshpass"):
|
||||
return True
|
||||
info("sshpass не найден. Устанавливаем ...")
|
||||
r1 = run("apt-get update", check=False, timeout=60)
|
||||
if r1.returncode != 0:
|
||||
warn(f"apt-get update: {r1.stderr.strip()[:120]}")
|
||||
r = run("apt-get install -y sshpass", check=False, timeout=120)
|
||||
if r.returncode != 0:
|
||||
warn(f"Не удалось установить sshpass: {r.stderr.strip()[:120]}")
|
||||
return False
|
||||
return exists("sshpass")
|
||||
|
||||
|
||||
# ...
|
||||
|
||||
|
||||
def pick_or_setup_ssh_key(host, user, port):
|
||||
"""
|
||||
Возвращает путь к приватному SSH-ключу для нового сервера.
|
||||
|
||||
Reference in New Issue
Block a user