all nuing
This commit is contained in:
1 parent
e99744f628
commit
1e1da2f7a1
7 files changed
+443
-211
No files matched your search
+7
-39
@@ -25,33 +25,10 @@
|
||||
# happen.
|
||||
|
||||
# ---------------------------------------------------------------- output ---
|
||||
|
||||
def say [msg: string] { print $" ($msg)" }
|
||||
def note [msg: string] { print $" (ansi dark_gray)($msg)(ansi reset)" }
|
||||
def ok [msg: string] { print $" (ansi green)✓(ansi reset) ($msg)" }
|
||||
def warn [msg: string] { print $" (ansi yellow)!(ansi reset) ($msg)" }
|
||||
def die [msg: string] { print -e $"\n(ansi red)error:(ansi reset) ($msg)"; exit 1 }
|
||||
def step [n: int, title: string] { print $"\n(ansi attr_bold)== ($n). ($title)(ansi reset)" }
|
||||
|
||||
def ask [prompt: string, default: string = ""] {
|
||||
let suffix = if $default != "" { $" [($default)]" } else { "" }
|
||||
let reply = (input $" ($prompt)($suffix): ")
|
||||
if $reply == "" { $default } else { $reply }
|
||||
}
|
||||
|
||||
def confirm [prompt: string] {
|
||||
let reply = (input $" ($prompt) [y/N] ")
|
||||
(($reply | str starts-with "y") or ($reply | str starts-with "Y"))
|
||||
}
|
||||
|
||||
def confirm-word [word: string, prompt: string] {
|
||||
(input $" ($prompt) ") == $word
|
||||
}
|
||||
|
||||
# Single-quote a string for safe embedding in a remote shell command line.
|
||||
def shquote [s: string] {
|
||||
"'" + ($s | str replace --all "'" "'\\''") + "'"
|
||||
}
|
||||
#
|
||||
# say/note/ok/warn/die/step/ask/confirm/confirm-word/shquote/vsock-ssh-args/
|
||||
# run-argv live in nu/lib/common.nu, shared with hermes-vm.nu and
|
||||
# hermes-ctl.nu - see flake.nix, which concatenates it in front of this file.
|
||||
|
||||
# `truncate -s` treats a bare number as bytes, not gigabytes - the size
|
||||
# prompts' own defaults ("80G", "20G") make gigabytes the obvious intent, so
|
||||
@@ -448,16 +425,8 @@ def "main migrate" [
|
||||
die "--rewrite-from and --rewrite-to must have the same length"
|
||||
}
|
||||
|
||||
let ssh_base = [
|
||||
"ssh"
|
||||
"-o" $"ProxyCommand=socat - VSOCK-CONNECT:($vsock_cid):22"
|
||||
"-o" "StrictHostKeyChecking=accept-new"
|
||||
$"($guest_user)@hermes"
|
||||
]
|
||||
def gssh [...args: string] {
|
||||
let full = $ssh_base ++ $args
|
||||
^($full | first) ...($full | skip 1)
|
||||
}
|
||||
let ssh_base = (vsock-ssh-args $vsock_cid $guest_user "hermes")
|
||||
def gssh [cmd: string] { run-argv ($ssh_base ++ [$cmd]) }
|
||||
|
||||
say $"Source \(read-only\): ($source)"
|
||||
say $"Destination \(guest\): ($guest_user)@hermes:($dest) \(over vsock, cid ($vsock_cid)\)"
|
||||
@@ -475,8 +444,7 @@ def "main migrate" [
|
||||
gssh "true"
|
||||
|
||||
step 2 $"streaming ($source) -> guest:($dest) \(this can take a while for 8G+\)"
|
||||
let stream_argv = $ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"]
|
||||
^tar -C $source -cf - . | ^($stream_argv | first) ...($stream_argv | skip 1)
|
||||
^tar -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||
|
||||
step 3 "rewriting stale hostnames in the guest"
|
||||
let sed_expr = (0..(($rewrite_from | length) - 1)
|
||||
|
||||
Reference in new issue
Block a user