• Operand
  • # (b)ring mi - belles.

gram:build

> ./config/nushell/machine.nu

Lenses
(coming soon!)


def "machine norm" [ number: int ] { {
  login: root,
  address: $"10.0.0.($number)",
  key: ~/.ssh/id_ed25519.pub,
} }

def spin [ machine: record ] { try { shell $machine reboot }; ping $machine.address }

let machines = {
  mesh-b: { login: root, address: "10.10.0.12" },
  base: {login: root, address: "172.233.194.84", name: base },
  beacon: { login: root, address: "172.233.232.194", name: beacon },

#... original lab machines
# harbor: { login: access, address: "10.0.0.192" },
# pier: { login: access, address: "10.0.0.201" },
# share: { login: access, address: "10.0.0.201" },
# proxy: { login: root, channel: 21, address: "10.0.0.2" },
# press     : (machine norm 2),
# paper     : (machine norm 103),
# session   : (machine norm 106),
# assembled : (machine norm 202),
# backlog   : (machine norm 105),
# calcom    : (machine norm 204),
# carbon    : (machine norm 194),
# deploy    : (machine norm 205),
# gym       : (machine norm 104),
# labori    : (machine norm 208),
# lock      : (machine norm 207),
# pico      : (machine norm 200),
# pagemark  : (machine norm 202),
# pain      : (machine norm 203),
# space     : (machine norm 209),

}; let m = $machines

def announce [ message: any,
    -s: record = { size: 1 }, # shape (displayed message)
] {
  print "\n"
# for x in 1..$s.size { print "\n" }

# if (($message | describe) == 'string' ) {
# for x in 1..$s.size { print --no-newline "  " }; }; # print $message } # | lines | each { .... }

  if (($message | describe) == 'table') {
    print ($message | table --expand | into string) }

  # else { print $message }
  print $message
  print "\n"
}

def "machine address" [mach:record] { $"($mach.login)@($mach.address)" }

# let mach = $machines | transpose | find column0 = $m | get column1

let names = $machines | transpose | get column0

announce ([
  $"Hello; here are machines you can easily call:"
  ($machines | transpose | each {|m| $"  > shell $m.($m.column0)" } | str join "\n  ")
  "\b\b- Check again using:"
  "  > $machines"
  "  > $m"
  "\b\b- you can also run commands using `shell or `console` (as samples):"
  $"  > shell $m.(
    $names | get ((random dice --sides ($names | length) | get 0) - 1 )
    ) ls"
  $"  > console $m.(
    $names | get ((random dice --sides ($names | length) | get 0) - 1 )
    ) 'watch ip'"
] | str join "\n  "
)

def console --wrapped [mach: record, ...command] {
  let chan = if ($mach | transpose | get column0 | find channel | length) > 0 { $mach | get channel } else { 22 }
  ssh -t -p ($chan) (machine address $mach) ($command | str join ' ') }

def prox [mach: record, ...command] {
  let chan = if ($mach | transpose | get column0 | find channel | length) > 0 { $mach | get channel } else { 22 }
  console $m.proxy ssh -t -p $chan (machine address $mach) ($command | str join ' ')
}

def shell --wrapped [mach: record, ...command] {
  let chan = if ($mach | transpose | get column0 | find channel | length) > 0 { $mach | get channel } else { 22 }
  ssh -p ($chan) (machine address $mach) ($command | str join ' ') }

# hacdc
def amnesia-sh [] { ssh hacdcadmin@205.196.222.120; } #amnesia.dreamhost.com; }
def wiki-sh [] { ssh -t root@10.11.3.206; }

# # program local domains
def on [address:int]   { ssh -t $"root@10.0.0.($address)"; }
def mesh [address:int] { ssh -t $"mesh@10.10.0.($address)"; }

# # mesh machines
def carbon-sh []     { mesh 3; }
def mesh-a []        { mesh 11; }
def mesh-b []        { mesh 12; }
def mesh-c []        { mesh 13; }
def ll-sh []         { ssh calliope@10.10.0.10; }

def proxy-cycle []  {
  console $m.proxy ./cycle.sh
  shell $m.proxy systemctl status caddy
  shell $m.proxy journalctl -fu caddy }

def assembled-c []     { ssh -t root@10.0.0.202 'dokku run assembled rails c'; }
def assembled-cycle [] { ssh -t root@10.0.0.202 'dokku ps:restart assembled'; }
def assembled-log []   { ssh -t root@10.0.0.202 'dokku logs -t assembled'; }

def pico-cycle [] { cd; bind backup backup;
  let node = $"backup/log/(clock | str trim).picogram.log"
  ssh root@10.0.0.200 'cd /pico && docker compose logs' | save $node;
  ssh root@10.0.0.200 bash /root/cycle.sh }

def lock-cycle [] { cd; bind backup backup;
  let node = $"backup/log/(clock | str trim).padlock.log"
  ssh root@10.0.0.207 'cd /root/passbolt && docker compose logs' | save $node;
  ssh root@10.0.0.207 bash /root/cycle.sh;
}